More improvements to semantic highlighting. Still not done though.

This commit is contained in:
Jacob Dufault 2017-11-11 11:18:55 -08:00
parent 8145a06534
commit 5fa7fbf0d2
3 changed files with 42 additions and 18 deletions

View File

@ -161,29 +161,51 @@ void EmitSemanticHighlighting(QueryDatabase* db,
};
// Group symbols together.
std::unordered_map<SymbolIdx, NonElidedVector<lsRange>> grouped_symbols;
std::unordered_map<SymbolIdx, Out_CqueryPublishSemanticHighlighting::Symbol>
grouped_symbols;
for (SymbolRef sym : file->def->all_symbols) {
if (sym.idx.kind == SymbolKind::Var) {
bool is_type_member = false;
switch (sym.idx.kind) {
case SymbolKind::Func: {
QueryFunc* func = &db->funcs[sym.idx.idx];
if (!func->def)
continue; // applies to for loop
is_type_member = func->def->declaring_type.has_value();
break;
}
case SymbolKind::Var: {
QueryVar* var = &db->vars[sym.idx.idx];
if (!var->def)
continue;
if (!var->def->is_local)
continue;
continue; // applies to for loop
if (!var->def->is_local && !var->def->declaring_type)
continue; // applies to for loop
is_type_member = var->def->declaring_type.has_value();
break;
}
default:
continue; // applies to for loop
}
optional<lsRange> loc = GetLsRange(working_file, sym.loc.range);
if (loc)
grouped_symbols[sym.idx].push_back(*loc);
if (loc) {
auto it = grouped_symbols.find(sym.idx);
if (it != grouped_symbols.end()) {
it->second.ranges.push_back(*loc);
} else {
Out_CqueryPublishSemanticHighlighting::Symbol symbol;
symbol.type = map_symbol_kind_to_symbol_type(sym.idx.kind);
symbol.is_type_member = is_type_member;
symbol.ranges.push_back(*loc);
grouped_symbols[sym.idx] = symbol;
}
}
}
// Publish.
Out_CqueryPublishSemanticHighlighting out;
out.params.uri = lsDocumentUri::FromPath(working_file->filename);
for (auto& entry : grouped_symbols) {
Out_CqueryPublishSemanticHighlighting::Symbol symbol;
symbol.type = map_symbol_kind_to_symbol_type(entry.first.kind);
symbol.ranges = entry.second;
out.params.symbols.push_back(symbol);
}
for (auto& entry : grouped_symbols)
out.params.symbols.push_back(entry.second);
IpcManager::instance()->SendOutMessageToClient(
IpcId::CqueryPublishSemanticHighlighting, out);
}

View File

@ -373,10 +373,10 @@ struct VarDefDefinitionData {
// Type of the variable.
optional<TypeId> variable_type;
// Type which declares this one (ie, it is a method)
// Type which declares this one.
optional<TypeId> declaring_type;
// Is this a "local" variable, ie, a parameter or function variable?
// Is this a parameter or function variable?
bool is_local = false;
// Is this a macro, ie, #define FOO?
bool is_macro = false;

View File

@ -1484,7 +1484,8 @@ struct Out_CqueryPublishSemanticHighlighting
: public lsOutMessage<Out_CqueryPublishSemanticHighlighting> {
enum class SymbolType { Type = 0, Function, Variable };
struct Symbol {
SymbolType type;
SymbolType type = SymbolType::Type;
bool is_type_member = false;
NonElidedVector<lsRange> ranges;
};
struct Params {
@ -1497,6 +1498,7 @@ struct Out_CqueryPublishSemanticHighlighting
MAKE_REFLECT_TYPE_PROXY(Out_CqueryPublishSemanticHighlighting::SymbolType, int);
MAKE_REFLECT_STRUCT(Out_CqueryPublishSemanticHighlighting::Symbol,
type,
is_type_member,
ranges);
MAKE_REFLECT_STRUCT(Out_CqueryPublishSemanticHighlighting::Params,
uri,