ipc.h -> method.h, rename some types

This commit is contained in:
Jacob Dufault 2018-03-21 22:01:21 -07:00 committed by Fangrui Song
parent e37a6c814b
commit 2fc731c856
47 changed files with 94 additions and 90 deletions

View File

@ -183,7 +183,7 @@ target_sources(cquery PRIVATE
src/import_manager.cc
src/import_pipeline.cc
src/include_complete.cc
src/ipc.cc
src/method.cc
src/lex_utils.cc
src/lsp_diagnostic.cc
src/lsp.cc

View File

@ -137,7 +137,7 @@ bool QueryDbMainLoop(Config* config,
CodeCompleteCache* non_global_code_complete_cache,
CodeCompleteCache* signature_cache) {
auto* queue = QueueManager::instance();
std::vector<std::unique_ptr<BaseIpcMessage>> messages =
std::vector<std::unique_ptr<InMessage>> messages =
queue->for_querydb.DequeueAll();
bool did_work = messages.size();
for (auto& message : messages) {
@ -281,7 +281,7 @@ void LaunchStdinLoop(Config* config,
WorkThread::StartThread("stdin", [request_times]() {
auto* queue = QueueManager::instance();
while (true) {
std::unique_ptr<BaseIpcMessage> message;
std::unique_ptr<InMessage> message;
optional<std::string> err =
MessageRegistry::instance()->ReadMessageFromStdin(&message);

View File

@ -123,7 +123,7 @@ optional<char> ReadCharFromStdinBlocking() {
}
optional<std::string> MessageRegistry::ReadMessageFromStdin(
std::unique_ptr<BaseIpcMessage>* message) {
std::unique_ptr<InMessage>* message) {
optional<std::string> content =
ReadJsonRpcContentFrom(&ReadCharFromStdinBlocking);
if (!content) {
@ -141,7 +141,7 @@ optional<std::string> MessageRegistry::ReadMessageFromStdin(
optional<std::string> MessageRegistry::Parse(
Reader& visitor,
std::unique_ptr<BaseIpcMessage>* message) {
std::unique_ptr<InMessage>* message) {
if (!visitor.HasMember("jsonrpc") ||
std::string(visitor["jsonrpc"]->GetString()) != "2.0") {
LOG_S(FATAL) << "Bad or missing jsonrpc version";

View File

@ -1,7 +1,7 @@
#pragma once
#include "config.h"
#include "ipc.h"
#include "method.h"
#include "serializer.h"
#include "utils.h"
@ -32,13 +32,13 @@ struct MessageRegistry {
static MessageRegistry* instance();
using Allocator =
std::function<void(Reader& visitor, std::unique_ptr<BaseIpcMessage>*)>;
std::function<void(Reader& visitor, std::unique_ptr<InMessage>*)>;
std::unordered_map<std::string, Allocator> allocators;
optional<std::string> ReadMessageFromStdin(
std::unique_ptr<BaseIpcMessage>* message);
std::unique_ptr<InMessage>* message);
optional<std::string> Parse(Reader& visitor,
std::unique_ptr<BaseIpcMessage>* message);
std::unique_ptr<InMessage>* message);
};
template <typename T>
@ -47,7 +47,7 @@ struct MessageRegistryRegister {
T dummy;
std::string method_name = dummy.GetMethodType();
MessageRegistry::instance()->allocators[method_name] =
[](Reader& visitor, std::unique_ptr<BaseIpcMessage>* message) {
[](Reader& visitor, std::unique_ptr<InMessage>* message) {
*message = std::make_unique<T>();
// Reflect may throw and *message will be partially deserialized.
Reflect(visitor, static_cast<T&>(**message));

View File

@ -1,7 +1,7 @@
#pragma once
#include "ipc.h"
#include "lsp.h"
#include "method.h"
#include "query.h"
#include <optional.h>
@ -87,7 +87,7 @@ struct MessageHandler {
CodeCompleteCache* signature_cache = nullptr;
virtual MethodType GetMethodType() const = 0;
virtual void Run(std::unique_ptr<BaseIpcMessage> message) = 0;
virtual void Run(std::unique_ptr<InMessage> message) = 0;
static std::vector<MessageHandler*>* message_handlers;
@ -100,7 +100,7 @@ struct BaseMessageHandler : MessageHandler {
virtual void Run(TMessage* message) = 0;
// MessageHandler:
void Run(std::unique_ptr<BaseIpcMessage> message) override {
void Run(std::unique_ptr<InMessage> message) override {
Run(static_cast<TMessage*>(message.get()));
}
};

View File

@ -6,7 +6,7 @@ namespace {
MethodType kMethodType = "$cquery/base";
struct In_CqueryBase : public RequestMessage {
struct In_CqueryBase : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsTextDocumentPositionParams params;

View File

@ -20,7 +20,7 @@ bool operator&(CallType lhs, CallType rhs) {
return uint8_t(lhs) & uint8_t(rhs);
}
struct In_CqueryCallHierarchy : public RequestMessage {
struct In_CqueryCallHierarchy : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
struct Params {

View File

@ -5,7 +5,7 @@
namespace {
MethodType kMethodType = "$cquery/callers";
struct In_CqueryCallers : public RequestMessage {
struct In_CqueryCallers : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsTextDocumentPositionParams params;
};

View File

@ -5,7 +5,7 @@
namespace {
MethodType kMethodType = "$cquery/derived";
struct In_CqueryDerived : public RequestMessage {
struct In_CqueryDerived : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsTextDocumentPositionParams params;
};

View File

@ -5,7 +5,7 @@
namespace {
MethodType kMethodType = "$cquery/textDocumentDidView";
struct In_CqueryTextDocumentDidView : public NotificationMessage {
struct In_CqueryTextDocumentDidView : public NotificationInMessage {
MethodType GetMethodType() const override { return kMethodType; }
struct Params {
lsDocumentUri textDocumentUri;

View File

@ -10,7 +10,7 @@ struct lsDocumentSymbolParams {
};
MAKE_REFLECT_STRUCT(lsDocumentSymbolParams, textDocument);
struct In_CqueryFileInfo : public RequestMessage {
struct In_CqueryFileInfo : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsDocumentSymbolParams params;
};

View File

@ -15,7 +15,7 @@
namespace {
MethodType kMethodType = "$cquery/freshenIndex";
struct In_CqueryFreshenIndex : public NotificationMessage {
struct In_CqueryFreshenIndex : public NotificationInMessage {
MethodType GetMethodType() const override { return kMethodType; }
struct Params {
bool dependencies = true;

View File

@ -8,7 +8,7 @@
namespace {
MethodType kMethodType = "$cquery/indexFile";
struct In_CqueryIndexFile : public NotificationMessage {
struct In_CqueryIndexFile : public NotificationInMessage {
MethodType GetMethodType() const override { return kMethodType; }
struct Params {
std::string path;

View File

@ -5,7 +5,7 @@
namespace {
MethodType kMethodType = "$cquery/inheritanceHierarchy";
struct In_CqueryInheritanceHierarchy : public RequestMessage {
struct In_CqueryInheritanceHierarchy : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
struct Params {
// If id+kind are specified, expand a node; otherwise textDocument+position

View File

@ -5,7 +5,7 @@
namespace {
MethodType kMethodType = "$cquery/memberHierarchy";
struct In_CqueryMemberHierarchy : public RequestMessage {
struct In_CqueryMemberHierarchy : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
struct Params {

View File

@ -9,7 +9,7 @@
namespace {
MethodType kMethodType = "$cquery/random";
struct In_CqueryRandom : public RequestMessage {
struct In_CqueryRandom : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
};
MAKE_REFLECT_STRUCT(In_CqueryRandom, id);

View File

@ -5,7 +5,7 @@
namespace {
MethodType kMethodType = "$cquery/vars";
struct In_CqueryVars : public RequestMessage {
struct In_CqueryVars : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsTextDocumentPositionParams params;

View File

@ -8,7 +8,7 @@
namespace {
MethodType kMethodType = "$cquery/wait";
struct In_CqueryWait : public NotificationMessage {
struct In_CqueryWait : public NotificationInMessage {
MethodType GetMethodType() const override { return kMethodType; }
};
MAKE_REFLECT_EMPTY_STRUCT(In_CqueryWait);
@ -17,7 +17,7 @@ REGISTER_IN_MESSAGE(In_CqueryWait);
struct Handler_CqueryWait : MessageHandler {
MethodType GetMethodType() const override { return kMethodType; }
void Run(std::unique_ptr<BaseIpcMessage> request) override {
void Run(std::unique_ptr<InMessage> request) override {
// TODO: use status message system here, then run querydb as normal? Maybe
// this cannot be a normal message, ie, it needs to be re-entrant.

View File

@ -3,7 +3,7 @@
#include <loguru.hpp>
namespace {
struct In_Exit : public NotificationMessage {
struct In_Exit : public NotificationInMessage {
MethodType GetMethodType() const override { return kMethodType_Exit; }
};
MAKE_REFLECT_EMPTY_STRUCT(In_Exit);
@ -12,7 +12,7 @@ REGISTER_IN_MESSAGE(In_Exit);
struct Handler_Exit : MessageHandler {
MethodType GetMethodType() const override { return kMethodType_Exit; }
void Run(std::unique_ptr<BaseIpcMessage> request) override {
void Run(std::unique_ptr<InMessage> request) override {
LOG_S(INFO) << "Exiting; got exit message";
exit(0);
}

View File

@ -462,7 +462,7 @@ struct lsInitializeError {
};
MAKE_REFLECT_STRUCT(lsInitializeError, retry);
struct In_InitializeRequest : public RequestMessage {
struct In_InitializeRequest : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsInitializeParams params;

View File

@ -4,7 +4,7 @@
namespace {
MethodType kMethodType = "shutdown";
struct In_Shutdown : public RequestMessage {
struct In_Shutdown : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
};
MAKE_REFLECT_STRUCT(In_Shutdown, id);

View File

@ -257,7 +257,7 @@ optional<lsTextEdit> BuildAutoImplementForFunction(QueryDatabase* db,
return nullopt;
}
struct In_TextDocumentCodeAction : public RequestMessage {
struct In_TextDocumentCodeAction : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
// Contains additional diagnostic information about the context in which

View File

@ -13,7 +13,7 @@ struct lsDocumentCodeLensParams {
MAKE_REFLECT_STRUCT(lsDocumentCodeLensParams, textDocument);
using TCodeLens = lsCodeLens<lsCodeLensUserData, lsCodeLensCommandArguments>;
struct In_TextDocumentCodeLens : public RequestMessage {
struct In_TextDocumentCodeLens : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsDocumentCodeLensParams params;
};

View File

@ -48,7 +48,7 @@ struct lsCompletionParams : lsTextDocumentPositionParams {
};
MAKE_REFLECT_STRUCT(lsCompletionParams, textDocument, position, context);
struct In_TextDocumentComplete : public RequestMessage {
struct In_TextDocumentComplete : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsCompletionParams params;
};
@ -219,7 +219,7 @@ void FilterAndSortCompletionResponse(
struct Handler_TextDocumentCompletion : MessageHandler {
MethodType GetMethodType() const override { return kMethodType; }
void Run(std::unique_ptr<BaseIpcMessage> message) override {
void Run(std::unique_ptr<InMessage> message) override {
auto request = std::shared_ptr<In_TextDocumentComplete>(
static_cast<In_TextDocumentComplete*>(message.release()));

View File

@ -10,7 +10,7 @@
namespace {
MethodType kMethodType = "textDocument/definition";
struct In_TextDocumentDefinition : public RequestMessage {
struct In_TextDocumentDefinition : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsTextDocumentPositionParams params;
};

View File

@ -10,7 +10,7 @@
namespace {
MethodType kMethodType = "textDocument/didChange";
struct In_TextDocumentDidChange : public NotificationMessage {
struct In_TextDocumentDidChange : public NotificationInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsTextDocumentDidChangeParams params;
};

View File

@ -6,7 +6,7 @@
namespace {
MethodType kMethodType = "textDocument/didClose";
struct In_TextDocumentDidClose : public NotificationMessage {
struct In_TextDocumentDidClose : public NotificationInMessage {
MethodType GetMethodType() const override { return kMethodType; }
struct Params {
lsTextDocumentIdentifier textDocument;

View File

@ -13,7 +13,7 @@ namespace {
MethodType kMethodType = "textDocument/didOpen";
// Open, view, change, close file
struct In_TextDocumentDidOpen : public NotificationMessage {
struct In_TextDocumentDidOpen : public NotificationInMessage {
MethodType GetMethodType() const override { return kMethodType; }
struct Params {

View File

@ -9,7 +9,7 @@
namespace {
MethodType kMethodType = "textDocument/didSave";
struct In_TextDocumentDidSave : public NotificationMessage {
struct In_TextDocumentDidSave : public NotificationInMessage {
MethodType GetMethodType() const override { return kMethodType; }
struct Params {

View File

@ -6,7 +6,7 @@
namespace {
MethodType kMethodType = "textDocument/documentHighlight";
struct In_TextDocumentDocumentHighlight : public RequestMessage {
struct In_TextDocumentDocumentHighlight : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsTextDocumentPositionParams params;
};

View File

@ -8,7 +8,7 @@
namespace {
MethodType kMethodType = "textDocument/documentLink";
struct In_TextDocumentDocumentLink : public RequestMessage {
struct In_TextDocumentDocumentLink : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
struct Params {
// The document to provide document links for.

View File

@ -10,7 +10,7 @@ struct lsDocumentSymbolParams {
};
MAKE_REFLECT_STRUCT(lsDocumentSymbolParams, textDocument);
struct In_TextDocumentDocumentSymbol : public RequestMessage {
struct In_TextDocumentDocumentSymbol : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsDocumentSymbolParams params;
};

View File

@ -8,7 +8,7 @@
namespace {
MethodType kMethodType = "textDocument/formatting";
struct In_TextDocumentFormatting : public RequestMessage {
struct In_TextDocumentFormatting : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
struct Params {
lsTextDocumentIdentifier textDocument;

View File

@ -42,7 +42,7 @@ std::pair<std::string_view, std::string_view> GetCommentsAndHover(
return {"", ""};
}
struct In_TextDocumentHover : public RequestMessage {
struct In_TextDocumentHover : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsTextDocumentPositionParams params;
};

View File

@ -19,7 +19,7 @@ MAKE_REFLECT_STRUCT(lsTextDocumentRangeFormattingParams,
range,
options);
struct In_TextDocumentRangeFormatting : public RequestMessage {
struct In_TextDocumentRangeFormatting : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsTextDocumentRangeFormattingParams params;
};

View File

@ -7,7 +7,7 @@
namespace {
MethodType kMethodType = "textDocument/references";
struct In_TextDocumentReferences : public RequestMessage {
struct In_TextDocumentReferences : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
struct lsReferenceContext {
// Include the declaration of the current symbol.

View File

@ -48,7 +48,7 @@ lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db,
return edit;
}
struct In_TextDocumentRename : public RequestMessage {
struct In_TextDocumentRename : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
struct Params {
// The document to format.

View File

@ -9,7 +9,7 @@
namespace {
MethodType kMethodType = "textDocument/signatureHelp";
struct In_TextDocumentSignatureHelp : public RequestMessage {
struct In_TextDocumentSignatureHelp : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsTextDocumentPositionParams params;
};
@ -86,7 +86,7 @@ MAKE_REFLECT_STRUCT(Out_TextDocumentSignatureHelp, jsonrpc, id, result);
struct Handler_TextDocumentSignatureHelp : MessageHandler {
MethodType GetMethodType() const override { return kMethodType; }
void Run(std::unique_ptr<BaseIpcMessage> message) override {
void Run(std::unique_ptr<InMessage> message) override {
auto request = static_cast<In_TextDocumentSignatureHelp*>(message.get());
lsTextDocumentPositionParams& params = request->params;
WorkingFile* file =
@ -103,7 +103,7 @@ struct Handler_TextDocumentSignatureHelp : MessageHandler {
return;
ClangCompleteManager::OnComplete callback = std::bind(
[this](BaseIpcMessage* message, std::string search, int active_param,
[this](InMessage* message, std::string search, int active_param,
const std::vector<lsCompletionItem>& results,
bool is_cached_result) {
auto msg = static_cast<In_TextDocumentSignatureHelp*>(message);

View File

@ -5,7 +5,7 @@
namespace {
MethodType kMethodType = "textDocument/typeDefinition";
struct In_TextDocumentTypeDefinition : public RequestMessage {
struct In_TextDocumentTypeDefinition : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsTextDocumentPositionParams params;
};

View File

@ -16,7 +16,7 @@ struct lsDidChangeConfigurationParams {
};
MAKE_REFLECT_STRUCT(lsDidChangeConfigurationParams, placeholder);
struct In_WorkspaceDidChangeConfiguration : public NotificationMessage {
struct In_WorkspaceDidChangeConfiguration : public NotificationInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsDidChangeConfigurationParams params;
};

View File

@ -28,7 +28,7 @@ struct lsDidChangeWatchedFilesParams {
};
MAKE_REFLECT_STRUCT(lsDidChangeWatchedFilesParams, changes);
struct In_WorkspaceDidChangeWatchedFiles : public NotificationMessage {
struct In_WorkspaceDidChangeWatchedFiles : public NotificationInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsDidChangeWatchedFilesParams params;
};

View File

@ -6,7 +6,7 @@
namespace {
MethodType kMethodType = "workspace/executeCommand";
struct In_WorkspaceExecuteCommand : public RequestMessage {
struct In_WorkspaceExecuteCommand : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
lsCommand<lsCodeLensCommandArguments> params;
};

View File

@ -43,7 +43,7 @@ bool InsertSymbolIntoResult(QueryDatabase* db,
return true;
}
struct In_WorkspaceSymbol : public RequestMessage {
struct In_WorkspaceSymbol : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; }
struct Params {
std::string query;

View File

@ -1,4 +1,4 @@
#include "ipc.h"
#include "method.h"
const char* kMethodType_Unknown = "$unknown";
const char* kMethodType_Exit = "exit";
@ -6,8 +6,12 @@ const char* kMethodType_TextDocumentPublishDiagnostics = "textDocument/publishDi
const char* kMethodType_CqueryPublishInactiveRegions = "$cquery/publishInactiveRegions";
const char* kMethodType_CqueryPublishSemanticHighlighting = "$cquery/publishSemanticHighlighting";
BaseIpcMessage::~BaseIpcMessage() = default;
InMessage::~InMessage() = default;
lsRequestId BaseIpcMessage::GetRequestId() {
lsRequestId RequestInMessage::GetRequestId() const {
return id;
}
lsRequestId NotificationInMessage::GetRequestId() const {
return std::monostate();
}

View File

@ -5,28 +5,29 @@
#include <string>
using lsRequestId = std::variant<std::monostate, int64_t, std::string>;
using MethodType = std::string;
extern const char* kMethodType_Unknown;
extern const char* kMethodType_Exit;
extern const char* kMethodType_TextDocumentPublishDiagnostics;
extern const char* kMethodType_CqueryPublishInactiveRegions;
extern const char* kMethodType_CqueryPublishSemanticHighlighting;
struct BaseIpcMessage {
virtual ~BaseIpcMessage();
using lsRequestId = std::variant<std::monostate, int64_t, std::string>;
struct InMessage {
virtual ~InMessage();
virtual MethodType GetMethodType() const = 0;
virtual lsRequestId GetRequestId();
virtual lsRequestId GetRequestId() const = 0;
};
struct RequestMessage : public BaseIpcMessage {
struct RequestInMessage : public InMessage {
// number or string, actually no null
lsRequestId id;
lsRequestId GetRequestId() override { return id; }
lsRequestId GetRequestId() const override;
};
// NotificationMessage does not have |id|.
struct NotificationMessage : public BaseIpcMessage {};
// NotificationInMessage does not have |id|.
struct NotificationInMessage : public InMessage {
lsRequestId GetRequestId() const override;
};

View File

@ -1,6 +1,7 @@
#pragma once
#include "config.h"
#include "method.h"
#include <optional.h>
#include <sparsepp/spp.h>
@ -11,8 +12,6 @@
#include <string>
#include <vector>
// FIXME ipc.h
using lsRequestId = std::variant<std::monostate, int64_t, std::string>;
class QueueManager;
struct WorkingFiles;

View File

@ -1,6 +1,6 @@
#pragma once
#include "ipc.h"
#include "method.h"
#include "performance.h"
#include "query.h"
#include "threaded_queue.h"
@ -94,7 +94,7 @@ class QueueManager {
ThreadedQueue<Stdout_Request> for_stdout;
// Runs on querydb thread.
ThreadedQueue<std::unique_ptr<BaseIpcMessage>> for_querydb;
ThreadedQueue<std::unique_ptr<InMessage>> for_querydb;
ThreadedQueue<Index_DoIdMap> do_id_map;
// Runs on indexer threads.