documentSymbol: ignore TypeParameter

Reported by Riatre
This commit is contained in:
Fangrui Song 2018-09-23 10:20:05 -07:00
parent 3abbca6474
commit f82a436536

View File

@ -64,6 +64,14 @@ struct Out_HierarchicalDocumentSymbol
}; };
MAKE_REFLECT_STRUCT(Out_HierarchicalDocumentSymbol, jsonrpc, id, result); 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 struct Handler_TextDocumentDocumentSymbol
: BaseMessageHandler<In_TextDocumentDocumentSymbol> { : BaseMessageHandler<In_TextDocumentDocumentSymbol> {
MethodType GetMethodType() const override { return kMethodType; } MethodType GetMethodType() const override { return kMethodType; }
@ -128,8 +136,10 @@ struct Handler_TextDocumentDocumentSymbol
kv.first = static_cast<const void *>(&def); kv.first = static_cast<const void *>(&def);
} }
}); });
if (kv.first && sym.kind == SymbolKind::Var) if (kv.first && ((sym.kind == SymbolKind::Type &&
if (static_cast<const QueryVar::Def *>(kv.first)->is_local()) IgnoreType((const QueryType::Def *)kv.first)) ||
(sym.kind == SymbolKind::Var &&
IgnoreVar((const QueryVar::Def *)kv.first))))
kv.first = nullptr; kv.first = nullptr;
if (!kv.first) { if (!kv.first) {
kv.second.reset(); kv.second.reset();
@ -186,12 +196,11 @@ struct Handler_TextDocumentDocumentSymbol
if (refcnt <= 0) continue; if (refcnt <= 0) continue;
if (std::optional<lsSymbolInformation> info = if (std::optional<lsSymbolInformation> info =
GetSymbolInfo(db, sym, false)) { GetSymbolInfo(db, sym, false)) {
if (sym.kind == SymbolKind::Var) { if ((sym.kind == SymbolKind::Type &&
QueryVar &var = db->GetVar(sym); IgnoreType(db->GetType(sym).AnyDef())) ||
auto *def = var.AnyDef(); (sym.kind == SymbolKind::Var &&
if (!def || !def->spell || def->is_local()) IgnoreVar(db->GetVar(sym).AnyDef())))
continue; continue;
}
if (std::optional<lsLocation> location = GetLsLocation( if (std::optional<lsLocation> location = GetLsLocation(
db, working_files, db, working_files,
Use{{sym.range, sym.usr, sym.kind, sym.role}, file_id})) { Use{{sym.range, sym.usr, sym.kind, sym.role}, file_id})) {