forked from MaskRay/ccls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cquery_base.cc
52 lines (44 loc) · 1.64 KB
/
cquery_base.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
namespace {
MethodType kMethodType = "$cquery/base";
struct In_CqueryBase : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsTextDocumentPositionParams params;
};
MAKE_REFLECT_STRUCT(In_CqueryBase, id, params);
REGISTER_IN_MESSAGE(In_CqueryBase);
struct Handler_CqueryBase : BaseMessageHandler<In_CqueryBase> {
MethodType GetMethodType() const override { return kMethodType; }
void Run(In_CqueryBase* request) override {
QueryFile* file;
if (!FindFileOrFail(db, project, request->id,
request->params.textDocument.uri.GetPath(), &file)) {
return;
}
WorkingFile* working_file =
working_files->GetFileByFilename(file->def->path);
Out_LocationList out;
out.id = request->id;
for (SymbolRef sym :
FindSymbolsAtLocation(working_file, file, request->params.position)) {
if (sym.kind == SymbolKind::Type) {
if (const auto* def = db->GetType(sym).AnyDef())
out.result = GetLsLocationExs(
db, working_files, GetDeclarations(db, def->bases),
config->xref.container, config->xref.maxNum);
break;
} else if (sym.kind == SymbolKind::Func) {
if (const auto* def = db->GetFunc(sym).AnyDef())
out.result = GetLsLocationExs(
db, working_files, GetDeclarations(db, def->bases),
config->xref.container, config->xref.maxNum);
break;
}
}
QueueManager::WriteStdout(kMethodType, out);
}
};
REGISTER_MESSAGE_HANDLER(Handler_CqueryBase);
} // namespace