diff --git a/src/command_line.cc b/src/command_line.cc index 23c19d969..12efb94bb 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -331,6 +331,7 @@ void LaunchStdinLoop(Config* config, case IpcId::TextDocumentCodeLens: case IpcId::WorkspaceDidChangeWatchedFiles: case IpcId::WorkspaceSymbol: + case IpcId::CqueryFileInfo: case IpcId::CqueryFreshenIndex: case IpcId::CqueryTypeHierarchyTree: case IpcId::CqueryCallTreeInitial: diff --git a/src/ipc.cc b/src/ipc.cc index ba7cee119..8fff915b5 100644 --- a/src/ipc.cc +++ b/src/ipc.cc @@ -66,6 +66,8 @@ const char* IpcIdToString(IpcId id) { case IpcId::CqueryPublishSemanticHighlighting: return "$cquery/publishSemanticHighlighting"; + case IpcId::CqueryFileInfo: + return "$cquery/fileInfo"; case IpcId::CqueryFreshenIndex: return "$cquery/freshenIndex"; case IpcId::CqueryTypeHierarchyTree: diff --git a/src/ipc.h b/src/ipc.h index 59d820ecc..ffc8be20b 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -45,6 +45,7 @@ enum class IpcId : int { CqueryPublishSemanticHighlighting, // Custom messages + CqueryFileInfo, CqueryFreshenIndex, // Messages used in tree views. CqueryTypeHierarchyTree, diff --git a/src/messages/cquery_file_info.cc b/src/messages/cquery_file_info.cc new file mode 100644 index 000000000..1fa9998b3 --- /dev/null +++ b/src/messages/cquery_file_info.cc @@ -0,0 +1,44 @@ +#include "message_handler.h" +#include "query_utils.h" +#include "queue_manager.h" + +namespace { +struct lsDocumentSymbolParams { + lsTextDocumentIdentifier textDocument; +}; +MAKE_REFLECT_STRUCT(lsDocumentSymbolParams, textDocument); + +struct Ipc_CqueryFileInfo : public RequestMessage { + const static IpcId kIpcId = IpcId::CqueryFileInfo; + lsDocumentSymbolParams params; +}; +MAKE_REFLECT_STRUCT(Ipc_CqueryFileInfo, id, params); +REGISTER_IPC_MESSAGE(Ipc_CqueryFileInfo); + +struct Out_CqueryFileInfo : public lsOutMessage { + lsRequestId id; + QueryFile::Def result; +}; +MAKE_REFLECT_STRUCT(Out_CqueryFileInfo, jsonrpc, id, result); + +struct CqueryFileInfoHandler : BaseMessageHandler { + void Run(Ipc_CqueryFileInfo* request) override { + QueryFile* file; + if (!FindFileOrFail(db, project, request->id, + request->params.textDocument.uri.GetPath(), &file)) { + return; + } + + Out_CqueryFileInfo 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.inactive_regions = file->def->inactive_regions; + QueueManager::WriteStdout(IpcId::CqueryFileInfo, out); + } +}; +REGISTER_MESSAGE_HANDLER(CqueryFileInfoHandler); +} // namespace diff --git a/src/query.cc b/src/query.cc index 6c451989b..f985c41d0 100644 --- a/src/query.cc +++ b/src/query.cc @@ -211,6 +211,7 @@ void CompareGroups(std::vector& previous_data, QueryFile::DefUpdate BuildFileDefUpdate(const IdMap& id_map, const IndexFile& indexed) { QueryFile::Def def; def.path = indexed.path; + def.args = indexed.args; def.includes = indexed.includes; def.inactive_regions = indexed.skipped_by_preprocessor; def.dependencies = indexed.dependencies; diff --git a/src/query.h b/src/query.h index f1fa156b5..75f5b0840 100644 --- a/src/query.h +++ b/src/query.h @@ -96,6 +96,7 @@ struct QueryFamily { struct QueryFile { struct Def { std::string path; + std::vector args; // Language identifier std::string language; // Includes in the file. @@ -122,6 +123,7 @@ struct QueryFile { }; MAKE_REFLECT_STRUCT(QueryFile::Def, path, + args, language, outline, all_symbols,