diff --git a/CMakeLists.txt b/CMakeLists.txt index 384c008f..47af70f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -208,7 +208,7 @@ target_sources(ccls PRIVATE target_sources(ccls PRIVATE src/messages/ccls_call.cc - src/messages/ccls_fileInfo.cc + src/messages/ccls_info.cc src/messages/ccls_inheritance.cc src/messages/ccls_member.cc src/messages/ccls_navigate.cc diff --git a/src/messages/ccls_fileInfo.cc b/src/messages/ccls_fileInfo.cc deleted file mode 100644 index 3893833d..00000000 --- a/src/messages/ccls_fileInfo.cc +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2017-2018 ccls Authors -// SPDX-License-Identifier: Apache-2.0 - -#include "message_handler.h" -#include "pipeline.hh" -#include "query_utils.h" -using namespace ccls; - -MAKE_REFLECT_STRUCT(QueryFile::Def, path, args, language, skipped_ranges, - dependencies); - -namespace { -MethodType kMethodType = "$ccls/fileInfo"; - -struct lsDocumentSymbolParams { - lsTextDocumentIdentifier textDocument; -}; -MAKE_REFLECT_STRUCT(lsDocumentSymbolParams, textDocument); - -struct In_CclsFileInfo : public RequestInMessage { - MethodType GetMethodType() const override { return kMethodType; } - lsDocumentSymbolParams params; -}; -MAKE_REFLECT_STRUCT(In_CclsFileInfo, id, params); -REGISTER_IN_MESSAGE(In_CclsFileInfo); - -struct Out_CclsFileInfo : public lsOutMessage { - lsRequestId id; - QueryFile::Def result; -}; -MAKE_REFLECT_STRUCT(Out_CclsFileInfo, jsonrpc, id, result); - -struct Handler_CclsFileInfo : BaseMessageHandler { - MethodType GetMethodType() const override { return kMethodType; } - void Run(In_CclsFileInfo *request) override { - QueryFile *file; - if (!FindFileOrFail(db, project, request->id, - request->params.textDocument.uri.GetPath(), &file)) { - return; - } - - Out_CclsFileInfo out; - out.id = request->id; - // Expose some fields of |QueryFile::Def|. - out.result.path = file->def->path; - out.result.args = file->def->args; - out.result.language = file->def->language; - out.result.includes = file->def->includes; - out.result.skipped_ranges = file->def->skipped_ranges; - pipeline::WriteStdout(kMethodType, out); - } -}; -REGISTER_MESSAGE_HANDLER(Handler_CclsFileInfo); -} // namespace diff --git a/src/messages/ccls_info.cc b/src/messages/ccls_info.cc new file mode 100644 index 00000000..667948d9 --- /dev/null +++ b/src/messages/ccls_info.cc @@ -0,0 +1,94 @@ +// Copyright 2017-2018 ccls Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "message_handler.h" +#include "pipeline.hh" +#include "project.h" +#include "query_utils.h" +using namespace ccls; + +MAKE_REFLECT_STRUCT(QueryFile::Def, path, args, language, skipped_ranges, + dependencies); + +namespace { +MethodType cclsInfo = "$ccls/info", fileInfo = "$ccls/fileInfo"; + +struct In_cclsInfo : public RequestInMessage { + MethodType GetMethodType() const override { return cclsInfo; } +}; +MAKE_REFLECT_STRUCT(In_cclsInfo, id); +REGISTER_IN_MESSAGE(In_cclsInfo); + +struct Out_cclsInfo : public lsOutMessage { + lsRequestId id; + struct Result { + struct DB { + int files, funcs, types, vars; + } db; + struct Pipeline { + int pendingIndexRequests; + } pipeline; + struct Project { + int entries; + } project; + } result; +}; +MAKE_REFLECT_STRUCT(Out_cclsInfo::Result::DB, files, funcs, types, vars); +MAKE_REFLECT_STRUCT(Out_cclsInfo::Result::Pipeline, pendingIndexRequests); +MAKE_REFLECT_STRUCT(Out_cclsInfo::Result::Project, entries); +MAKE_REFLECT_STRUCT(Out_cclsInfo::Result, db, pipeline, project); +MAKE_REFLECT_STRUCT(Out_cclsInfo, jsonrpc, id, result); + +struct Handler_cclsInfo : BaseMessageHandler { + MethodType GetMethodType() const override { return cclsInfo; } + void Run(In_cclsInfo *request) override { + Out_cclsInfo out; + out.id = request->id; + out.result.db.files = db->files.size(); + out.result.db.funcs = db->funcs.size(); + out.result.db.types = db->types.size(); + out.result.db.vars = db->vars.size(); + out.result.pipeline.pendingIndexRequests = pipeline::pending_index_requests; + out.result.project.entries = project->entries.size(); + pipeline::WriteStdout(cclsInfo, out); + } +}; +REGISTER_MESSAGE_HANDLER(Handler_cclsInfo); + +struct In_cclsFileInfo : public RequestInMessage { + MethodType GetMethodType() const override { return fileInfo; } + struct Params { + lsTextDocumentIdentifier textDocument; + } params; +}; +MAKE_REFLECT_STRUCT(In_cclsFileInfo::Params, textDocument); +MAKE_REFLECT_STRUCT(In_cclsFileInfo, id, params); +REGISTER_IN_MESSAGE(In_cclsFileInfo); + +struct Out_cclsFileInfo : public lsOutMessage { + lsRequestId id; + QueryFile::Def result; +}; +MAKE_REFLECT_STRUCT(Out_cclsFileInfo, jsonrpc, id, result); + +struct Handler_cclsFileInfo : BaseMessageHandler { + MethodType GetMethodType() const override { return fileInfo; } + void Run(In_cclsFileInfo *request) override { + QueryFile *file; + if (!FindFileOrFail(db, project, request->id, + request->params.textDocument.uri.GetPath(), &file)) + return; + + Out_cclsFileInfo out; + out.id = request->id; + // Expose some fields of |QueryFile::Def|. + out.result.path = file->def->path; + out.result.args = file->def->args; + out.result.language = file->def->language; + out.result.includes = file->def->includes; + out.result.skipped_ranges = file->def->skipped_ranges; + pipeline::WriteStdout(fileInfo, out); + } +}; +REGISTER_MESSAGE_HANDLER(Handler_cclsFileInfo); +} // namespace