-
Notifications
You must be signed in to change notification settings - Fork 262
/
ccls_vars.cc
50 lines (46 loc) · 1.2 KB
/
ccls_vars.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
// 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->getType(usr).instances, param.kind))
if (auto loc = getLocationLink(db, wfiles, dr))
result.push_back(Location(std::move(loc)));
break;
}
}
}
reply(result);
}
} // namespace ccls