From 196973178143303adfaf13d8393ff3459781f557 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 12 Sep 2018 21:03:35 -0700 Subject: [PATCH] textDocument/documentSymbol --- src/messages/textDocument_documentSymbol.cc | 2 +- src/messages/workspace_symbol.cc | 3 +-- src/query_utils.cc | 10 +++------- src/query_utils.h | 8 +++----- src/symbol.h | 2 +- 5 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/messages/textDocument_documentSymbol.cc b/src/messages/textDocument_documentSymbol.cc index 53b63960..9991cc93 100644 --- a/src/messages/textDocument_documentSymbol.cc +++ b/src/messages/textDocument_documentSymbol.cc @@ -84,7 +84,7 @@ struct Handler_TextDocumentDocumentSymbol for (auto [sym, refcnt] : symbol2refcnt) { if (refcnt <= 0) continue; if (std::optional info = - GetSymbolInfo(db, working_files, sym, false)) { + GetSymbolInfo(db, sym, false)) { if (sym.kind == SymbolKind::Var) { QueryVar &var = db->GetVar(sym); auto *def = var.AnyDef(); diff --git a/src/messages/workspace_symbol.cc b/src/messages/workspace_symbol.cc index 2449e072..c78e9462 100644 --- a/src/messages/workspace_symbol.cc +++ b/src/messages/workspace_symbol.cc @@ -31,8 +31,7 @@ MethodType kMethodType = "workspace/symbol"; bool AddSymbol( DB *db, WorkingFiles *working_files, SymbolIdx sym, bool use_detailed, std::vector> *result) { - std::optional info = - GetSymbolInfo(db, working_files, sym, true); + std::optional info = GetSymbolInfo(db, sym, true); if (!info) return false; diff --git a/src/query_utils.cc b/src/query_utils.cc index 749b9088..4390ae14 100644 --- a/src/query_utils.cc +++ b/src/query_utils.cc @@ -286,11 +286,8 @@ lsSymbolKind GetSymbolKind(DB *db, SymbolIdx sym) { return ret; } -// Returns a symbol. The symbol will have *NOT* have a location assigned. -std::optional GetSymbolInfo(DB *db, - WorkingFiles *working_files, - SymbolIdx sym, - bool detailed_name) { +std::optional GetSymbolInfo(DB *db, SymbolIdx sym, + bool detailed) { switch (sym.kind) { case SymbolKind::Invalid: break; @@ -307,12 +304,11 @@ std::optional GetSymbolInfo(DB *db, default: { lsSymbolInformation info; EachEntityDef(db, sym, [&](const auto &def) { - if (detailed_name) + if (detailed) info.name = def.detailed_name; else info.name = def.Name(true); info.kind = def.kind; - info.containerName = def.detailed_name; return false; }); return info; diff --git a/src/query_utils.h b/src/query_utils.h index 262fbdfa..cd07d963 100644 --- a/src/query_utils.h +++ b/src/query_utils.h @@ -47,11 +47,9 @@ std::optional GetLsLocationEx(DB *db, WorkingFiles *working_files, Use use, bool container); std::vector GetLsLocationExs(DB *db, WorkingFiles *working_files, const std::vector &refs); -// Returns a symbol. The symbol will have *NOT* have a location assigned. -std::optional GetSymbolInfo(DB *db, - WorkingFiles *working_files, - SymbolIdx sym, - bool detailed_name); +// Returns a symbol. The symbol will *NOT* have a location assigned. +std::optional GetSymbolInfo(DB *db, SymbolIdx sym, + bool detailed); std::vector FindSymbolsAtLocation(WorkingFile *working_file, QueryFile *file, diff --git a/src/symbol.h b/src/symbol.h index a4f3c05d..16e4de11 100644 --- a/src/symbol.h +++ b/src/symbol.h @@ -76,6 +76,6 @@ struct lsSymbolInformation { std::string_view name; lsSymbolKind kind; lsLocation location; - std::string_view containerName; + std::optional containerName; }; MAKE_REFLECT_STRUCT(lsSymbolInformation, name, kind, location, containerName);