parentKind in semantic highlighting: SymbolKind -> lsSymbolKind

This commit is contained in:
Fangrui Song 2018-03-07 00:29:53 -08:00
parent 6815f1312f
commit 57f2c325f0
4 changed files with 24 additions and 11 deletions

View File

@ -130,7 +130,7 @@ void EmitSemanticHighlighting(QueryDatabase* db,
grouped_symbols; grouped_symbols;
for (SymbolRef sym : file->def->all_symbols) { for (SymbolRef sym : file->def->all_symbols) {
std::string_view detailed_name; std::string_view detailed_name;
SymbolKind parent_kind = SymbolKind::Invalid; lsSymbolKind parent_kind = lsSymbolKind::Unknown;
lsSymbolKind kind = lsSymbolKind::Unknown; lsSymbolKind kind = lsSymbolKind::Unknown;
StorageClass storage = StorageClass::Invalid; StorageClass storage = StorageClass::Invalid;
// This switch statement also filters out symbols that are not highlighted. // This switch statement also filters out symbols that are not highlighted.
@ -151,7 +151,7 @@ void EmitSemanticHighlighting(QueryDatabase* db,
short_name.compare(0, 27, "function<type-parameter-0-0") == 0) short_name.compare(0, 27, "function<type-parameter-0-0") == 0)
continue; // applies to for loop continue; // applies to for loop
if (def->spell) if (def->spell)
parent_kind = def->spell->kind; parent_kind = GetSymbolKind(db, *def->spell);
kind = def->kind; kind = def->kind;
storage = def->storage; storage = def->storage;
detailed_name = short_name; detailed_name = short_name;
@ -180,7 +180,7 @@ void EmitSemanticHighlighting(QueryDatabase* db,
kind = def.kind; kind = def.kind;
detailed_name = def.detailed_name; detailed_name = def.detailed_name;
if (def.spell) { if (def.spell) {
parent_kind = def.spell->kind; parent_kind = GetSymbolKind(db, *def.spell);
break; break;
} }
} }
@ -191,7 +191,7 @@ void EmitSemanticHighlighting(QueryDatabase* db,
storage = def.storage; storage = def.storage;
detailed_name = def.detailed_name; detailed_name = def.detailed_name;
if (def.spell) { if (def.spell) {
parent_kind = def.spell->kind; parent_kind = GetSymbolKind(db, *def.spell);
break; break;
} }
} }

View File

@ -29,7 +29,7 @@ struct Out_CqueryPublishSemanticHighlighting
: public lsOutMessage<Out_CqueryPublishSemanticHighlighting> { : public lsOutMessage<Out_CqueryPublishSemanticHighlighting> {
struct Symbol { struct Symbol {
int stableId = 0; int stableId = 0;
SymbolKind parentKind; lsSymbolKind parentKind;
lsSymbolKind kind; lsSymbolKind kind;
StorageClass storage; StorageClass storage;
std::vector<lsRange> ranges; std::vector<lsRange> ranges;

View File

@ -266,6 +266,22 @@ std::vector<lsLocationEx> GetLsLocationExs(QueryDatabase* db,
return ret; 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. // Returns a symbol. The symbol will have *NOT* have a location assigned.
optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db, optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
WorkingFiles* working_files, WorkingFiles* working_files,

View File

@ -92,6 +92,8 @@ void EachOccurrence(QueryDatabase* db, SymbolIdx sym, bool include_decl, Fn&& fn
}); });
} }
lsSymbolKind GetSymbolKind(QueryDatabase* db, SymbolIdx sym);
template <typename Fn> template <typename Fn>
void EachOccurrenceWithParent(QueryDatabase* db, void EachOccurrenceWithParent(QueryDatabase* db,
SymbolIdx sym, SymbolIdx sym,
@ -101,12 +103,7 @@ void EachOccurrenceWithParent(QueryDatabase* db,
lsSymbolKind parent_kind = lsSymbolKind::Unknown; lsSymbolKind parent_kind = lsSymbolKind::Unknown;
for (auto& def : entity.def) for (auto& def : entity.def)
if (def.spell) { if (def.spell) {
WithEntity(db, *def.spell, [&](const auto& entity) { parent_kind = GetSymbolKind(db, sym);
for (auto& def : entity.def) {
parent_kind = def.kind;
break;
}
});
break; break;
} }
for (Use use : entity.uses) for (Use use : entity.uses)