diff --git a/src/message_handler.cc b/src/message_handler.cc index d5fbdd95..81576227 100644 --- a/src/message_handler.cc +++ b/src/message_handler.cc @@ -130,7 +130,7 @@ void EmitSemanticHighlighting(QueryDatabase* db, grouped_symbols; for (SymbolRef sym : file->def->all_symbols) { std::string_view detailed_name; - SymbolKind parent_kind = SymbolKind::Invalid; + lsSymbolKind parent_kind = lsSymbolKind::Unknown; lsSymbolKind kind = lsSymbolKind::Unknown; StorageClass storage = StorageClass::Invalid; // This switch statement also filters out symbols that are not highlighted. @@ -151,7 +151,7 @@ void EmitSemanticHighlighting(QueryDatabase* db, short_name.compare(0, 27, "functionspell) - parent_kind = def->spell->kind; + parent_kind = GetSymbolKind(db, *def->spell); kind = def->kind; storage = def->storage; detailed_name = short_name; @@ -180,7 +180,7 @@ void EmitSemanticHighlighting(QueryDatabase* db, kind = def.kind; detailed_name = def.detailed_name; if (def.spell) { - parent_kind = def.spell->kind; + parent_kind = GetSymbolKind(db, *def.spell); break; } } @@ -191,7 +191,7 @@ void EmitSemanticHighlighting(QueryDatabase* db, storage = def.storage; detailed_name = def.detailed_name; if (def.spell) { - parent_kind = def.spell->kind; + parent_kind = GetSymbolKind(db, *def.spell); break; } } diff --git a/src/message_handler.h b/src/message_handler.h index 1339e695..d5b79d48 100644 --- a/src/message_handler.h +++ b/src/message_handler.h @@ -29,7 +29,7 @@ struct Out_CqueryPublishSemanticHighlighting : public lsOutMessage { struct Symbol { int stableId = 0; - SymbolKind parentKind; + lsSymbolKind parentKind; lsSymbolKind kind; StorageClass storage; std::vector ranges; diff --git a/src/query_utils.cc b/src/query_utils.cc index 7361187e..7377ad17 100644 --- a/src/query_utils.cc +++ b/src/query_utils.cc @@ -266,6 +266,22 @@ std::vector GetLsLocationExs(QueryDatabase* db, return ret; } +lsSymbolKind GetSymbolKind(QueryDatabase* db, SymbolIdx sym) { + lsSymbolKind ret; + if (sym.kind == SymbolKind::File) + ret = lsSymbolKind::File; + else { + ret = lsSymbolKind::Unknown; + WithEntity(db, sym, [&](const auto& entity) { + for (auto& def : entity.def) { + ret = def.kind; + break; + } + }); + } + return ret; +} + // Returns a symbol. The symbol will have *NOT* have a location assigned. optional GetSymbolInfo(QueryDatabase* db, WorkingFiles* working_files, diff --git a/src/query_utils.h b/src/query_utils.h index 4b341086..f9a10a6a 100644 --- a/src/query_utils.h +++ b/src/query_utils.h @@ -92,6 +92,8 @@ void EachOccurrence(QueryDatabase* db, SymbolIdx sym, bool include_decl, Fn&& fn }); } +lsSymbolKind GetSymbolKind(QueryDatabase* db, SymbolIdx sym); + template void EachOccurrenceWithParent(QueryDatabase* db, SymbolIdx sym, @@ -101,12 +103,7 @@ void EachOccurrenceWithParent(QueryDatabase* db, lsSymbolKind parent_kind = lsSymbolKind::Unknown; for (auto& def : entity.def) if (def.spell) { - WithEntity(db, *def.spell, [&](const auto& entity) { - for (auto& def : entity.def) { - parent_kind = def.kind; - break; - } - }); + parent_kind = GetSymbolKind(db, sym); break; } for (Use use : entity.uses)