Add $cquery/fileInfo

This commit is contained in:
Fangrui Song 2018-02-14 22:41:07 -08:00
parent afe86ef146
commit 5bbd3f4a29
6 changed files with 51 additions and 0 deletions

View File

@ -331,6 +331,7 @@ void LaunchStdinLoop(Config* config,
case IpcId::TextDocumentCodeLens: case IpcId::TextDocumentCodeLens:
case IpcId::WorkspaceDidChangeWatchedFiles: case IpcId::WorkspaceDidChangeWatchedFiles:
case IpcId::WorkspaceSymbol: case IpcId::WorkspaceSymbol:
case IpcId::CqueryFileInfo:
case IpcId::CqueryFreshenIndex: case IpcId::CqueryFreshenIndex:
case IpcId::CqueryTypeHierarchyTree: case IpcId::CqueryTypeHierarchyTree:
case IpcId::CqueryCallTreeInitial: case IpcId::CqueryCallTreeInitial:

View File

@ -66,6 +66,8 @@ const char* IpcIdToString(IpcId id) {
case IpcId::CqueryPublishSemanticHighlighting: case IpcId::CqueryPublishSemanticHighlighting:
return "$cquery/publishSemanticHighlighting"; return "$cquery/publishSemanticHighlighting";
case IpcId::CqueryFileInfo:
return "$cquery/fileInfo";
case IpcId::CqueryFreshenIndex: case IpcId::CqueryFreshenIndex:
return "$cquery/freshenIndex"; return "$cquery/freshenIndex";
case IpcId::CqueryTypeHierarchyTree: case IpcId::CqueryTypeHierarchyTree:

View File

@ -45,6 +45,7 @@ enum class IpcId : int {
CqueryPublishSemanticHighlighting, CqueryPublishSemanticHighlighting,
// Custom messages // Custom messages
CqueryFileInfo,
CqueryFreshenIndex, CqueryFreshenIndex,
// Messages used in tree views. // Messages used in tree views.
CqueryTypeHierarchyTree, CqueryTypeHierarchyTree,

View File

@ -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<Ipc_CqueryFileInfo> {
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<Out_CqueryFileInfo> {
lsRequestId id;
QueryFile::Def result;
};
MAKE_REFLECT_STRUCT(Out_CqueryFileInfo, jsonrpc, id, result);
struct CqueryFileInfoHandler : BaseMessageHandler<Ipc_CqueryFileInfo> {
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

View File

@ -211,6 +211,7 @@ void CompareGroups(std::vector<T>& previous_data,
QueryFile::DefUpdate BuildFileDefUpdate(const IdMap& id_map, const IndexFile& indexed) { QueryFile::DefUpdate BuildFileDefUpdate(const IdMap& id_map, const IndexFile& indexed) {
QueryFile::Def def; QueryFile::Def def;
def.path = indexed.path; def.path = indexed.path;
def.args = indexed.args;
def.includes = indexed.includes; def.includes = indexed.includes;
def.inactive_regions = indexed.skipped_by_preprocessor; def.inactive_regions = indexed.skipped_by_preprocessor;
def.dependencies = indexed.dependencies; def.dependencies = indexed.dependencies;

View File

@ -96,6 +96,7 @@ struct QueryFamily {
struct QueryFile { struct QueryFile {
struct Def { struct Def {
std::string path; std::string path;
std::vector<std::string> args;
// Language identifier // Language identifier
std::string language; std::string language;
// Includes in the file. // Includes in the file.
@ -122,6 +123,7 @@ struct QueryFile {
}; };
MAKE_REFLECT_STRUCT(QueryFile::Def, MAKE_REFLECT_STRUCT(QueryFile::Def,
path, path,
args,
language, language,
outline, outline,
all_symbols, all_symbols,