Browse Source

textDocument/documentSymbol

pull/522/head
Fangrui Song 6 years ago
parent
commit
db50943cd7
  1. 2
      src/messages/textDocument_documentSymbol.cc
  2. 3
      src/messages/workspace_symbol.cc
  3. 10
      src/query_utils.cc
  4. 8
      src/query_utils.h
  5. 2
      src/symbol.h

2
src/messages/textDocument_documentSymbol.cc

@ -72,7 +72,7 @@ struct Handler_TextDocumentDocumentSymbol
for (auto [sym, refcnt] : symbol2refcnt) {
if (refcnt <= 0) continue;
if (std::optional<lsSymbolInformation> 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();

3
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<std::tuple<lsSymbolInformation, int, SymbolIdx>> *result) {
std::optional<lsSymbolInformation> info =
GetSymbolInfo(db, working_files, sym, true);
std::optional<lsSymbolInformation> info = GetSymbolInfo(db, sym, true);
if (!info)
return false;

10
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<lsSymbolInformation> GetSymbolInfo(DB *db,
WorkingFiles *working_files,
SymbolIdx sym,
bool detailed_name) {
std::optional<lsSymbolInformation> GetSymbolInfo(DB *db, SymbolIdx sym,
bool detailed) {
switch (sym.kind) {
case SymbolKind::Invalid:
break;
@ -295,12 +292,11 @@ std::optional<lsSymbolInformation> 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;

8
src/query_utils.h

@ -35,11 +35,9 @@ std::optional<lsLocationEx> GetLsLocationEx(DB *db, WorkingFiles *working_files,
Use use, bool container);
std::vector<lsLocationEx> GetLsLocationExs(DB *db, WorkingFiles *working_files,
const std::vector<Use> &refs);
// Returns a symbol. The symbol will have *NOT* have a location assigned.
std::optional<lsSymbolInformation> GetSymbolInfo(DB *db,
WorkingFiles *working_files,
SymbolIdx sym,
bool detailed_name);
// Returns a symbol. The symbol will *NOT* have a location assigned.
std::optional<lsSymbolInformation> GetSymbolInfo(DB *db, SymbolIdx sym,
bool detailed);
std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile *working_file,
QueryFile *file,

2
src/symbol.h

@ -64,6 +64,6 @@ struct lsSymbolInformation {
std::string_view name;
lsSymbolKind kind;
lsLocation location;
std::string_view containerName;
std::optional<std::string_view> containerName;
};
MAKE_REFLECT_STRUCT(lsSymbolInformation, name, kind, location, containerName);

Loading…
Cancel
Save