Browse Source

Language server logging can now be enabled in preferences

merge-requests/389/head
eidheim 7 years ago
parent
commit
9a5eaf892a
  1. 2
      CMakeLists.txt
  2. 2
      src/config.cc
  3. 6
      src/config.h
  4. 3
      src/files.h
  5. 13
      src/source_language_protocol.cc

2
CMakeLists.txt

@ -1,7 +1,7 @@
cmake_minimum_required (VERSION 2.8.8) cmake_minimum_required (VERSION 2.8.8)
project(juci) project(juci)
set(JUCI_VERSION "1.4.4") set(JUCI_VERSION "1.4.4.1")
set(CPACK_PACKAGE_NAME "jucipp") set(CPACK_PACKAGE_NAME "jucipp")
set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim <eidheim@gmail.com>") set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim <eidheim@gmail.com>")

2
src/config.cc

@ -201,4 +201,6 @@ void Config::read(const boost::property_tree::ptree &cfg) {
terminal.history_size = cfg.get<int>("terminal.history_size"); terminal.history_size = cfg.get<int>("terminal.history_size");
terminal.font = cfg.get<std::string>("terminal.font"); terminal.font = cfg.get<std::string>("terminal.font");
log.language_server = cfg.get<bool>("log.language_server");
} }

6
src/config.h

@ -94,6 +94,11 @@ public:
std::unordered_map<std::string, DocumentationSearch> documentation_searches; std::unordered_map<std::string, DocumentationSearch> documentation_searches;
}; };
class Log {
public:
bool language_server;
};
private: private:
Config(); Config();
@ -110,6 +115,7 @@ public:
Terminal terminal; Terminal terminal;
Project project; Project project;
Source source; Source source;
Log log;
boost::filesystem::path home_path; boost::filesystem::path home_path;
boost::filesystem::path home_juci_path; boost::filesystem::path home_juci_path;

3
src/files.h

@ -191,6 +191,9 @@ const std::string default_config_file = R"RAW({
"@any": "https://www.google.com/search?btnI&q=" "@any": "https://www.google.com/search?btnI&q="
} }
} }
},
"log": {
"language_server": false
} }
} }
)RAW"; )RAW";

13
src/source_language_protocol.cc

@ -7,13 +7,12 @@
#ifdef JUCI_ENABLE_DEBUG #ifdef JUCI_ENABLE_DEBUG
#include "debug_lldb.h" #include "debug_lldb.h"
#endif #endif
#include "config.h"
#include "menu.h" #include "menu.h"
#include <future> #include <future>
#include <limits> #include <limits>
#include <regex> #include <regex>
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_)) { 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<TinyProcessLib::Process>(language_id + "-language-server", root_uri, [this](const char *bytes, size_t n) { process = std::make_unique<TinyProcessLib::Process>(language_id + "-language-server", root_uri, [this](const char *bytes, size_t n) {
server_message_stream.write(bytes, n); server_message_stream.write(bytes, n);
@ -69,7 +68,7 @@ LanguageProtocol::Client::~Client() {
if(process->try_get_exit_status(exit_status)) if(process->try_get_exit_status(exit_status))
break; break;
} }
if(output_messages_and_errors) if(Config::get().log.language_server)
std::cout << "Language server exit status: " << exit_status << std::endl; std::cout << "Language server exit status: " << exit_status << std::endl;
if(exit_status == -1) if(exit_status == -1)
process->kill(); process->kill();
@ -176,7 +175,7 @@ void LanguageProtocol::Client::parse_server_message() {
boost::property_tree::ptree pt; boost::property_tree::ptree pt;
boost::property_tree::read_json(server_message_stream, 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: "; std::cout << "language server: ";
boost::property_tree::write_json(std::cout, pt); 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()) { 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); boost::property_tree::write_json(std::cerr, pt);
if(message_id) { if(message_id) {
auto id_it = handlers.find(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 + "}}"); 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; 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; std::cout << "Language client: " << content << std::endl;
if(!process->write(message)) { if(!process->write(message)) {
Terminal::get().async_print("Error writing to language protocol server. Please close and reopen all project source files.\n", true); 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<std::mutex> lock(read_write_mutex); std::unique_lock<std::mutex> lock(read_write_mutex);
std::string content(R"({"jsonrpc":"2.0","method":")" + method + R"(","params":{)" + params + "}}"); 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; 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; std::cout << "Language client: " << content << std::endl;
process->write(message); process->write(message);
} }

Loading…
Cancel
Save