ccls/src/messages/cquery_vars.cc

58 lines
1.6 KiB
C++
Raw Normal View History

2017-12-06 03:32:33 +00:00
#include "message_handler.h"
#include "query_utils.h"
2017-12-29 16:29:47 +00:00
#include "queue_manager.h"
2017-12-06 03:32:33 +00:00
namespace {
MethodType kMethodType = "$cquery/vars";
2018-03-22 05:01:21 +00:00
struct In_CqueryVars : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
2017-12-06 04:39:44 +00:00
lsTextDocumentPositionParams params;
};
MAKE_REFLECT_STRUCT(In_CqueryVars, id, params);
REGISTER_IN_MESSAGE(In_CqueryVars);
struct Handler_CqueryVars : BaseMessageHandler<In_CqueryVars> {
MethodType GetMethodType() const override { return kMethodType; }
2017-12-06 04:39:44 +00:00
void Run(In_CqueryVars* request) override {
2017-12-06 03:32:33 +00:00
QueryFile* file;
if (!FindFileOrFail(db, project, request->id,
2017-12-06 03:32:33 +00:00
request->params.textDocument.uri.GetPath(), &file)) {
return;
}
WorkingFile* working_file =
working_files->GetFileByFilename(file->def->path);
Out_LocationList out;
out.id = request->id;
2018-02-10 06:51:58 +00:00
for (SymbolRef sym :
2017-12-06 03:32:33 +00:00
FindSymbolsAtLocation(working_file, file, request->params.position)) {
Id<void> id = sym.id;
2018-02-10 06:51:58 +00:00
switch (sym.kind) {
default:
break;
case SymbolKind::Var: {
const QueryVar::Def* def = db->GetVar(sym).AnyDef();
if (!def || !def->type)
continue;
id = *def->type;
}
// fallthrough
case SymbolKind::Type: {
QueryType& type = db->types[id.id];
out.result = GetLsLocationExs(
db, working_files, GetDeclarations(db, type.instances),
config->xref.container, config->xref.maxNum);
break;
}
2017-12-06 03:32:33 +00:00
}
}
QueueManager::WriteStdout(kMethodType, out);
2017-12-06 03:32:33 +00:00
}
};
REGISTER_MESSAGE_HANDLER(Handler_CqueryVars);
} // namespace