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 {
|
2018-03-22 04:05:25 +00:00
|
|
|
MethodType kMethodType = "textDocument/documentSymbol";
|
|
|
|
|
2017-12-06 04:39:44 +00:00
|
|
|
struct lsDocumentSymbolParams {
|
|
|
|
lsTextDocumentIdentifier textDocument;
|
|
|
|
};
|
|
|
|
MAKE_REFLECT_STRUCT(lsDocumentSymbolParams, textDocument);
|
|
|
|
|
2018-03-22 05:01:21 +00:00
|
|
|
struct In_TextDocumentDocumentSymbol : public RequestInMessage {
|
2018-03-22 04:05:25 +00:00
|
|
|
MethodType GetMethodType() const override { return kMethodType; }
|
2017-12-06 04:39:44 +00:00
|
|
|
lsDocumentSymbolParams params;
|
|
|
|
};
|
2018-03-22 04:05:25 +00:00
|
|
|
MAKE_REFLECT_STRUCT(In_TextDocumentDocumentSymbol, id, params);
|
|
|
|
REGISTER_IN_MESSAGE(In_TextDocumentDocumentSymbol);
|
2017-12-06 04:39:44 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-03-22 04:05:25 +00:00
|
|
|
struct Handler_TextDocumentDocumentSymbol
|
|
|
|
: BaseMessageHandler<In_TextDocumentDocumentSymbol> {
|
|
|
|
MethodType GetMethodType() const override { return kMethodType; }
|
|
|
|
void Run(In_TextDocumentDocumentSymbol* request) override {
|
2017-12-06 03:32:33 +00:00
|
|
|
Out_TextDocumentDocumentSymbol out;
|
|
|
|
out.id = request->id;
|
|
|
|
|
|
|
|
QueryFile* file;
|
2018-04-30 04:49:03 +00:00
|
|
|
int file_id;
|
2017-12-31 03:18:33 +00:00
|
|
|
if (!FindFileOrFail(db, project, request->id,
|
2018-02-12 18:15:43 +00:00
|
|
|
request->params.textDocument.uri.GetPath(), &file,
|
|
|
|
&file_id)) {
|
2017-12-06 03:32:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-09 17:42:10 +00:00
|
|
|
for (SymbolRef sym : file->def->outline) {
|
2018-03-31 03:16:33 +00:00
|
|
|
std::optional<lsSymbolInformation> info =
|
2018-04-08 17:32:08 +00:00
|
|
|
GetSymbolInfo(db, working_files, sym, false);
|
2017-12-06 03:32:33 +00:00
|
|
|
if (!info)
|
|
|
|
continue;
|
2018-02-22 07:23:39 +00:00
|
|
|
if (sym.kind == SymbolKind::Var) {
|
|
|
|
QueryVar& var = db->GetVar(sym);
|
|
|
|
auto* def = var.AnyDef();
|
2018-03-20 02:51:42 +00:00
|
|
|
if (!def || !def->spell)
|
|
|
|
continue;
|
2018-02-22 07:23:39 +00:00
|
|
|
// Ignore local variables.
|
|
|
|
if (def->spell->kind == SymbolKind::Func &&
|
|
|
|
def->storage != StorageClass::Static &&
|
|
|
|
def->storage != StorageClass::Extern)
|
|
|
|
continue;
|
|
|
|
}
|
2017-12-06 03:32:33 +00:00
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
if (std::optional<lsLocation> location = GetLsLocation(
|
2018-02-18 18:07:13 +00:00
|
|
|
db, working_files,
|
2018-04-30 04:49:03 +00:00
|
|
|
Use{{sym.range, sym.usr, sym.kind, sym.role}, file_id})) {
|
2018-02-18 18:07:13 +00:00
|
|
|
info->location = *location;
|
|
|
|
out.result.push_back(*info);
|
|
|
|
}
|
2017-12-06 03:32:33 +00:00
|
|
|
}
|
|
|
|
|
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_TextDocumentDocumentSymbol);
|
2017-12-31 03:18:33 +00:00
|
|
|
} // namespace
|