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
|
|
|
|
2017-12-06 05:03:38 +00:00
|
|
|
namespace {
|
2017-12-06 04:39:44 +00:00
|
|
|
struct lsDocumentSymbolParams {
|
|
|
|
lsTextDocumentIdentifier textDocument;
|
|
|
|
};
|
|
|
|
MAKE_REFLECT_STRUCT(lsDocumentSymbolParams, textDocument);
|
|
|
|
|
|
|
|
struct Ipc_TextDocumentDocumentSymbol
|
|
|
|
: public IpcMessage<Ipc_TextDocumentDocumentSymbol> {
|
|
|
|
const static IpcId kIpcId = IpcId::TextDocumentDocumentSymbol;
|
|
|
|
|
|
|
|
lsRequestId id;
|
|
|
|
lsDocumentSymbolParams params;
|
|
|
|
};
|
|
|
|
MAKE_REFLECT_STRUCT(Ipc_TextDocumentDocumentSymbol, id, params);
|
|
|
|
REGISTER_IPC_MESSAGE(Ipc_TextDocumentDocumentSymbol);
|
|
|
|
|
|
|
|
struct Out_TextDocumentDocumentSymbol
|
|
|
|
: public lsOutMessage<Out_TextDocumentDocumentSymbol> {
|
|
|
|
lsRequestId id;
|
2017-12-12 05:20:29 +00:00
|
|
|
std::vector<lsSymbolInformation> result;
|
2017-12-06 04:39:44 +00:00
|
|
|
};
|
|
|
|
MAKE_REFLECT_STRUCT(Out_TextDocumentDocumentSymbol, jsonrpc, id, result);
|
|
|
|
|
2017-12-06 03:32:33 +00:00
|
|
|
struct TextDocumentDocumentSymbolHandler
|
|
|
|
: BaseMessageHandler<Ipc_TextDocumentDocumentSymbol> {
|
|
|
|
void Run(Ipc_TextDocumentDocumentSymbol* request) override {
|
|
|
|
Out_TextDocumentDocumentSymbol out;
|
|
|
|
out.id = request->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)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (SymbolRef ref : file->def->outline) {
|
|
|
|
optional<lsSymbolInformation> info =
|
2017-12-19 05:31:19 +00:00
|
|
|
GetSymbolInfo(db, working_files, ref.idx, true /*use_short_name*/);
|
2017-12-06 03:32:33 +00:00
|
|
|
if (!info)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
optional<lsLocation> location = GetLsLocation(db, working_files, ref.loc);
|
|
|
|
if (!location)
|
|
|
|
continue;
|
|
|
|
info->location = *location;
|
|
|
|
out.result.push_back(*info);
|
|
|
|
}
|
|
|
|
|
2017-12-24 00:25:18 +00:00
|
|
|
QueueManager::WriteStdout(IpcId::TextDocumentDocumentSymbol, out);
|
2017-12-06 03:32:33 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
REGISTER_MESSAGE_HANDLER(TextDocumentDocumentSymbolHandler);
|
2017-12-31 03:18:33 +00:00
|
|
|
} // namespace
|