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 <christian.kandeler@qt.io>
This commit is contained in:
David Schulz
2021-06-03 11:21:28 +02:00
parent aa8d2dc2d1
commit f4ed1d20ec
2 changed files with 8 additions and 5 deletions

View File

@@ -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<int> percentage() const { return optionalValue<int>(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<double> percentage() const { return optionalValue<double>(percentageKey); }
void setPercentage(double percentage) { insert(percentageKey, percentage); }
void clearPercentage() { remove(percentageKey); }
};

View File

@@ -107,9 +107,8 @@ void ProgressManager::reportProgress(const ProgressToken &token,
}
}
if (progress.futureInterface) {
const Utils::optional<int> &progressValue = report.percentage();
if (progressValue.has_value())
progress.futureInterface->setProgressValue(*progressValue);
if (const Utils::optional<double> &percentage = report.percentage(); percentage.has_value())
progress.futureInterface->setProgressValue(*percentage);
}
}