diff --git a/src/plugins/languageclient/client.cpp b/src/plugins/languageclient/client.cpp index f081b960371..503256c4607 100644 --- a/src/plugins/languageclient/client.cpp +++ b/src/plugins/languageclient/client.cpp @@ -307,13 +307,11 @@ void Client::initialize() initRequest.setResponseCallback([this](const InitializeRequest::Response &initResponse){ initializeCallback(initResponse); }); - // directly send data otherwise the state check would fail; if (Utils::optional responseHandler = initRequest.responseHandler()) m_responseHandlers[responseHandler->id] = responseHandler->callback; - LanguageClientManager::logBaseMessage(LspLogMessage::ClientMessage, - name(), - initRequest.toBaseMessage()); + // directly send message otherwise the state check of sendContent would fail + sendMessage(initRequest.toBaseMessage()); m_clientInterface->sendMessage(initRequest.toBaseMessage()); m_state = InitializeRequested; } @@ -426,9 +424,7 @@ void Client::sendContent(const IContent &content, SendDocUpdates sendUpdates) QString error; if (!QTC_GUARD(content.isValid(&error))) Core::MessageManager::writeFlashing(error); - const BaseMessage message = content.toBaseMessage(); - LanguageClientManager::logBaseMessage(LspLogMessage::ClientMessage, name(), message); - m_clientInterface->sendMessage(message); + sendMessage(content.toBaseMessage()); } void Client::cancelRequest(const MessageId &id) @@ -1450,6 +1446,12 @@ void Client::handleDiagnostics(const PublishDiagnosticsParams ¶ms) } } +void Client::sendMessage(const BaseMessage &message) +{ + LanguageClientManager::logBaseMessage(LspLogMessage::ClientMessage, name(), message); + m_clientInterface->sendMessage(message); +} + bool Client::documentUpdatePostponed(const Utils::FilePath &fileName) const { return Utils::contains(m_documentsToUpdate, [fileName](const auto &elem) { @@ -1560,8 +1562,8 @@ void Client::shutDownCallback(const ShutdownRequest::Response &shutdownResponse) qDebug() << error; return; } - // directly send data otherwise the state check would fail; - m_clientInterface->sendMessage(ExitNotification().toBaseMessage()); + // directly send message otherwise the state check of sendContent would fail + sendMessage(ExitNotification().toBaseMessage()); qCDebug(LOGLSPCLIENT) << "language server " << m_displayName << " shutdown"; m_state = Shutdown; } diff --git a/src/plugins/languageclient/client.h b/src/plugins/languageclient/client.h index 7f5a9fa46cd..c999dd84ef6 100644 --- a/src/plugins/languageclient/client.h +++ b/src/plugins/languageclient/client.h @@ -221,6 +221,7 @@ protected: virtual void handleDiagnostics(const LanguageServerProtocol::PublishDiagnosticsParams ¶ms); private: + void sendMessage(const LanguageServerProtocol::BaseMessage &message); void handleResponse(const LanguageServerProtocol::MessageId &id, const QByteArray &content, QTextCodec *codec); void handleMethod(const QString &method, const LanguageServerProtocol::MessageId &id,