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 <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2019-03-15 10:05:40 +01:00
parent 988fe7384e
commit 6d0d227974
2 changed files with 4 additions and 6 deletions

View File

@@ -232,6 +232,7 @@ template <typename Result, typename ErrorDataType>
class Response : public JsonRpcMessage
{
public:
explicit Response(const MessageId &id) { setId(id); }
using JsonRpcMessage::JsonRpcMessage;
MessageId id() const

View File

@@ -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<MessageActionItem>(item)
: LanguageClientValue<MessageActionItem>());
@@ -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<std::nullptr_t> 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<JsonObject, JsonObject> response;
response.setId(id);
Response<JsonObject, JsonObject> response(id);
ResponseError<JsonObject> error;
error.setCode(ResponseError<JsonObject>::MethodNotFound);
response.setError(error);