textDocument/documentSymbol

This commit is contained in:
Fangrui Song 2018-09-12 21:03:35 -07:00
parent d758b78635
commit db50943cd7
5 changed files with 9 additions and 16 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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;

View File

@ -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,

View File

@ -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);