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_manager.cc
src/import_pipeline.cc src/import_pipeline.cc
src/include_complete.cc src/include_complete.cc
src/ipc.cc src/method.cc
src/lex_utils.cc src/lex_utils.cc
src/lsp_diagnostic.cc src/lsp_diagnostic.cc
src/lsp.cc src/lsp.cc

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -8,7 +8,7 @@
namespace { namespace {
MethodType kMethodType = "$cquery/wait"; MethodType kMethodType = "$cquery/wait";
struct In_CqueryWait : public NotificationMessage { struct In_CqueryWait : public NotificationInMessage {
MethodType GetMethodType() const override { return kMethodType; } MethodType GetMethodType() const override { return kMethodType; }
}; };
MAKE_REFLECT_EMPTY_STRUCT(In_CqueryWait); MAKE_REFLECT_EMPTY_STRUCT(In_CqueryWait);
@ -17,7 +17,7 @@ REGISTER_IN_MESSAGE(In_CqueryWait);
struct Handler_CqueryWait : MessageHandler { struct Handler_CqueryWait : MessageHandler {
MethodType GetMethodType() const override { return kMethodType; } 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 // 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. // this cannot be a normal message, ie, it needs to be re-entrant.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,7 +9,7 @@
namespace { namespace {
MethodType kMethodType = "textDocument/signatureHelp"; MethodType kMethodType = "textDocument/signatureHelp";
struct In_TextDocumentSignatureHelp : public RequestMessage { struct In_TextDocumentSignatureHelp : public RequestInMessage {
MethodType GetMethodType() const override { return kMethodType; } MethodType GetMethodType() const override { return kMethodType; }
lsTextDocumentPositionParams params; lsTextDocumentPositionParams params;
}; };
@ -86,7 +86,7 @@ MAKE_REFLECT_STRUCT(Out_TextDocumentSignatureHelp, jsonrpc, id, result);
struct Handler_TextDocumentSignatureHelp : MessageHandler { struct Handler_TextDocumentSignatureHelp : MessageHandler {
MethodType GetMethodType() const override { return kMethodType; } 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()); auto request = static_cast<In_TextDocumentSignatureHelp*>(message.get());
lsTextDocumentPositionParams& params = request->params; lsTextDocumentPositionParams& params = request->params;
WorkingFile* file = WorkingFile* file =
@ -103,7 +103,7 @@ struct Handler_TextDocumentSignatureHelp : MessageHandler {
return; return;
ClangCompleteManager::OnComplete callback = std::bind( 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, const std::vector<lsCompletionItem>& results,
bool is_cached_result) { bool is_cached_result) {
auto msg = static_cast<In_TextDocumentSignatureHelp*>(message); auto msg = static_cast<In_TextDocumentSignatureHelp*>(message);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
#include "ipc.h" #include "method.h"
const char* kMethodType_Unknown = "$unknown"; const char* kMethodType_Unknown = "$unknown";
const char* kMethodType_Exit = "exit"; const char* kMethodType_Exit = "exit";
@ -6,8 +6,12 @@ const char* kMethodType_TextDocumentPublishDiagnostics = "textDocument/publishDi
const char* kMethodType_CqueryPublishInactiveRegions = "$cquery/publishInactiveRegions"; const char* kMethodType_CqueryPublishInactiveRegions = "$cquery/publishInactiveRegions";
const char* kMethodType_CqueryPublishSemanticHighlighting = "$cquery/publishSemanticHighlighting"; 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(); return std::monostate();
} }

View File

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

View File

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

View File

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