LanguageClient: log exit notification

Add a private function that logs and sends a basemessage without
checking the current server state and use it for server init,
sendContent and exit.

Change-Id: I6532dfb36ef5bf4d036bb71dbfab4ab29497fc9a
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2022-02-14 14:43:53 +01:00
parent 3905239cea
commit dc268e3157
2 changed files with 12 additions and 9 deletions

View File

@@ -307,13 +307,11 @@ void Client::initialize()
initRequest.setResponseCallback([this](const InitializeRequest::Response &initResponse){ initRequest.setResponseCallback([this](const InitializeRequest::Response &initResponse){
initializeCallback(initResponse); initializeCallback(initResponse);
}); });
// directly send data otherwise the state check would fail;
if (Utils::optional<ResponseHandler> responseHandler = initRequest.responseHandler()) if (Utils::optional<ResponseHandler> responseHandler = initRequest.responseHandler())
m_responseHandlers[responseHandler->id] = responseHandler->callback; m_responseHandlers[responseHandler->id] = responseHandler->callback;
LanguageClientManager::logBaseMessage(LspLogMessage::ClientMessage, // directly send message otherwise the state check of sendContent would fail
name(), sendMessage(initRequest.toBaseMessage());
initRequest.toBaseMessage());
m_clientInterface->sendMessage(initRequest.toBaseMessage()); m_clientInterface->sendMessage(initRequest.toBaseMessage());
m_state = InitializeRequested; m_state = InitializeRequested;
} }
@@ -426,9 +424,7 @@ void Client::sendContent(const IContent &content, SendDocUpdates sendUpdates)
QString error; QString error;
if (!QTC_GUARD(content.isValid(&error))) if (!QTC_GUARD(content.isValid(&error)))
Core::MessageManager::writeFlashing(error); Core::MessageManager::writeFlashing(error);
const BaseMessage message = content.toBaseMessage(); sendMessage(content.toBaseMessage());
LanguageClientManager::logBaseMessage(LspLogMessage::ClientMessage, name(), message);
m_clientInterface->sendMessage(message);
} }
void Client::cancelRequest(const MessageId &id) void Client::cancelRequest(const MessageId &id)
@@ -1450,6 +1446,12 @@ void Client::handleDiagnostics(const PublishDiagnosticsParams &params)
} }
} }
void Client::sendMessage(const BaseMessage &message)
{
LanguageClientManager::logBaseMessage(LspLogMessage::ClientMessage, name(), message);
m_clientInterface->sendMessage(message);
}
bool Client::documentUpdatePostponed(const Utils::FilePath &fileName) const bool Client::documentUpdatePostponed(const Utils::FilePath &fileName) const
{ {
return Utils::contains(m_documentsToUpdate, [fileName](const auto &elem) { return Utils::contains(m_documentsToUpdate, [fileName](const auto &elem) {
@@ -1560,8 +1562,8 @@ void Client::shutDownCallback(const ShutdownRequest::Response &shutdownResponse)
qDebug() << error; qDebug() << error;
return; return;
} }
// directly send data otherwise the state check would fail; // directly send message otherwise the state check of sendContent would fail
m_clientInterface->sendMessage(ExitNotification().toBaseMessage()); sendMessage(ExitNotification().toBaseMessage());
qCDebug(LOGLSPCLIENT) << "language server " << m_displayName << " shutdown"; qCDebug(LOGLSPCLIENT) << "language server " << m_displayName << " shutdown";
m_state = Shutdown; m_state = Shutdown;
} }

View File

@@ -221,6 +221,7 @@ protected:
virtual void handleDiagnostics(const LanguageServerProtocol::PublishDiagnosticsParams &params); virtual void handleDiagnostics(const LanguageServerProtocol::PublishDiagnosticsParams &params);
private: private:
void sendMessage(const LanguageServerProtocol::BaseMessage &message);
void handleResponse(const LanguageServerProtocol::MessageId &id, const QByteArray &content, void handleResponse(const LanguageServerProtocol::MessageId &id, const QByteArray &content,
QTextCodec *codec); QTextCodec *codec);
void handleMethod(const QString &method, const LanguageServerProtocol::MessageId &id, void handleMethod(const QString &method, const LanguageServerProtocol::MessageId &id,