about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-10-07 10:17:14 +0000
committerGitHub <noreply@github.com>2020-10-07 10:17:14 +0000
commit2aa46034c2eeb3d994b2760878ac1969487542e3 (patch)
tree702b1a779d511b9e353b2f8923d5f016f9465c48
parent67c76c35a3d047bc5eb21b2d1d77dd3ab0e4bd85 (diff)
parent6219142c96708d8068bcf9eb2a6424882d74094c (diff)
downloadrust-2aa46034c2eeb3d994b2760878ac1969487542e3.tar.gz
rust-2aa46034c2eeb3d994b2760878ac1969487542e3.zip
Merge #6166
6166: Better progress API r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
-rw-r--r--crates/rust-analyzer/src/lsp_utils.rs11
-rw-r--r--crates/rust-analyzer/src/main_loop.rs2
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 85c66157148..bd888f63478 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 {
 }
 
 impl Progress {
-    pub(crate) fn percentage(done: usize, total: usize) -> f64 {
-        (done as f64 / total.max(1) as f64) * 100.0
+    pub(crate) fn fraction(done: usize, total: usize) -> f64 {
+        assert!(done <= total);
+        done as f64 / total.max(1) as f64
     }
 }
 
@@ -43,11 +44,15 @@ impl GlobalState {
         title: &str,
         state: Progress,
         message: Option<String>,
-        percentage: Option<f64>,
+        fraction: Option<f64>,
     ) {
         if !self.config.client_caps.work_done_progress {
             return;
         }
+        let percentage = fraction.map(|f| {
+            assert!(0.0 <= f && f <= 1.0);
+            f * 100.0
+        });
         let token = lsp_types::ProgressToken::String(format!("rustAnalyzer/{}", title));
         let work_done_progress = match state {
             Progress::Begin => {
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index c2d0ac791bf..4b7ac8224ef 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -230,7 +230,7 @@ impl GlobalState {
                                     "roots scanned",
                                     state,
                                     Some(format!("{}/{}", n_done, n_total)),
-                                    Some(Progress::percentage(n_done, n_total)),
+                                    Some(Progress::fraction(n_done, n_total)),
                                 )
                             }
                         }