mirror of
https://github.com/MaskRay/ccls.git
synced 2025-02-07 17:32:14 +00:00
A little bit more IPC cleanup
This commit is contained in:
parent
724d8cc3f4
commit
5105f41f6d
@ -96,8 +96,7 @@ struct IpcManager {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
void SendOutMessageToClient(lsBaseOutMessage& response) {
|
||||||
void SendOutMessageToClient(T& response) {
|
|
||||||
std::ostringstream sstream;
|
std::ostringstream sstream;
|
||||||
response.Write(sstream);
|
response.Write(sstream);
|
||||||
|
|
||||||
@ -109,8 +108,7 @@ struct IpcManager {
|
|||||||
enum class Destination {
|
enum class Destination {
|
||||||
Client, Server
|
Client, Server
|
||||||
};
|
};
|
||||||
template <typename TId, typename TMessage>
|
void SendMessageWithId(Destination destination, IpcId id, BaseIpcMessage& message) {
|
||||||
void SendMessageWithId(Destination destination, TId id, TMessage& message) {
|
|
||||||
ipc_queue_->SendMessage(
|
ipc_queue_->SendMessage(
|
||||||
destination == Destination::Client ? &ipc_queue_->for_client : &ipc_queue_->for_server,
|
destination == Destination::Client ? &ipc_queue_->for_client : &ipc_queue_->for_server,
|
||||||
id,
|
id,
|
||||||
@ -121,8 +119,7 @@ struct IpcManager {
|
|||||||
SendMessageWithId(destination, TMessage::kIpcId, message);
|
SendMessageWithId(destination, TMessage::kIpcId, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TMessage>
|
std::vector<std::unique_ptr<BaseIpcMessage>> GetMessages(Destination destination) {
|
||||||
std::vector<std::unique_ptr<TMessage>> GetMessages(Destination destination) {
|
|
||||||
return ipc_queue_->GetMessages(destination == Destination::Client ? &ipc_queue_->for_client : &ipc_queue_->for_server);
|
return ipc_queue_->GetMessages(destination == Destination::Client ? &ipc_queue_->for_client : &ipc_queue_->for_server);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -999,7 +996,7 @@ void QueryDbMainLoop(
|
|||||||
WorkingFiles* working_files,
|
WorkingFiles* working_files,
|
||||||
CompletionManager* completion_manager) {
|
CompletionManager* completion_manager) {
|
||||||
|
|
||||||
std::vector<std::unique_ptr<BaseIpcMessage>> messages = language_client->GetMessages<BaseIpcMessage>(IpcManager::Destination::Server);
|
std::vector<std::unique_ptr<BaseIpcMessage>> messages = language_client->GetMessages(IpcManager::Destination::Server);
|
||||||
for (auto& message : messages) {
|
for (auto& message : messages) {
|
||||||
//std::cerr << "[querydb] Processing message " << static_cast<int>(message->method_id) << std::endl;
|
//std::cerr << "[querydb] Processing message " << static_cast<int>(message->method_id) << std::endl;
|
||||||
|
|
||||||
@ -1682,7 +1679,7 @@ void LanguageServerStdinLoop(IpcManager* ipc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LanguageServerMainLoop(IpcManager* ipc) {
|
void LanguageServerMainLoop(IpcManager* ipc) {
|
||||||
std::vector<std::unique_ptr<BaseIpcMessage>> messages = ipc->GetMessages<BaseIpcMessage>(IpcManager::Destination::Client);
|
std::vector<std::unique_ptr<BaseIpcMessage>> messages = ipc->GetMessages(IpcManager::Destination::Client);
|
||||||
for (auto& message : messages) {
|
for (auto& message : messages) {
|
||||||
switch (message->method_id) {
|
switch (message->method_id) {
|
||||||
case IpcId::Quit: {
|
case IpcId::Quit: {
|
||||||
@ -1763,7 +1760,7 @@ bool IsQueryDbProcessRunning(IpcManager* ipc) {
|
|||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
|
||||||
// Check if we got an IsAlive message back.
|
// Check if we got an IsAlive message back.
|
||||||
std::vector<std::unique_ptr<BaseIpcMessage>> messages = ipc->GetMessages<BaseIpcMessage>(IpcManager::Destination::Client);
|
std::vector<std::unique_ptr<BaseIpcMessage>> messages = ipc->GetMessages(IpcManager::Destination::Client);
|
||||||
for (auto& message : messages) {
|
for (auto& message : messages) {
|
||||||
if (IpcId::IsAlive == message->method_id)
|
if (IpcId::IsAlive == message->method_id)
|
||||||
return true;
|
return true;
|
||||||
@ -1776,7 +1773,7 @@ void LanguageServerMain(std::string process_name) {
|
|||||||
IpcManager ipc;
|
IpcManager ipc;
|
||||||
|
|
||||||
// Discard any left-over messages from previous runs.
|
// Discard any left-over messages from previous runs.
|
||||||
ipc.GetMessages<BaseIpcMessage>(IpcManager::Destination::Client);
|
ipc.GetMessages(IpcManager::Destination::Client);
|
||||||
|
|
||||||
bool has_server = IsQueryDbProcessRunning(&ipc);
|
bool has_server = IsQueryDbProcessRunning(&ipc);
|
||||||
|
|
||||||
|
@ -32,7 +32,6 @@ TEST_CASE("sanity") {
|
|||||||
// TODO: check case
|
// TODO: check case
|
||||||
CHECK(m.IsMatch("abc"));
|
CHECK(m.IsMatch("abc"));
|
||||||
CHECK(m.IsMatch("fooabc"));
|
CHECK(m.IsMatch("fooabc"));
|
||||||
CHECK(m.IsMatch("fooabc"));
|
|
||||||
CHECK(m.IsMatch("abc"));
|
CHECK(m.IsMatch("abc"));
|
||||||
CHECK(m.IsMatch("abcfoo"));
|
CHECK(m.IsMatch("abcfoo"));
|
||||||
CHECK(m.IsMatch("11a11b11c11"));
|
CHECK(m.IsMatch("11a11b11c11"));
|
||||||
|
@ -103,14 +103,17 @@ struct MessageRegistry {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct lsBaseOutMessage {
|
||||||
|
virtual void Write(std::ostream& out) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
template<typename TDerived>
|
template<typename TDerived>
|
||||||
struct lsOutMessage {
|
struct lsOutMessage : lsBaseOutMessage {
|
||||||
// All derived types need to reflect on the |jsonrpc| member.
|
// All derived types need to reflect on the |jsonrpc| member.
|
||||||
std::string jsonrpc = "2.0";
|
std::string jsonrpc = "2.0";
|
||||||
|
|
||||||
// Send the message to the language client by writing it to stdout.
|
// 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;
|
rapidjson::StringBuffer output;
|
||||||
Writer writer(output);
|
Writer writer(output);
|
||||||
auto that = static_cast<TDerived*>(this);
|
auto that = static_cast<TDerived*>(this);
|
||||||
|
Loading…
Reference in New Issue
Block a user