Skip to content

Commit 2aa4603

Browse files
bors[bot]matklad
andauthored
Merge #6166
6166: Better progress API r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 67c76c3 + 6219142 commit 2aa4603

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

crates/rust-analyzer/src/lsp_utils.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ pub(crate) enum Progress {
2525
}
2626

2727
impl Progress {
28-
pub(crate) fn percentage(done: usize, total: usize) -> f64 {
29-
(done as f64 / total.max(1) as f64) * 100.0
28+
pub(crate) fn fraction(done: usize, total: usize) -> f64 {
29+
assert!(done <= total);
30+
done as f64 / total.max(1) as f64
3031
}
3132
}
3233

@@ -43,11 +44,15 @@ impl GlobalState {
4344
title: &str,
4445
state: Progress,
4546
message: Option<String>,
46-
percentage: Option<f64>,
47+
fraction: Option<f64>,
4748
) {
4849
if !self.config.client_caps.work_done_progress {
4950
return;
5051
}
52+
let percentage = fraction.map(|f| {
53+
assert!(0.0 <= f && f <= 1.0);
54+
f * 100.0
55+
});
5156
let token = lsp_types::ProgressToken::String(format!("rustAnalyzer/{}", title));
5257
let work_done_progress = match state {
5358
Progress::Begin => {

crates/rust-analyzer/src/main_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl GlobalState {
230230
"roots scanned",
231231
state,
232232
Some(format!("{}/{}", n_done, n_total)),
233-
Some(Progress::percentage(n_done, n_total)),
233+
Some(Progress::fraction(n_done, n_total)),
234234
)
235235
}
236236
}

0 commit comments

Comments
 (0)