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"
|
2018-02-13 01:15:19 +00:00
|
|
|
#include "symbol.h"
|
2017-12-06 03:32:33 +00:00
|
|
|
|
2017-12-06 05:03:38 +00:00
|
|
|
namespace {
|
2018-03-22 04:05:25 +00:00
|
|
|
MethodType kMethodType = "textDocument/documentHighlight";
|
|
|
|
|
|
|
|
struct In_TextDocumentDocumentHighlight : public RequestMessage {
|
|
|
|
MethodType GetMethodType() const override { return kMethodType; }
|
2017-12-06 04:39:44 +00:00
|
|
|
lsTextDocumentPositionParams params;
|
|
|
|
};
|
2018-03-22 04:05:25 +00:00
|
|
|
MAKE_REFLECT_STRUCT(In_TextDocumentDocumentHighlight, id, params);
|
|
|
|
REGISTER_IN_MESSAGE(In_TextDocumentDocumentHighlight);
|
2017-12-06 04:39:44 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-03-22 04:05:25 +00:00
|
|
|
struct Handler_TextDocumentDocumentHighlight
|
|
|
|
: BaseMessageHandler<In_TextDocumentDocumentHighlight> {
|
|
|
|
MethodType GetMethodType() const override { return kMethodType; }
|
|
|
|
void Run(In_TextDocumentDocumentHighlight* request) override {
|
2017-12-06 03:32:33 +00:00
|
|
|
QueryFileId file_id;
|
|
|
|
QueryFile* file;
|
2017-12-31 03:18:33 +00:00
|
|
|
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-23 23:27:21 +00:00
|
|
|
EachOccurrence(db, sym, true, [&](Use use) {
|
2018-02-12 04:22:47 +00:00
|
|
|
if (use.file != file_id)
|
2018-02-21 01:50:48 +00:00
|
|
|
return;
|
|
|
|
if (optional<lsLocation> ls_loc =
|
|
|
|
GetLsLocation(db, working_files, use)) {
|
|
|
|
lsDocumentHighlight highlight;
|
|
|
|
highlight.range = ls_loc->range;
|
|
|
|
if (use.role & Role::Write)
|
|
|
|
highlight.kind = lsDocumentHighlightKind::Write;
|
|
|
|
else if (use.role & Role::Read)
|
|
|
|
highlight.kind = lsDocumentHighlightKind::Read;
|
|
|
|
else
|
|
|
|
highlight.kind = lsDocumentHighlightKind::Text;
|
|
|
|
highlight.role = use.role;
|
|
|
|
out.result.push_back(highlight);
|
|
|
|
}
|
|
|
|
});
|
2017-12-06 03:32:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-03-22 04:05:25 +00:00
|
|
|
QueueManager::WriteStdout(kMethodType, out);
|
2017-12-06 03:32:33 +00:00
|
|
|
}
|
|
|
|
};
|
2018-03-22 04:05:25 +00:00
|
|
|
REGISTER_MESSAGE_HANDLER(Handler_TextDocumentDocumentHighlight);
|
2017-12-31 03:18:33 +00:00
|
|
|
} // namespace
|