diff --git a/src/messages/text_document_document_symbol.cc b/src/messages/text_document_document_symbol.cc index a6f12710..b6631bd1 100644 --- a/src/messages/text_document_document_symbol.cc +++ b/src/messages/text_document_document_symbol.cc @@ -42,6 +42,16 @@ struct TextDocumentDocumentSymbolHandler GetSymbolInfo(db, working_files, sym, true /*use_short_name*/); if (!info) continue; + if (sym.kind == SymbolKind::Var) { + QueryVar& var = db->GetVar(sym); + auto* def = var.AnyDef(); + if (!def || !def->spell) continue; + // Ignore local variables. + if (def->spell->kind == SymbolKind::Func && + def->storage != StorageClass::Static && + def->storage != StorageClass::Extern) + continue; + } if (optional location = GetLsLocation( db, working_files, diff --git a/src/query.cc b/src/query.cc index 656a5a73..ddf5c6cf 100644 --- a/src/query.cc +++ b/src/query.cc @@ -278,17 +278,13 @@ QueryFile::DefUpdate BuildFileDefUpdate(const IdMap& id_map, } for (const IndexVar& var : indexed.vars) { QueryVarId id = id_map.ToQuery(var.id); - if (var.def.spell) { + if (var.def.spell) add_all_symbols(*var.def.spell, id, SymbolKind::Var); - if (var.def.extent && (var.def.spell->kind != SymbolKind::Func || - var.def.storage == StorageClass::Static)) - add_outline(*var.def.extent, id, SymbolKind::Var); - } + if (var.def.extent) + add_outline(*var.def.extent, id, SymbolKind::Var); for (Use decl : var.declarations) { add_all_symbols(decl, id, SymbolKind::Var); - if (decl.kind != SymbolKind::Func || - var.def.storage == StorageClass::Static) - add_outline(decl, id, SymbolKind::Var); + add_outline(decl, id, SymbolKind::Var); } for (Use use : var.uses) add_all_symbols(use, id, SymbolKind::Var); @@ -425,9 +421,6 @@ QueryTypeId IdMap::ToQuery(IndexTypeId id) const { return QueryTypeId(cached_type_ids_.find(id)->second); } QueryFuncId IdMap::ToQuery(IndexFuncId id) const { - // FIXME id shouldn't be invalid - if (id == IndexFuncId()) - return QueryFuncId(); assert(cached_func_ids_.find(id) != cached_func_ids_.end()); return QueryFuncId(cached_func_ids_.find(id)->second); } diff --git a/src/query.h b/src/query.h index dbd35e76..008d52a5 100644 --- a/src/query.h +++ b/src/query.h @@ -134,8 +134,12 @@ MAKE_REFLECT_STRUCT(QueryFile::Def, inactive_regions, dependencies); -template +template struct QueryEntity { + using Def = QDef; + using DefUpdate = WithUsr; + using DeclarationsUpdate = MergeableUpdate, Use>; + using UsesUpdate = MergeableUpdate, Use>; Def* AnyDef() { Def* ret = nullptr; for (auto& i : static_cast(this)->def) { @@ -149,12 +153,8 @@ struct QueryEntity { }; struct QueryType : QueryEntity> { - using Def = TypeDefDefinitionData; - using DefUpdate = WithUsr; - using DeclarationsUpdate = MergeableUpdate; using DerivedUpdate = MergeableUpdate; using InstancesUpdate = MergeableUpdate; - using UsesUpdate = MergeableUpdate; Usr usr; Maybe> symbol_idx; @@ -168,11 +168,7 @@ struct QueryType : QueryEntity> { }; struct QueryFunc : QueryEntity> { - using Def = FuncDefDefinitionData; - using DefUpdate = WithUsr; - using DeclarationsUpdate = MergeableUpdate; using DerivedUpdate = MergeableUpdate; - using UsesUpdate = MergeableUpdate; Usr usr; Maybe> symbol_idx; @@ -185,11 +181,6 @@ struct QueryFunc : QueryEntity> { }; struct QueryVar : QueryEntity> { - using Def = VarDefDefinitionData; - using DefUpdate = WithUsr; - using DeclarationsUpdate = MergeableUpdate; - using UsesUpdate = MergeableUpdate; - Usr usr; Maybe> symbol_idx; std::forward_list def;