ccls/src/messages/ccls_base.cc
Fangrui Song fac5c56682 Use usr as primary key and remove id; simplify import pipeline
Remove on_id_map, IndexMergeIndexUpdates
2018-05-01 22:45:01 -07:00

51 lines
1.5 KiB
C++

#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
namespace {
MethodType kMethodType = "$ccls/base";
struct In_CclsBase : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsTextDocumentPositionParams params;
};
MAKE_REFLECT_STRUCT(In_CclsBase, id, params);
REGISTER_IN_MESSAGE(In_CclsBase);
struct Handler_CclsBase : BaseMessageHandler<In_CclsBase> {
MethodType GetMethodType() const override { return kMethodType; }
void Run(In_CclsBase* request) override {
QueryFile* file;
if (!FindFileOrFail(db, project, request->id,
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)) {
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;
} 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;
}
}
QueueManager::WriteStdout(kMethodType, out);
}
};
REGISTER_MESSAGE_HANDLER(Handler_CclsBase);
} // namespace