Report detailed name for workspace symbol search.

This fixes vscode filtering which fixes qualified name global symbol search.
This commit is contained in:
Jacob Dufault 2017-12-18 21:31:19 -08:00
parent be961fc4f2
commit a7d1c6917f
4 changed files with 36 additions and 38 deletions

View File

@ -38,7 +38,7 @@ struct TextDocumentDocumentSymbolHandler
for (SymbolRef ref : file->def->outline) { for (SymbolRef ref : file->def->outline) {
optional<lsSymbolInformation> info = optional<lsSymbolInformation> info =
GetSymbolInfo(db, working_files, ref.idx); GetSymbolInfo(db, working_files, ref.idx, true /*use_short_name*/);
if (!info) if (!info)
continue; continue;

View File

@ -5,6 +5,32 @@
#include <loguru.hpp> #include <loguru.hpp>
namespace { namespace {
// Lookup |symbol| in |db| and insert the value into |result|.
void InsertSymbolIntoResult(QueryDatabase* db,
WorkingFiles* working_files,
SymbolIdx symbol,
std::vector<lsSymbolInformation>* result) {
optional<lsSymbolInformation> info = GetSymbolInfo(db, working_files, symbol, false /*use_short_name*/);
if (!info)
return;
optional<QueryLocation> location = GetDefinitionExtentOfSymbol(db, symbol);
if (!location) {
auto decls = GetDeclarationsOfSymbolForGotoDefinition(db, symbol);
if (decls.empty())
return;
location = decls[0];
}
optional<lsLocation> ls_location =
GetLsLocation(db, working_files, *location);
if (!ls_location)
return;
info->location = *ls_location;
result->push_back(*info);
}
struct lsWorkspaceSymbolParams { struct lsWorkspaceSymbolParams {
std::string query; std::string query;
}; };

View File

@ -420,7 +420,8 @@ std::vector<lsLocation> GetLsLocations(
// Returns a symbol. The symbol will have *NOT* have a location assigned. // Returns a symbol. The symbol will have *NOT* have a location assigned.
optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db, optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
WorkingFiles* working_files, WorkingFiles* working_files,
SymbolIdx symbol) { SymbolIdx symbol,
bool use_short_name) {
switch (symbol.kind) { switch (symbol.kind) {
case SymbolKind::File: { case SymbolKind::File: {
QueryFile& file = db->files[symbol.idx]; QueryFile& file = db->files[symbol.idx];
@ -438,7 +439,7 @@ optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
return nullopt; return nullopt;
lsSymbolInformation info; 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) if (type.def->detailed_name != type.def->short_name)
info.containerName = type.def->detailed_name; info.containerName = type.def->detailed_name;
info.kind = lsSymbolKind::Class; info.kind = lsSymbolKind::Class;
@ -450,7 +451,7 @@ optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
return nullopt; return nullopt;
lsSymbolInformation info; 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.containerName = func.def->detailed_name;
info.kind = lsSymbolKind::Function; info.kind = lsSymbolKind::Function;
@ -468,7 +469,7 @@ optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
return nullopt; return nullopt;
lsSymbolInformation info; 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.containerName = var.def->detailed_name;
info.kind = lsSymbolKind::Variable; info.kind = lsSymbolKind::Variable;
return info; return info;
@ -570,27 +571,3 @@ std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile* working_file,
return symbols; return symbols;
} }
void InsertSymbolIntoResult(QueryDatabase* db,
WorkingFiles* working_files,
SymbolIdx symbol,
std::vector<lsSymbolInformation>* result) {
optional<lsSymbolInformation> info = GetSymbolInfo(db, working_files, symbol);
if (!info)
return;
optional<QueryLocation> location = GetDefinitionExtentOfSymbol(db, symbol);
if (!location) {
auto decls = GetDeclarationsOfSymbolForGotoDefinition(db, symbol);
if (decls.empty())
return;
location = decls[0];
}
optional<lsLocation> ls_location =
GetLsLocation(db, working_files, *location);
if (!ls_location)
return;
info->location = *ls_location;
result->push_back(*info);
}

View File

@ -58,7 +58,8 @@ std::vector<lsLocation> GetLsLocations(
// Returns a symbol. The symbol will have *NOT* have a location assigned. // Returns a symbol. The symbol will have *NOT* have a location assigned.
optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db, optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
WorkingFiles* working_files, WorkingFiles* working_files,
SymbolIdx symbol); SymbolIdx symbol,
bool use_short_name);
lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db, lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db,
WorkingFiles* working_files, WorkingFiles* working_files,
@ -68,9 +69,3 @@ lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db,
std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile* working_file, std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile* working_file,
QueryFile* file, QueryFile* file,
lsPosition position); lsPosition position);
// Lookup |symbol| in |db| and insert the value into |result|.
void InsertSymbolIntoResult(QueryDatabase* db,
WorkingFiles* working_files,
SymbolIdx symbol,
std::vector<lsSymbolInformation>* result);