forked from qt-creator/qt-creator
LanguageClient: do not send empty responses
Even if we do not have to provide any data just send a null as the result so the server nows that the request did not fail. Fixes: QTCREATORBUG-26116 Change-Id: I9b965389bb197cdd81d0d3ffbac05f289cabda40 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -236,7 +236,7 @@ public:
|
|||||||
|
|
||||||
Utils::optional<Result> result() const
|
Utils::optional<Result> result() const
|
||||||
{
|
{
|
||||||
const QJsonValue &result = m_jsonObject.value("result");
|
const QJsonValue &result = m_jsonObject.value(resultKey);
|
||||||
if (result.isUndefined())
|
if (result.isUndefined())
|
||||||
return Utils::nullopt;
|
return Utils::nullopt;
|
||||||
return Utils::make_optional(Result(result));
|
return Utils::make_optional(Result(result));
|
||||||
@@ -259,6 +259,41 @@ public:
|
|||||||
{ return JsonRpcMessage::isValid(errorMessage) && id().isValid(); }
|
{ return JsonRpcMessage::isValid(errorMessage) && id().isValid(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename ErrorDataType>
|
||||||
|
class Response<std::nullptr_t, ErrorDataType> : public JsonRpcMessage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit Response(const MessageId &id) { setId(id); }
|
||||||
|
using JsonRpcMessage::JsonRpcMessage;
|
||||||
|
|
||||||
|
MessageId id() const
|
||||||
|
{ return MessageId(m_jsonObject.value(idKey)); }
|
||||||
|
void setId(MessageId id)
|
||||||
|
{ this->m_jsonObject.insert(idKey, id); }
|
||||||
|
|
||||||
|
Utils::optional<std::nullptr_t> result() const
|
||||||
|
{
|
||||||
|
return m_jsonObject.value(resultKey).isNull() ? Utils::make_optional(nullptr)
|
||||||
|
: Utils::nullopt;
|
||||||
|
}
|
||||||
|
void setResult(const std::nullptr_t &) { m_jsonObject.insert(resultKey, QJsonValue::Null); }
|
||||||
|
void clearResult() { m_jsonObject.remove(resultKey); }
|
||||||
|
|
||||||
|
using Error = ResponseError<ErrorDataType>;
|
||||||
|
Utils::optional<Error> error() const
|
||||||
|
{
|
||||||
|
const QJsonValue &val = m_jsonObject.value(errorKey);
|
||||||
|
return val.isUndefined() ? Utils::nullopt
|
||||||
|
: Utils::make_optional(fromJsonValue<Error>(val));
|
||||||
|
}
|
||||||
|
void setError(const Error &error)
|
||||||
|
{ m_jsonObject.insert(errorKey, QJsonValue(error)); }
|
||||||
|
void clearError() { m_jsonObject.remove(errorKey); }
|
||||||
|
|
||||||
|
bool isValid(QString *errorMessage) const override
|
||||||
|
{ return JsonRpcMessage::isValid(errorMessage) && id().isValid(); }
|
||||||
|
};
|
||||||
|
|
||||||
template <typename Result, typename ErrorDataType, typename Params>
|
template <typename Result, typename ErrorDataType, typename Params>
|
||||||
class Request : public Notification<Params>
|
class Request : public Notification<Params>
|
||||||
{
|
{
|
||||||
|
@@ -1293,8 +1293,10 @@ void Client::handleMethod(const QString &method, const MessageId &id, const ICon
|
|||||||
response.setResult(result);
|
response.setResult(result);
|
||||||
sendContent(response);
|
sendContent(response);
|
||||||
} else if (method == WorkDoneProgressCreateRequest::methodName) {
|
} else if (method == WorkDoneProgressCreateRequest::methodName) {
|
||||||
sendContent(WorkDoneProgressCreateRequest::Response(
|
WorkDoneProgressCreateRequest::Response response(
|
||||||
dynamic_cast<const WorkDoneProgressCreateRequest *>(content)->id()));
|
dynamic_cast<const WorkDoneProgressCreateRequest *>(content)->id());
|
||||||
|
response.setResult(nullptr);
|
||||||
|
sendContent(response);
|
||||||
} else if (method == ProgressNotification::methodName) {
|
} else if (method == ProgressNotification::methodName) {
|
||||||
if (Utils::optional<ProgressParams> params
|
if (Utils::optional<ProgressParams> params
|
||||||
= dynamic_cast<const ProgressNotification *>(content)->params()) {
|
= dynamic_cast<const ProgressNotification *>(content)->params()) {
|
||||||
|
Reference in New Issue
Block a user