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;
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, "function<type-parameter-0-0") == 0)
continue; // applies to for loop
if (def->spell)
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;
}
}

View File

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

View File

@ -266,6 +266,22 @@ std::vector<lsLocationEx> 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<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
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>
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)