ccls/src/messages/ccls_base.cc

51 lines
1.5 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 {
2018-03-31 03:16:33 +00:00
MethodType kMethodType = "$ccls/base";
2018-03-31 03:16:33 +00:00
struct In_CclsBase : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
2017-12-06 04:39:44 +00:00
lsTextDocumentPositionParams params;
};
2018-03-31 03:16:33 +00:00
MAKE_REFLECT_STRUCT(In_CclsBase, id, params);
REGISTER_IN_MESSAGE(In_CclsBase);
2018-03-31 03:16:33 +00:00
struct Handler_CclsBase : BaseMessageHandler<In_CclsBase> {
MethodType GetMethodType() const override { return kMethodType; }
2017-12-06 04:39:44 +00:00
2018-03-31 03:16:33 +00:00
void Run(In_CclsBase* request) override {
2017-12-06 03:32:33 +00:00
QueryFile* file;
if (!FindFileOrFail(db, project, request->id,
2017-12-06 03:32:33 +00:00
request->params.textDocument.uri.GetPath(), &file)) {
return;
}
WorkingFile* working_file =
working_files->GetFileByFilename(file->def->path);
Out_LocationList out;
out.id = request->id;
for (SymbolRef sym :
FindSymbolsAtLocation(working_file, file, request->params.position)) {
2018-02-09 17:42:10 +00:00
if (sym.kind == SymbolKind::Type) {
if (const auto* def = db->GetType(sym).AnyDef())
out.result = GetLsLocationExs(
db, working_files, GetDeclarations(db->usr2type, def->bases));
break;
2018-02-09 17:42:10 +00:00
} else if (sym.kind == SymbolKind::Func) {
if (const auto* def = db->GetFunc(sym).AnyDef())
out.result = GetLsLocationExs(
db, working_files, GetDeclarations(db->usr2func, def->bases));
break;
2017-12-06 03:32:33 +00:00
}
}
QueueManager::WriteStdout(kMethodType, out);
2017-12-06 03:32:33 +00:00
}
};
2018-03-31 03:16:33 +00:00
REGISTER_MESSAGE_HANDLER(Handler_CclsBase);
} // namespace