Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.

Commit

Permalink
Add $cquery/fileInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Feb 15, 2018
1 parent 5eba3d4 commit af14a10
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/command_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions src/ipc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum class IpcId : int {
CqueryPublishSemanticHighlighting,

// Custom messages
CqueryFileInfo,
CqueryFreshenIndex,
// Messages used in tree views.
CqueryTypeHierarchyTree,
Expand Down
44 changes: 44 additions & 0 deletions src/messages/cquery_file_info.cc
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ void CompareGroups(std::vector<T>& 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;
Expand Down
2 changes: 2 additions & 0 deletions src/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ struct QueryFamily {
struct QueryFile {
struct Def {
std::string path;
std::vector<std::string> args;
// Language identifier
std::string language;
// Includes in the file.
Expand All @@ -122,6 +123,7 @@ struct QueryFile {
};
MAKE_REFLECT_STRUCT(QueryFile::Def,
path,
args,
language,
outline,
all_symbols,
Expand Down

0 comments on commit af14a10

Please sign in to comment.