From 71e9835b8c29f567d1f4e49545e390ec72bf65f4 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 23 Sep 2018 10:20:05 -0700 Subject: [PATCH] documentSymbol: ignore TypeParameter Reported by Riatre --- src/messages/textDocument_documentSymbol.cc | 27 ++++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/messages/textDocument_documentSymbol.cc b/src/messages/textDocument_documentSymbol.cc index f6064d19..bda4a270 100644 --- a/src/messages/textDocument_documentSymbol.cc +++ b/src/messages/textDocument_documentSymbol.cc @@ -76,6 +76,14 @@ struct Out_HierarchicalDocumentSymbol }; MAKE_REFLECT_STRUCT(Out_HierarchicalDocumentSymbol, jsonrpc, id, result); +bool IgnoreType(const QueryType::Def *def) { + return !def || def->kind == lsSymbolKind::TypeParameter; +} + +bool IgnoreVar(const QueryVar::Def *def) { + return !def || def->is_local(); +} + struct Handler_TextDocumentDocumentSymbol : BaseMessageHandler { MethodType GetMethodType() const override { return kMethodType; } @@ -140,9 +148,11 @@ struct Handler_TextDocumentDocumentSymbol kv.first = static_cast(&def); } }); - if (kv.first && sym.kind == SymbolKind::Var) - if (static_cast(kv.first)->is_local()) - kv.first = nullptr; + if (kv.first && ((sym.kind == SymbolKind::Type && + IgnoreType((const QueryType::Def *)kv.first)) || + (sym.kind == SymbolKind::Var && + IgnoreVar((const QueryVar::Def *)kv.first)))) + kv.first = nullptr; if (!kv.first) { kv.second.reset(); continue; @@ -198,12 +208,11 @@ struct Handler_TextDocumentDocumentSymbol if (refcnt <= 0) continue; if (std::optional info = GetSymbolInfo(db, sym, false)) { - if (sym.kind == SymbolKind::Var) { - QueryVar &var = db->GetVar(sym); - auto *def = var.AnyDef(); - if (!def || !def->spell || def->is_local()) - continue; - } + if ((sym.kind == SymbolKind::Type && + IgnoreType(db->GetType(sym).AnyDef())) || + (sym.kind == SymbolKind::Var && + IgnoreVar(db->GetVar(sym).AnyDef()))) + continue; if (std::optional location = GetLsLocation( db, working_files, Use{{sym.range, sym.usr, sym.kind, sym.role}, file_id})) {