mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-28 10:31:56 +00:00
47 lines
1.4 KiB
C++
47 lines
1.4 KiB
C++
|
#include "message_handler.h"
|
||
|
#include "query_utils.h"
|
||
|
|
||
|
struct TextDocumentDocumentHighlightHandler
|
||
|
: BaseMessageHandler<Ipc_TextDocumentDocumentHighlight> {
|
||
|
void Run(Ipc_TextDocumentDocumentHighlight* request) override {
|
||
|
QueryFileId file_id;
|
||
|
QueryFile* file;
|
||
|
if (!FindFileOrFail(db, request->id,
|
||
|
request->params.textDocument.uri.GetPath(), &file,
|
||
|
&file_id)) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
WorkingFile* working_file =
|
||
|
working_files->GetFileByFilename(file->def->path);
|
||
|
|
||
|
Out_TextDocumentDocumentHighlight out;
|
||
|
out.id = request->id;
|
||
|
|
||
|
for (const SymbolRef& ref :
|
||
|
FindSymbolsAtLocation(working_file, file, request->params.position)) {
|
||
|
// Found symbol. Return references to highlight.
|
||
|
std::vector<QueryLocation> uses = GetUsesOfSymbol(db, ref.idx);
|
||
|
out.result.reserve(uses.size());
|
||
|
for (const QueryLocation& use : uses) {
|
||
|
if (use.path != file_id)
|
||
|
continue;
|
||
|
|
||
|
optional<lsLocation> ls_location =
|
||
|
GetLsLocation(db, working_files, use);
|
||
|
if (!ls_location)
|
||
|
continue;
|
||
|
|
||
|
lsDocumentHighlight highlight;
|
||
|
highlight.kind = lsDocumentHighlightKind::Text;
|
||
|
highlight.range = ls_location->range;
|
||
|
out.result.push_back(highlight);
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
IpcManager::WriteStdout(IpcId::TextDocumentDocumentHighlight, out);
|
||
|
}
|
||
|
};
|
||
|
REGISTER_MESSAGE_HANDLER(TextDocumentDocumentHighlightHandler);
|