Repository: rust-analyzer/rust-analyzer
Pull request #5312 (2020-07-11 10:57:06)

Make slow test parallel


bors r+
🤖


Patch:
diff --git a/Cargo.lock b/Cargo.lock
index e6c7da51f0..09909b60a8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1267,6 +1267,7 @@ dependencies = [
  "once_cell",
  "ra_parser",
  "ra_text_edit",
+ "rayon",
  "rowan",
  "rustc-ap-rustc_lexer",
  "rustc-hash",
diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml
index cb21b8053f..57cc09854b 100644
--- a/crates/ra_syntax/Cargo.toml
+++ b/crates/ra_syntax/Cargo.toml
@@ -33,3 +33,4 @@ serde = { version = "1.0.106", features = ["derive"] }
 test_utils = { path = "../test_utils" }
 expect = { path = "../expect" }
 walkdir = "2.3.1"
+rayon = "1"
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs
index 1b1e670c1b..b1b222deb8 100644
--- a/crates/rust-analyzer/src/diagnostics/to_proto.rs
+++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs
@@ -118,6 +118,7 @@ fn map_rust_child_diagnostic(
                 changes: Some(edit_map),
                 document_changes: None,
             }),
+            command: None,
         })
     }
 }
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index d39dceae04..8ce6e1c711 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -762,6 +762,7 @@ fn handle_fixes(
             group: None,
             kind: Some(lsp_types::code_action_kind::QUICKFIX.into()),
             edit: Some(edit),
+            command: None,
         };
         res.push(action);
     }
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs
index a3e12c046b..ba8a0231fa 100644
--- a/crates/rust-analyzer/src/lsp_ext.rs
+++ b/crates/rust-analyzer/src/lsp_ext.rs
@@ -249,9 +249,8 @@ pub struct CodeAction {
     pub group: Option<String>,
     #[serde(skip_serializing_if = "Option::is_none")]
     pub kind: Option<String>,
-    // We don't handle commands on the client-side
-    // #[serde(skip_serializing_if = "Option::is_none")]
-    // pub command: Option<lsp_types::Command>,
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub command: Option<lsp_types::Command>,
     #[serde(skip_serializing_if = "Option::is_none")]
     pub edit: Option<SnippetWorkspaceEdit>,
 }
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index f6dff16844..263f58a00e 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -651,6 +651,7 @@ pub(crate) fn unresolved_code_action(
         group: assist.group.filter(|_| snap.config.client_caps.code_action_group).map(|gr| gr.0),
         kind: Some(code_action_kind(assist.id.1)),
         edit: None,
+        command: None,
     };
     Ok(res)
 }


Test patch:
diff --git a/crates/ra_syntax/src/tests.rs b/crates/ra_syntax/src/tests.rs
index aa78735da6..8447dcad70 100644
--- a/crates/ra_syntax/src/tests.rs
+++ b/crates/ra_syntax/src/tests.rs
@@ -1,10 +1,11 @@
 use std::{
     fmt::Write,
     fs,
-    path::{Component, Path, PathBuf},
+    path::{Path, PathBuf},
 };
 
 use expect::expect_file;
+use rayon::prelude::*;
 use test_utils::project_dir;
 
 use crate::{fuzz, tokenize, SourceFile, SyntaxError, TextRange, TextSize, Token};
@@ -121,33 +122,43 @@ fn reparse_fuzz_tests() {
 /// FIXME: Use this as a benchmark
 #[test]
 fn self_hosting_parsing() {
-    use std::ffi::OsStr;
     let dir = project_dir().join("crates");
-    let mut count = 0;
-    for entry in walkdir::WalkDir::new(dir)
+    let files = walkdir::WalkDir::new(dir)
         .into_iter()
         .filter_entry(|entry| {
-            !entry.path().components().any(|component| {
-                // Get all files which are not in the crates/ra_syntax/test_data folder
-                component == Component::Normal(OsStr::new("test_data"))
-            })
+            // Get all files which are not in the crates/ra_syntax/test_data folder
+            !entry.path().components().any(|component| component.as_os_str() == "test_data")
         })
         .map(|e| e.unwrap())
         .filter(|entry| {
             // Get all `.rs ` files
-            !entry.path().is_dir() && (entry.path().extension() == Some(OsStr::new("rs")))
+            !entry.path().is_dir() && (entry.path().extension().unwrap_or_default() == "rs")
         })
-    {
-        count += 1;
-        let text = read_text(entry.path());
-        if let Err(errors) = SourceFile::parse(&text).ok() {
-            panic!("Parsing errors:\n{:?}\n{}\n", errors, entry.path().display());
-        }
-    }
+        .map(|entry| entry.into_path())
+        .collect::<Vec<_>>();
     assert!(
-        count > 30,
+        files.len() > 100,
         "self_hosting_parsing found too few files - is it running in the right directory?"
-    )
+    );
+
+    let errors = files
+        .into_par_iter()
+        .filter_map(|file| {
+            let text = read_text(&file);
+            match SourceFile::parse(&text).ok() {
+                Ok(_) => None,
+                Err(err) => Some((file, err)),
+            }
+        })
+        .collect::<Vec<_>>();
+
+    if !errors.is_empty() {
+        let errors = errors
+            .into_iter()
+            .map(|(path, err)| format!("{}: {:?}\n", path.display(), err))
+            .collect::<String>();
+        panic!("Parsing errors:\n{}\n", errors);
+    }
 }
 
 fn test_data_dir() -> PathBuf {
diff --git a/crates/rust-analyzer/test_data/rustc_unused_variable.txt b/crates/rust-analyzer/test_data/rustc_unused_variable.txt
index 92aea088b9..81f180a861 100644
--- a/crates/rust-analyzer/test_data/rustc_unused_variable.txt
+++ b/crates/rust-analyzer/test_data/rustc_unused_variable.txt
@@ -39,6 +39,7 @@
                 kind: Some(
                     "quickfix",
                 ),
+                command: None,
                 edit: Some(
                     SnippetWorkspaceEdit {
                         changes: Some(
diff --git a/crates/rust-analyzer/test_data/rustc_unused_variable_as_hint.txt b/crates/rust-analyzer/test_data/rustc_unused_variable_as_hint.txt
index 80cf0d8a54..d5d78fd800 100644
--- a/crates/rust-analyzer/test_data/rustc_unused_variable_as_hint.txt
+++ b/crates/rust-analyzer/test_data/rustc_unused_variable_as_hint.txt
@@ -39,6 +39,7 @@
                 kind: Some(
                     "quickfix",
                 ),
+                command: None,
                 edit: Some(
                     SnippetWorkspaceEdit {
                         changes: Some(
diff --git a/crates/rust-analyzer/test_data/rustc_unused_variable_as_info.txt b/crates/rust-analyzer/test_data/rustc_unused_variable_as_info.txt
index afe3cb6d8a..2a7505c59f 100644
--- a/crates/rust-analyzer/test_data/rustc_unused_variable_as_info.txt
+++ b/crates/rust-analyzer/test_data/rustc_unused_variable_as_info.txt
@@ -39,6 +39,7 @@
                 kind: Some(
                     "quickfix",
                 ),
+                command: None,
                 edit: Some(
                     SnippetWorkspaceEdit {
                         changes: Some(
diff --git a/crates/rust-analyzer/test_data/snap_multi_line_fix.txt b/crates/rust-analyzer/test_data/snap_multi_line_fix.txt
index 7814d35435..6eca3ae2f2 100644
--- a/crates/rust-analyzer/test_data/snap_multi_line_fix.txt
+++ b/crates/rust-analyzer/test_data/snap_multi_line_fix.txt
@@ -54,6 +54,7 @@
                 kind: Some(
                     "quickfix",
                 ),
+                command: None,
                 edit: Some(
                     SnippetWorkspaceEdit {
                         changes: Some(