From 5105f41f6d85fe4860284b17e98ad57c5bd8bfab Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Sun, 16 Apr 2017 13:43:30 -0700 Subject: [PATCH] A little bit more IPC cleanup --- src/command_line.cc | 17 +++++++---------- src/fuzzy.cc | 1 - src/language_server_api.h | 7 +++++-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/command_line.cc b/src/command_line.cc index e2694ea7..40d37708 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -96,8 +96,7 @@ struct IpcManager { - template - void SendOutMessageToClient(T& response) { + void SendOutMessageToClient(lsBaseOutMessage& response) { std::ostringstream sstream; response.Write(sstream); @@ -109,8 +108,7 @@ struct IpcManager { enum class Destination { Client, Server }; - template - void SendMessageWithId(Destination destination, TId id, TMessage& message) { + void SendMessageWithId(Destination destination, IpcId id, BaseIpcMessage& message) { ipc_queue_->SendMessage( destination == Destination::Client ? &ipc_queue_->for_client : &ipc_queue_->for_server, id, @@ -121,8 +119,7 @@ struct IpcManager { SendMessageWithId(destination, TMessage::kIpcId, message); } - template - std::vector> GetMessages(Destination destination) { + std::vector> GetMessages(Destination destination) { return ipc_queue_->GetMessages(destination == Destination::Client ? &ipc_queue_->for_client : &ipc_queue_->for_server); } @@ -999,7 +996,7 @@ void QueryDbMainLoop( WorkingFiles* working_files, CompletionManager* completion_manager) { - std::vector> messages = language_client->GetMessages(IpcManager::Destination::Server); + std::vector> messages = language_client->GetMessages(IpcManager::Destination::Server); for (auto& message : messages) { //std::cerr << "[querydb] Processing message " << static_cast(message->method_id) << std::endl; @@ -1682,7 +1679,7 @@ void LanguageServerStdinLoop(IpcManager* ipc) { } void LanguageServerMainLoop(IpcManager* ipc) { - std::vector> messages = ipc->GetMessages(IpcManager::Destination::Client); + std::vector> messages = ipc->GetMessages(IpcManager::Destination::Client); for (auto& message : messages) { switch (message->method_id) { case IpcId::Quit: { @@ -1763,7 +1760,7 @@ bool IsQueryDbProcessRunning(IpcManager* ipc) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); // Check if we got an IsAlive message back. - std::vector> messages = ipc->GetMessages(IpcManager::Destination::Client); + std::vector> messages = ipc->GetMessages(IpcManager::Destination::Client); for (auto& message : messages) { if (IpcId::IsAlive == message->method_id) return true; @@ -1776,7 +1773,7 @@ void LanguageServerMain(std::string process_name) { IpcManager ipc; // Discard any left-over messages from previous runs. - ipc.GetMessages(IpcManager::Destination::Client); + ipc.GetMessages(IpcManager::Destination::Client); bool has_server = IsQueryDbProcessRunning(&ipc); diff --git a/src/fuzzy.cc b/src/fuzzy.cc index 8ab5a4a8..9cd0ed1d 100644 --- a/src/fuzzy.cc +++ b/src/fuzzy.cc @@ -32,7 +32,6 @@ TEST_CASE("sanity") { // TODO: check case CHECK(m.IsMatch("abc")); CHECK(m.IsMatch("fooabc")); - CHECK(m.IsMatch("fooabc")); CHECK(m.IsMatch("abc")); CHECK(m.IsMatch("abcfoo")); CHECK(m.IsMatch("11a11b11c11")); diff --git a/src/language_server_api.h b/src/language_server_api.h index 09d3a3c5..1b89f8a8 100644 --- a/src/language_server_api.h +++ b/src/language_server_api.h @@ -103,14 +103,17 @@ struct MessageRegistry { }; +struct lsBaseOutMessage { + virtual void Write(std::ostream& out) = 0; +}; template -struct lsOutMessage { +struct lsOutMessage : lsBaseOutMessage { // All derived types need to reflect on the |jsonrpc| member. std::string jsonrpc = "2.0"; // Send the message to the language client by writing it to stdout. - void Write(std::ostream& out) { + void Write(std::ostream& out) override { rapidjson::StringBuffer output; Writer writer(output); auto that = static_cast(this);