From 71fa2d950c938bcda279a5e5d8d0c64635030906 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 18 Jul 2019 13:26:34 +0200 Subject: [PATCH] LSP: update colorProvider entry of ServerCapabilities Since version 3.8.0 of the lsp the server can provide the information whether it supports colors also via an boolean value. The newly added ColorProviderOptions are currently completely empty, so we ignore them. Fixes: QTCREATORBUG-22691 Change-Id: I76232d160f4abed7b07574dc1b5413cead26b9f0 Reviewed-by: Christian Stenger --- .../servercapabilities.cpp | 21 ++++++++++++++++++- .../servercapabilities.h | 6 ++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/libs/languageserverprotocol/servercapabilities.cpp b/src/libs/languageserverprotocol/servercapabilities.cpp index 3d2721f4a69..1b2c0bd9cc0 100644 --- a/src/libs/languageserverprotocol/servercapabilities.cpp +++ b/src/libs/languageserverprotocol/servercapabilities.cpp @@ -130,6 +130,25 @@ void ServerCapabilities::setRenameProvider(Utils::variant(renameProvider)); } +Utils::optional> ServerCapabilities::colorProvider() const +{ + using RetType = Utils::variant; + const QJsonValue &localValue = value(colorProviderKey); + if (localValue.isBool()) + return RetType(localValue.toBool()); + if (localValue.isObject()) + return RetType(JsonObject(localValue.toObject())); + return Utils::nullopt; +} + +void ServerCapabilities::setColorProvider(Utils::variant colorProvider) +{ + if (Utils::holds_alternative(colorProvider)) + insert(renameProviderKey, Utils::get(colorProvider)); + else if (Utils::holds_alternative(colorProvider)) + insert(renameProviderKey, Utils::get(colorProvider)); +} + bool ServerCapabilities::isValid(QStringList *error) const { return checkOptional(error, textDocumentSyncKey) @@ -149,7 +168,7 @@ bool ServerCapabilities::isValid(QStringList *error) const && checkOptional(error, documentRangeFormattingProviderKey) && checkOptional(error, renameProviderKey) && checkOptional(error, documentLinkProviderKey) - && checkOptional(error, colorProviderKey) + && checkOptional(error, colorProviderKey) && checkOptional(error, executeCommandProviderKey) && checkOptional(error, workspaceKey); } diff --git a/src/libs/languageserverprotocol/servercapabilities.h b/src/libs/languageserverprotocol/servercapabilities.h index 0cbc7facf87..4c8011378f4 100644 --- a/src/libs/languageserverprotocol/servercapabilities.h +++ b/src/libs/languageserverprotocol/servercapabilities.h @@ -373,10 +373,8 @@ public: void clearDocumentLinkProvider() { remove(documentLinkProviderKey); } // The server provides color provider support. - Utils::optional colorProvider() const - { return optionalValue(colorProviderKey); } - void setColorProvider(TextDocumentRegistrationOptions colorProvider) - { insert(colorProviderKey, colorProvider); } + Utils::optional> colorProvider() const; + void setColorProvider(Utils::variant colorProvider); void clearColorProvider() { remove(colorProviderKey); } // The server provides execute command support.