From db50943cd7aaf61cb122fa20ba34e6e5e3e7b112 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 6b5703fd..1ce0ef2b 100644 --- a/src/messages/textDocument_documentSymbol.cc +++ b/src/messages/textDocument_documentSymbol.cc @@ -72,7 +72,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 ad15dc92..00c0aa27 100644 --- a/src/messages/workspace_symbol.cc +++ b/src/messages/workspace_symbol.cc @@ -19,8 +19,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 963166a5..bacffa11 100644 --- a/src/query_utils.cc +++ b/src/query_utils.cc @@ -274,11 +274,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; @@ -295,12 +292,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 18677329..6bf0a70a 100644 --- a/src/query_utils.h +++ b/src/query_utils.h @@ -35,11 +35,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 b8fab1f2..4d83f57c 100644 --- a/src/symbol.h +++ b/src/symbol.h @@ -64,6 +64,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);