ccls/src/messages/text_document_highlight.cc

65 lines
2.1 KiB
C++
Raw Normal View History

2017-12-06 03:32:33 +00:00
#include "message_handler.h"
#include "query_utils.h"
2017-12-29 16:29:47 +00:00
#include "queue_manager.h"
2017-12-06 03:32:33 +00:00
namespace {
2017-12-06 04:39:44 +00:00
struct Ipc_TextDocumentDocumentHighlight
: public RequestMessage<Ipc_TextDocumentDocumentHighlight> {
2017-12-06 04:39:44 +00:00
const static IpcId kIpcId = IpcId::TextDocumentDocumentHighlight;
lsTextDocumentPositionParams params;
};
MAKE_REFLECT_STRUCT(Ipc_TextDocumentDocumentHighlight, id, params);
REGISTER_IPC_MESSAGE(Ipc_TextDocumentDocumentHighlight);
struct Out_TextDocumentDocumentHighlight
: public lsOutMessage<Out_TextDocumentDocumentHighlight> {
lsRequestId id;
2017-12-12 05:20:29 +00:00
std::vector<lsDocumentHighlight> result;
2017-12-06 04:39:44 +00:00
};
MAKE_REFLECT_STRUCT(Out_TextDocumentDocumentHighlight, jsonrpc, id, result);
2017-12-06 03:32:33 +00:00
struct TextDocumentDocumentHighlightHandler
: BaseMessageHandler<Ipc_TextDocumentDocumentHighlight> {
void Run(Ipc_TextDocumentDocumentHighlight* request) override {
QueryFileId file_id;
QueryFile* file;
if (!FindFileOrFail(db, project, request->id,
2017-12-06 03:32:33 +00:00
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;
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)) {
// Found symbol. Return references to highlight.
2018-02-09 17:42:10 +00:00
std::vector<Reference> uses = GetUsesOfSymbol(db, sym, true);
2017-12-06 03:32:33 +00:00
out.result.reserve(uses.size());
2018-02-10 06:51:58 +00:00
for (Reference use : uses) {
2018-02-10 03:07:45 +00:00
if (db->GetFileId(use) != file_id)
2017-12-06 03:32:33 +00:00
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;
}
2017-12-24 00:25:18 +00:00
QueueManager::WriteStdout(IpcId::TextDocumentDocumentHighlight, out);
2017-12-06 03:32:33 +00:00
}
};
REGISTER_MESSAGE_HANDLER(TextDocumentDocumentHighlightHandler);
} // namespace