From 9a5eaf892a278e79f1fa6144b3b1ad7348f0ecf9 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 22 Jul 2018 18:59:46 +0200 Subject: [PATCH] Language server logging can now be enabled in preferences --- CMakeLists.txt | 2 +- src/config.cc | 2 ++ src/config.h | 6 ++++++ src/files.h | 3 +++ src/source_language_protocol.cc | 13 ++++++------- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 27bac4a..286607c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required (VERSION 2.8.8) project(juci) -set(JUCI_VERSION "1.4.4") +set(JUCI_VERSION "1.4.4.1") set(CPACK_PACKAGE_NAME "jucipp") set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim ") diff --git a/src/config.cc b/src/config.cc index fda194f..1952383 100644 --- a/src/config.cc +++ b/src/config.cc @@ -201,4 +201,6 @@ void Config::read(const boost::property_tree::ptree &cfg) { terminal.history_size = cfg.get("terminal.history_size"); terminal.font = cfg.get("terminal.font"); + + log.language_server = cfg.get("log.language_server"); } diff --git a/src/config.h b/src/config.h index 7307b7b..529b7a0 100644 --- a/src/config.h +++ b/src/config.h @@ -94,6 +94,11 @@ public: std::unordered_map documentation_searches; }; + class Log { + public: + bool language_server; + }; + private: Config(); @@ -110,6 +115,7 @@ public: Terminal terminal; Project project; Source source; + Log log; boost::filesystem::path home_path; boost::filesystem::path home_juci_path; diff --git a/src/files.h b/src/files.h index f0945a3..fad245f 100644 --- a/src/files.h +++ b/src/files.h @@ -191,6 +191,9 @@ const std::string default_config_file = R"RAW({ "@any": "https://www.google.com/search?btnI&q=" } } + }, + "log": { + "language_server": false } } )RAW"; diff --git a/src/source_language_protocol.cc b/src/source_language_protocol.cc index 1c57fb7..5a955d9 100644 --- a/src/source_language_protocol.cc +++ b/src/source_language_protocol.cc @@ -7,13 +7,12 @@ #ifdef JUCI_ENABLE_DEBUG #include "debug_lldb.h" #endif +#include "config.h" #include "menu.h" #include #include #include -const bool output_messages_and_errors = false; - LanguageProtocol::Client::Client(std::string root_uri_, std::string language_id_) : root_uri(std::move(root_uri_)), language_id(std::move(language_id_)) { process = std::make_unique(language_id + "-language-server", root_uri, [this](const char *bytes, size_t n) { server_message_stream.write(bytes, n); @@ -69,7 +68,7 @@ LanguageProtocol::Client::~Client() { if(process->try_get_exit_status(exit_status)) break; } - if(output_messages_and_errors) + if(Config::get().log.language_server) std::cout << "Language server exit status: " << exit_status << std::endl; if(exit_status == -1) process->kill(); @@ -176,7 +175,7 @@ void LanguageProtocol::Client::parse_server_message() { boost::property_tree::ptree pt; boost::property_tree::read_json(server_message_stream, pt); - if(output_messages_and_errors) { + if(Config::get().log.language_server) { std::cout << "language server: "; boost::property_tree::write_json(std::cout, pt); } @@ -199,7 +198,7 @@ void LanguageProtocol::Client::parse_server_message() { } } else if(error_it != pt.not_found()) { - if(!output_messages_and_errors) + if(!Config::get().log.language_server) boost::property_tree::write_json(std::cerr, pt); if(message_id) { auto id_it = handlers.find(message_id); @@ -267,7 +266,7 @@ void LanguageProtocol::Client::write_request(Source::LanguageProtocolView *view, } std::string content(R"({"jsonrpc":"2.0","id":)" + std::to_string(message_id++) + R"(,"method":")" + method + R"(","params":{)" + params + "}}"); auto message = "Content-Length: " + std::to_string(content.size()) + "\r\n\r\n" + content; - if(output_messages_and_errors) + if(Config::get().log.language_server) std::cout << "Language client: " << content << std::endl; if(!process->write(message)) { Terminal::get().async_print("Error writing to language protocol server. Please close and reopen all project source files.\n", true); @@ -286,7 +285,7 @@ void LanguageProtocol::Client::write_notification(const std::string &method, con std::unique_lock lock(read_write_mutex); std::string content(R"({"jsonrpc":"2.0","method":")" + method + R"(","params":{)" + params + "}}"); auto message = "Content-Length: " + std::to_string(content.size()) + "\r\n\r\n" + content; - if(output_messages_and_errors) + if(Config::get().log.language_server) std::cout << "Language client: " << content << std::endl; process->write(message); }