diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/src/lsp_utils.rs | 11 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 2 |
2 files changed, 9 insertions, 4 deletions
diff --git a/crates/rust-analyzer/src/lsp_utils.rs b/crates/rust-analyzer/src/lsp_utils.rs index 85c661571..bd888f634 100644 --- a/crates/rust-analyzer/src/lsp_utils.rs +++ b/crates/rust-analyzer/src/lsp_utils.rs | |||
@@ -25,8 +25,9 @@ pub(crate) enum Progress { | |||
25 | } | 25 | } |
26 | 26 | ||
27 | impl Progress { | 27 | impl Progress { |
28 | pub(crate) fn percentage(done: usize, total: usize) -> f64 { | 28 | pub(crate) fn fraction(done: usize, total: usize) -> f64 { |
29 | (done as f64 / total.max(1) as f64) * 100.0 | 29 | assert!(done <= total); |
30 | done as f64 / total.max(1) as f64 | ||
30 | } | 31 | } |
31 | } | 32 | } |
32 | 33 | ||
@@ -43,11 +44,15 @@ impl GlobalState { | |||
43 | title: &str, | 44 | title: &str, |
44 | state: Progress, | 45 | state: Progress, |
45 | message: Option<String>, | 46 | message: Option<String>, |
46 | percentage: Option<f64>, | 47 | fraction: Option<f64>, |
47 | ) { | 48 | ) { |
48 | if !self.config.client_caps.work_done_progress { | 49 | if !self.config.client_caps.work_done_progress { |
49 | return; | 50 | return; |
50 | } | 51 | } |
52 | let percentage = fraction.map(|f| { | ||
53 | assert!(0.0 <= f && f <= 1.0); | ||
54 | f * 100.0 | ||
55 | }); | ||
51 | let token = lsp_types::ProgressToken::String(format!("rustAnalyzer/{}", title)); | 56 | let token = lsp_types::ProgressToken::String(format!("rustAnalyzer/{}", title)); |
52 | let work_done_progress = match state { | 57 | let work_done_progress = match state { |
53 | Progress::Begin => { | 58 | Progress::Begin => { |
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index c2d0ac791..4b7ac8224 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -230,7 +230,7 @@ impl GlobalState { | |||
230 | "roots scanned", | 230 | "roots scanned", |
231 | state, | 231 | state, |
232 | Some(format!("{}/{}", n_done, n_total)), | 232 | Some(format!("{}/{}", n_done, n_total)), |
233 | Some(Progress::percentage(n_done, n_total)), | 233 | Some(Progress::fraction(n_done, n_total)), |
234 | ) | 234 | ) |
235 | } | 235 | } |
236 | } | 236 | } |