MCPcopy Create free account
hub / github.com/MaskRay/ccls / textDocument_documentHighlight

Method textDocument_documentHighlight

src/messages/textDocument_document.cc:37–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35} // namespace
36
37void MessageHandler::textDocument_documentHighlight(TextDocumentPositionParam &param, ReplyOnce &reply) {
38 int file_id;
39 auto [file, wf] = findOrFail(param.textDocument.uri.getPath(), reply, &file_id);
40 if (!wf)
41 return;
42
43 std::vector<DocumentHighlight> result;
44 std::vector<SymbolRef> syms = findSymbolsAtLocation(wf, file, param.position, true);
45 for (auto [sym, refcnt] : file->symbol2refcnt) {
46 if (refcnt <= 0)
47 continue;
48 Usr usr = sym.usr;
49 Kind kind = sym.kind;
50 if (std::none_of(syms.begin(), syms.end(), [&](auto &sym1) { return usr == sym1.usr && kind == sym1.kind; }))
51 continue;
52 if (auto loc = getLsLocation(db, wfiles, sym, file_id)) {
53 DocumentHighlight highlight;
54 highlight.range = loc->range;
55 if (sym.role & Role::Write)
56 highlight.kind = DocumentHighlight::Write;
57 else if (sym.role & Role::Read)
58 highlight.kind = DocumentHighlight::Read;
59 else
60 highlight.kind = DocumentHighlight::Text;
61 highlight.role = sym.role;
62 result.push_back(highlight);
63 }
64 }
65 std::sort(result.begin(), result.end());
66 reply(result);
67}
68
69namespace {
70struct DocumentLink {

Callers

nothing calls this directly

Calls 6

findSymbolsAtLocationFunction · 0.85
getLsLocationFunction · 0.85
replyFunction · 0.85
beginMethod · 0.80
endMethod · 0.80
getPathMethod · 0.45

Tested by

no test coverage detected