ccls/src/messages/ccls_vars.cc
Fangrui Song 8835a555f8 Delay requests if the document has not not indexed (#176)
This fixes a plethora of "not indexed" errors when the document has not been indexed.

* Message handler throws NotIndexed if not overdue
* The message is put into backlog and tagged with backlog_path
* path2backlog[path] tracks backlog associated with document `path`
* The backlog is cleared when the index is merged
* backlog[0] is forced to run if it becomes overdue
2019-11-09 20:09:13 -08:00

52 lines
1.2 KiB
C++

// Copyright 2017-2018 ccls Authors
// SPDX-License-Identifier: Apache-2.0
#include "message_handler.hh"
#include "pipeline.hh"
#include "query.hh"
namespace ccls {
namespace {
struct Param : TextDocumentPositionParam {
// 1: field
// 2: local
// 4: parameter
unsigned kind = ~0u;
};
REFLECT_STRUCT(Param, textDocument, position, kind);
} // namespace
void MessageHandler::ccls_vars(JsonReader &reader, ReplyOnce &reply) {
Param param;
Reflect(reader, param);
auto [file, wf] = FindOrFail(param.textDocument.uri.GetPath(), reply);
if (!wf) {
return;
}
std::vector<Location> result;
for (SymbolRef sym : FindSymbolsAtLocation(wf, file, param.position)) {
Usr usr = sym.usr;
switch (sym.kind) {
default:
break;
case Kind::Var: {
const QueryVar::Def *def = db->GetVar(sym).AnyDef();
if (!def || !def->type)
continue;
usr = def->type;
[[fallthrough]];
}
case Kind::Type: {
for (DeclRef dr :
GetVarDeclarations(db, db->Type(usr).instances, param.kind))
if (auto loc = GetLocationLink(db, wfiles, dr))
result.push_back(Location(std::move(loc)));
break;
}
}
}
reply(result);
}
} // namespace ccls