2017-12-06 03:32:33 +00:00
|
|
|
#include "message_handler.h"
|
|
|
|
#include "query_utils.h"
|
2018-05-28 00:50:02 +00:00
|
|
|
#include "pipeline.hh"
|
|
|
|
using namespace ccls;
|
2017-12-06 03:32:33 +00:00
|
|
|
|
2017-12-06 05:03:38 +00:00
|
|
|
namespace {
|
2018-03-31 03:16:33 +00:00
|
|
|
MethodType kMethodType = "$ccls/vars";
|
2018-03-22 04:05:25 +00:00
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
struct In_CclsVars : public RequestInMessage {
|
2018-03-22 04:05:25 +00:00
|
|
|
MethodType GetMethodType() const override { return kMethodType; }
|
|
|
|
|
2017-12-06 04:39:44 +00:00
|
|
|
lsTextDocumentPositionParams params;
|
|
|
|
};
|
2018-03-31 03:16:33 +00:00
|
|
|
MAKE_REFLECT_STRUCT(In_CclsVars, id, params);
|
|
|
|
REGISTER_IN_MESSAGE(In_CclsVars);
|
2018-03-22 04:05:25 +00:00
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
struct Handler_CclsVars : BaseMessageHandler<In_CclsVars> {
|
2018-03-22 04:05:25 +00:00
|
|
|
MethodType GetMethodType() const override { return kMethodType; }
|
2017-12-06 04:39:44 +00:00
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
void Run(In_CclsVars* request) override {
|
2017-12-06 03:32:33 +00:00
|
|
|
QueryFile* file;
|
2017-12-31 03:18:33 +00:00
|
|
|
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)) {
|
2018-04-30 04:49:03 +00:00
|
|
|
Usr usr = sym.usr;
|
2018-02-10 06:51:58 +00:00
|
|
|
switch (sym.kind) {
|
2018-01-21 06:34:41 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case SymbolKind::Var: {
|
2018-02-18 05:52:14 +00:00
|
|
|
const QueryVar::Def* def = db->GetVar(sym).AnyDef();
|
|
|
|
if (!def || !def->type)
|
2018-01-21 06:34:41 +00:00
|
|
|
continue;
|
2018-04-30 04:49:03 +00:00
|
|
|
usr = def->type;
|
|
|
|
[[fallthrough]];
|
2018-01-21 06:34:41 +00:00
|
|
|
}
|
2018-04-30 04:49:03 +00:00
|
|
|
case SymbolKind::Type:
|
|
|
|
out.result = GetLsLocationExs(
|
|
|
|
db, working_files,
|
|
|
|
GetDeclarations(db->usr2var, db->Type(usr).instances));
|
2018-01-21 06:34:41 +00:00
|
|
|
break;
|
2017-12-06 03:32:33 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-28 00:50:02 +00:00
|
|
|
pipeline::WriteStdout(kMethodType, out);
|
2017-12-06 03:32:33 +00:00
|
|
|
}
|
|
|
|
};
|
2018-03-31 03:16:33 +00:00
|
|
|
REGISTER_MESSAGE_HANDLER(Handler_CclsVars);
|
2017-12-31 03:18:33 +00:00
|
|
|
} // namespace
|