From 6d0d2279746e3bbcd50a4b56e734a28c36bf44c5 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Fri, 15 Mar 2019 10:05:40 +0100 Subject: [PATCH] LSP: Require an id for a response The id is the essential part of a response. Make the protocol implementation more stable by requiring this id in the Response constructor. Change-Id: I18908c8441be1ddd890058f3dd09fc8cda3b868c Reviewed-by: Christian Stenger --- src/libs/languageserverprotocol/jsonrpcmessages.h | 1 + src/plugins/languageclient/client.cpp | 9 +++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/libs/languageserverprotocol/jsonrpcmessages.h b/src/libs/languageserverprotocol/jsonrpcmessages.h index 66c28bea4be..473c9fe5808 100644 --- a/src/libs/languageserverprotocol/jsonrpcmessages.h +++ b/src/libs/languageserverprotocol/jsonrpcmessages.h @@ -232,6 +232,7 @@ template class Response : public JsonRpcMessage { public: + explicit Response(const MessageId &id) { setId(id); } using JsonRpcMessage::JsonRpcMessage; MessageId id() const diff --git a/src/plugins/languageclient/client.cpp b/src/plugins/languageclient/client.cpp index c67934bbdac..2b96e0d073f 100644 --- a/src/plugins/languageclient/client.cpp +++ b/src/plugins/languageclient/client.cpp @@ -784,8 +784,7 @@ void Client::showMessageBox(const ShowMessageRequestParams &message, const Messa } box->setModal(true); connect(box, &QMessageBox::finished, this, [=]{ - ShowMessageRequest::Response response; - response.setId(id); + ShowMessageRequest::Response response(id); const MessageActionItem &item = itemForButton.value(box->clickedButton()); response.setResult(item.isValid(nullptr) ? LanguageClientValue(item) : LanguageClientValue()); @@ -847,8 +846,7 @@ void Client::handleMethod(const QString &method, MessageId id, const IContent *c if (paramsValid) { showMessageBox(params, request->id()); } else { - ShowMessageRequest::Response response; - response.setId(request->id()); + ShowMessageRequest::Response response(request->id()); ResponseError error; const QString errorMessage = QString("Could not parse ShowMessageRequest parameter of '%1': \"%2\"") @@ -874,8 +872,7 @@ void Client::handleMethod(const QString &method, MessageId id, const IContent *c if (paramsValid) applyWorkspaceEdit(params.edit()); } else if (id.isValid(&error)) { - Response response; - response.setId(id); + Response response(id); ResponseError error; error.setCode(ResponseError::MethodNotFound); response.setError(error);