From 40f863b9cf108425eac235e2a5142e62de2f1453 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Fri, 15 Oct 2021 10:40:02 +0200 Subject: [PATCH] LanguageClient: Allow to log to console rather than message window And make use of that in ClangdClient. When I get a slowdown while typing, it is usually accompanied by the clangd message "Request cancelled because the document was modified" occurring in the message window, often many times in a row. I'd like to find out whether writing to the message window itself is a contributing factor to the slowdown. Change-Id: Iff7c459af0aed27d22366b9aade573f51eb5dbc7 Reviewed-by: David Schulz --- src/plugins/clangcodemodel/clangdclient.cpp | 1 + src/plugins/languageclient/client.cpp | 9 ++++++++- src/plugins/languageclient/client.h | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index d8b98a0a2d0..34eb06791ae 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -1081,6 +1081,7 @@ ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir) "text/x-c++hdr", "text/x-c++src", "text/x-objc++src", "text/x-objcsrc"}; setSupportedLanguage(langFilter); setActivateDocumentAutomatically(true); + setLogTarget(LogTarget::Console); setCompletionAssistProvider(new ClangdCompletionAssistProvider(this)); if (!project) { QJsonObject initOptions; diff --git a/src/plugins/languageclient/client.cpp b/src/plugins/languageclient/client.cpp index 5f2b44d5e91..b177f82c520 100644 --- a/src/plugins/languageclient/client.cpp +++ b/src/plugins/languageclient/client.cpp @@ -1133,7 +1133,14 @@ void Client::handleMessage(const BaseMessage &message) void Client::log(const QString &message) const { - Core::MessageManager::writeFlashing(QString("LanguageClient %1: %2").arg(name(), message)); + switch (m_logTarget) { + case LogTarget::Ui: + Core::MessageManager::writeFlashing(QString("LanguageClient %1: %2").arg(name(), message)); + break; + case LogTarget::Console: + qCDebug(LOGLSPCLIENT) << message; + break; + } } const ServerCapabilities &Client::capabilities() const diff --git a/src/plugins/languageclient/client.h b/src/plugins/languageclient/client.h index bf06359ef41..59f23599a49 100644 --- a/src/plugins/languageclient/client.h +++ b/src/plugins/languageclient/client.h @@ -189,6 +189,8 @@ public: void setCompletionAssistProvider(LanguageClientCompletionAssistProvider *provider); // logging + enum class LogTarget { Console, Ui }; + void setLogTarget(LogTarget target) { m_logTarget = target; } void log(const QString &message) const; template void log(const LanguageServerProtocol::ResponseError &responseError) const @@ -288,6 +290,7 @@ private: QString m_serverName; QString m_serverVersion; LanguageServerProtocol::SymbolStringifier m_symbolStringifier; + LogTarget m_logTarget = LogTarget::Ui; bool m_locatorsEnabled = true; bool m_autoRequestCodeActions = true; };