From 15ec6036e7c647f115cd6df2e5517d16b88f8f74 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 7 Mar 2018 00:56:47 -0800 Subject: [PATCH] Set parentKind of Func/Var from declarations if they have no definition --- src/message_handler.cc | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/message_handler.cc b/src/message_handler.cc index 81576227..61e3da25 100644 --- a/src/message_handler.cc +++ b/src/message_handler.cc @@ -136,14 +136,18 @@ void EmitSemanticHighlighting(QueryDatabase* db, // This switch statement also filters out symbols that are not highlighted. switch (sym.kind) { case SymbolKind::Func: { - const QueryFunc::Def* def = nullptr; - for (auto& i : db->GetFunc(sym).def) { - def = &i; - if (i.spell) - break; - } + const QueryFunc& func = db->GetFunc(sym); + const QueryFunc::Def* def = func.AnyDef(); if (!def) continue; // applies to for loop + if (def->spell) + parent_kind = GetSymbolKind(db, *def->spell); + if (parent_kind == lsSymbolKind::Unknown) { + for (Use use: func.declarations) { + parent_kind = GetSymbolKind(db, use); + break; + } + } // Don't highlight overloadable operators or implicit lambda -> // std::function constructor. std::string_view short_name = def->ShortName(); @@ -185,8 +189,9 @@ void EmitSemanticHighlighting(QueryDatabase* db, } } break; - case SymbolKind::Var: - for (auto& def : db->GetVar(sym).def) { + case SymbolKind::Var: { + const QueryVar& var = db->GetVar(sym); + for (auto& def : var.def) { kind = def.kind; storage = def.storage; detailed_name = def.detailed_name; @@ -195,7 +200,14 @@ void EmitSemanticHighlighting(QueryDatabase* db, break; } } + if (parent_kind == lsSymbolKind::Unknown) { + for (Use use : var.declarations) { + parent_kind = GetSymbolKind(db, use); + break; + } + } break; + } default: continue; // applies to for loop }