From a7d1c6917f051301795ebe5d498c488f85a346ee Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Mon, 18 Dec 2017 21:31:19 -0800 Subject: [PATCH] Report detailed name for workspace symbol search. This fixes vscode filtering which fixes qualified name global symbol search. --- src/messages/text_document_document_symbol.cc | 2 +- src/messages/workspace_symbol.cc | 26 ++++++++++++++ src/query_utils.cc | 35 ++++--------------- src/query_utils.h | 11 ++---- 4 files changed, 36 insertions(+), 38 deletions(-) diff --git a/src/messages/text_document_document_symbol.cc b/src/messages/text_document_document_symbol.cc index b27f0d4a..ecdcf2c2 100644 --- a/src/messages/text_document_document_symbol.cc +++ b/src/messages/text_document_document_symbol.cc @@ -38,7 +38,7 @@ struct TextDocumentDocumentSymbolHandler for (SymbolRef ref : file->def->outline) { optional info = - GetSymbolInfo(db, working_files, ref.idx); + GetSymbolInfo(db, working_files, ref.idx, true /*use_short_name*/); if (!info) continue; diff --git a/src/messages/workspace_symbol.cc b/src/messages/workspace_symbol.cc index bdef766b..31ef00c4 100644 --- a/src/messages/workspace_symbol.cc +++ b/src/messages/workspace_symbol.cc @@ -5,6 +5,32 @@ #include namespace { + +// Lookup |symbol| in |db| and insert the value into |result|. +void InsertSymbolIntoResult(QueryDatabase* db, + WorkingFiles* working_files, + SymbolIdx symbol, + std::vector* result) { + optional info = GetSymbolInfo(db, working_files, symbol, false /*use_short_name*/); + if (!info) + return; + + optional location = GetDefinitionExtentOfSymbol(db, symbol); + if (!location) { + auto decls = GetDeclarationsOfSymbolForGotoDefinition(db, symbol); + if (decls.empty()) + return; + location = decls[0]; + } + + optional ls_location = + GetLsLocation(db, working_files, *location); + if (!ls_location) + return; + info->location = *ls_location; + result->push_back(*info); +} + struct lsWorkspaceSymbolParams { std::string query; }; diff --git a/src/query_utils.cc b/src/query_utils.cc index 072322c3..547fcbb0 100644 --- a/src/query_utils.cc +++ b/src/query_utils.cc @@ -420,7 +420,8 @@ std::vector GetLsLocations( // Returns a symbol. The symbol will have *NOT* have a location assigned. optional GetSymbolInfo(QueryDatabase* db, WorkingFiles* working_files, - SymbolIdx symbol) { + SymbolIdx symbol, + bool use_short_name) { switch (symbol.kind) { case SymbolKind::File: { QueryFile& file = db->files[symbol.idx]; @@ -438,7 +439,7 @@ optional GetSymbolInfo(QueryDatabase* db, return nullopt; lsSymbolInformation info; - info.name = type.def->short_name; + info.name = use_short_name ? type.def->short_name : type.def->detailed_name; if (type.def->detailed_name != type.def->short_name) info.containerName = type.def->detailed_name; info.kind = lsSymbolKind::Class; @@ -450,7 +451,7 @@ optional GetSymbolInfo(QueryDatabase* db, return nullopt; lsSymbolInformation info; - info.name = func.def->short_name; + info.name = use_short_name ? func.def->short_name : func.def->detailed_name; info.containerName = func.def->detailed_name; info.kind = lsSymbolKind::Function; @@ -468,7 +469,7 @@ optional GetSymbolInfo(QueryDatabase* db, return nullopt; lsSymbolInformation info; - info.name += var.def->short_name; + info.name = use_short_name ? var.def->short_name : var.def->detailed_name; info.containerName = var.def->detailed_name; info.kind = lsSymbolKind::Variable; return info; @@ -569,28 +570,4 @@ std::vector FindSymbolsAtLocation(WorkingFile* working_file, }); return symbols; -} - -void InsertSymbolIntoResult(QueryDatabase* db, - WorkingFiles* working_files, - SymbolIdx symbol, - std::vector* result) { - optional info = GetSymbolInfo(db, working_files, symbol); - if (!info) - return; - - optional location = GetDefinitionExtentOfSymbol(db, symbol); - if (!location) { - auto decls = GetDeclarationsOfSymbolForGotoDefinition(db, symbol); - if (decls.empty()) - return; - location = decls[0]; - } - - optional ls_location = - GetLsLocation(db, working_files, *location); - if (!ls_location) - return; - info->location = *ls_location; - result->push_back(*info); -} +} \ No newline at end of file diff --git a/src/query_utils.h b/src/query_utils.h index a13c5fac..45c1820a 100644 --- a/src/query_utils.h +++ b/src/query_utils.h @@ -58,7 +58,8 @@ std::vector GetLsLocations( // Returns a symbol. The symbol will have *NOT* have a location assigned. optional GetSymbolInfo(QueryDatabase* db, WorkingFiles* working_files, - SymbolIdx symbol); + SymbolIdx symbol, + bool use_short_name); lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db, WorkingFiles* working_files, @@ -67,10 +68,4 @@ lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db, std::vector FindSymbolsAtLocation(WorkingFile* working_file, QueryFile* file, - lsPosition position); - -// Lookup |symbol| in |db| and insert the value into |result|. -void InsertSymbolIntoResult(QueryDatabase* db, - WorkingFiles* working_files, - SymbolIdx symbol, - std::vector* result); \ No newline at end of file + lsPosition position); \ No newline at end of file