From f4ed1d20ec259281cab4e009cd454ff6a274a3e8 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 3 Jun 2021 11:21:28 +0200 Subject: [PATCH] LanguageClient: Use double for progress reports Some servers *cough* clangd *cough* report their progress in double instead of the uint defined by the protocol. Since this does not make a huge difference for the LanguageClient or json switch to double for progress. Change-Id: I76454285e5a3b582d6c6a23a6dfbeb5f1cd7631f Reviewed-by: Christian Kandeler --- src/libs/languageserverprotocol/progresssupport.h | 8 ++++++-- src/plugins/languageclient/progressmanager.cpp | 5 ++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libs/languageserverprotocol/progresssupport.h b/src/libs/languageserverprotocol/progresssupport.h index 0c2be91cda4..65cead4287b 100644 --- a/src/libs/languageserverprotocol/progresssupport.h +++ b/src/libs/languageserverprotocol/progresssupport.h @@ -76,8 +76,12 @@ public: * The value should be steadily rising. Clients are free to ignore values * that are not following this rule. */ - Utils::optional percentage() const { return optionalValue(percentageKey); } - void setPercentage(int percentage) { insert(percentageKey, percentage); } + + // Allthough percentage is defined as an uint by the protocol some server + // return a double here. Be less strict and also use a double. + // CAUTION: the range is still 0 - 100 and not 0 - 1 + Utils::optional percentage() const { return optionalValue(percentageKey); } + void setPercentage(double percentage) { insert(percentageKey, percentage); } void clearPercentage() { remove(percentageKey); } }; diff --git a/src/plugins/languageclient/progressmanager.cpp b/src/plugins/languageclient/progressmanager.cpp index a8543378334..d25da8a3e0f 100644 --- a/src/plugins/languageclient/progressmanager.cpp +++ b/src/plugins/languageclient/progressmanager.cpp @@ -107,9 +107,8 @@ void ProgressManager::reportProgress(const ProgressToken &token, } } if (progress.futureInterface) { - const Utils::optional &progressValue = report.percentage(); - if (progressValue.has_value()) - progress.futureInterface->setProgressValue(*progressValue); + if (const Utils::optional &percentage = report.percentage(); percentage.has_value()) + progress.futureInterface->setProgressValue(*percentage); } }