Repository: rust-analyzer/rust-analyzer
Pull request #7752 (2021-02-22 13:32:19)

up once_cell


Patch:
diff --git a/Cargo.lock b/Cargo.lock
index 6139679fab..050c239703 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -58,7 +58,6 @@ name = "assists"
 version = "0.0.0"
 dependencies = [
  "either",
- "expect-test",
  "hir",
  "ide_db",
  "itertools 0.10.0",
@@ -1026,9 +1025,9 @@ checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4"
 
 [[package]]
 name = "once_cell"
-version = "1.5.2"
+version = "1.6.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0"
+checksum = "4ad167a2f54e832b82dbe003a046280dceffe5227b5f79e08e363a29638cfddd"
 
 [[package]]
 name = "oorandom"
diff --git a/crates/assists/Cargo.toml b/crates/assists/Cargo.toml
index c78cb99afe..ed8ad666f7 100644
--- a/crates/assists/Cargo.toml
+++ b/crates/assists/Cargo.toml
@@ -21,6 +21,3 @@ profile = { path = "../profile", version = "0.0.0" }
 ide_db = { path = "../ide_db", version = "0.0.0" }
 hir = { path = "../hir", version = "0.0.0" }
 test_utils = { path = "../test_utils", version = "0.0.0" }
-
-[dev-dependencies]
-expect-test = "1.1"
diff --git a/crates/assists/src/lib.rs b/crates/assists/src/lib.rs
index 7067cf8b69..957efa6b9c 100644
--- a/crates/assists/src/lib.rs
+++ b/crates/assists/src/lib.rs
@@ -179,7 +179,9 @@ mod handlers {
             early_return::convert_to_guarded_return,
             expand_glob_import::expand_glob_import,
             move_module_to_file::move_module_to_file,
+            extract_function::extract_function,
             extract_struct_from_enum_variant::extract_struct_from_enum_variant,
+            extract_variable::extract_variable,
             fill_match_arms::fill_match_arms,
             fix_visibility::fix_visibility,
             flip_binexpr::flip_binexpr,
@@ -227,18 +229,12 @@ mod handlers {
             unmerge_use::unmerge_use,
             unwrap_block::unwrap_block,
             wrap_return_type_in_result::wrap_return_type_in_result,
-            // These are manually sorted for better priorities. By default,
-            // priority is determined by the size of the target range (smaller
-            // target wins). If the ranges are equal, position in this list is
-            // used as a tie-breaker.
+            // These are manually sorted for better priorities
             add_missing_impl_members::add_missing_impl_members,
             add_missing_impl_members::add_missing_default_members,
             //
             replace_string_with_char::replace_string_with_char,
             raw_string::make_raw_string,
-            //
-            extract_variable::extract_variable,
-            extract_function::extract_function,
             // Are you sure you want to add new assist here, and not to the
             // sorted list above?
         ]
diff --git a/crates/base_db/src/fixture.rs b/crates/base_db/src/fixture.rs
index 5c9824814e..98acd61b12 100644
--- a/crates/base_db/src/fixture.rs
+++ b/crates/base_db/src/fixture.rs
@@ -67,7 +67,7 @@ use test_utils::{
 use vfs::{file_set::FileSet, VfsPath};
 
 use crate::{
-    input::CrateName, Change, CrateGraph, CrateId, Edition, Env, FileId, FilePosition, FileRange,
+    input::CrateName, Change, CrateGraph, CrateId, Edition, Env, FileId, FilePosition,
     SourceDatabaseExt, SourceRoot, SourceRootId,
 };
 
@@ -99,15 +99,6 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static {
         (db, FilePosition { file_id, offset })
     }
 
-    fn with_range(ra_fixture: &str) -> (Self, FileRange) {
-        let (db, file_id, range_or_offset) = Self::with_range_or_offset(ra_fixture);
-        let range = match range_or_offset {
-            RangeOrOffset::Range(it) => it,
-            RangeOrOffset::Offset(_) => panic!(),
-        };
-        (db, FileRange { file_id, range })
-    }
-
     fn with_range_or_offset(ra_fixture: &str) -> (Self, FileId, RangeOrOffset) {
         let fixture = ChangeFixture::parse(ra_fixture);
         let mut db = Self::default();


Test patch:
diff --git a/crates/assists/src/tests.rs b/crates/assists/src/tests.rs
index 384eb7eeea..720f561a17 100644
--- a/crates/assists/src/tests.rs
+++ b/crates/assists/src/tests.rs
@@ -1,6 +1,5 @@
 mod generated;
 
-use expect_test::expect;
 use hir::Semantics;
 use ide_db::{
     base_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt},
@@ -11,11 +10,11 @@ use ide_db::{
     source_change::FileSystemEdit,
     RootDatabase,
 };
-use stdx::{format_to, trim_indent};
 use syntax::TextRange;
-use test_utils::{assert_eq_text, extract_offset};
+use test_utils::{assert_eq_text, extract_offset, extract_range};
 
 use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, AssistKind, Assists};
+use stdx::{format_to, trim_indent};
 
 pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig {
     snippet_cap: SnippetCap::new(true),
@@ -164,22 +163,6 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label:
     };
 }
 
-fn labels(assists: &[Assist]) -> String {
-    let mut labels = assists
-        .iter()
-        .map(|assist| {
-            let mut label = match &assist.group {
-                Some(g) => g.0.clone(),
-                None => assist.label.to_string(),
-            };
-            label.push('\n');
-            label
-        })
-        .collect::<Vec<_>>();
-    labels.dedup();
-    labels.into_iter().collect::<String>()
-}
-
 #[test]
 fn assist_order_field_struct() {
     let before = "struct Foo { $0bar: u32 }";
@@ -198,78 +181,66 @@ fn assist_order_field_struct() {
 
 #[test]
 fn assist_order_if_expr() {
-    let (db, frange) = RootDatabase::with_range(
-        r#"
-pub fn test_some_range(a: int) -> bool {
-    if let 2..6 = $05$0 {
-        true
-    } else {
-        false
-    }
-}
-"#,
-    );
-
+    let before = "
+    pub fn test_some_range(a: int) -> bool {
+        if let 2..6 = $05$0 {
+            true
+        } else {
+            false
+        }
+    }";
+    let (range, before) = extract_range(before);
+    let (db, file_id) = with_single_file(&before);
+    let frange = FileRange { file_id, range };
     let assists = Assist::get(&db, &TEST_CONFIG, false, frange);
-    let expected = labels(&assists);
+    let mut assists = assists.iter();
 
-    expect![[r#"
-        Convert integer base
-        Extract into variable
-        Extract into function
-        Replace with match
-    "#]]
-    .assert_eq(&expected);
+    assert_eq!(assists.next().expect("expected assist").label, "Extract into function");
+    assert_eq!(assists.next().expect("expected assist").label, "Extract into variable");
+    assert_eq!(assists.next().expect("expected assist").label, "Replace with match");
 }
 
 #[test]
 fn assist_filter_works() {
-    let (db, frange) = RootDatabase::with_range(
-        r#"
-pub fn test_some_range(a: int) -> bool {
-    if let 2..6 = $05$0 {
-        true
-    } else {
-        false
-    }
-}
-"#,
-    );
+    let before = "
+    pub fn test_some_range(a: int) -> bool {
+        if let 2..6 = $05$0 {
+            true
+        } else {
+            false
+        }
+    }";
+    let (range, before) = extract_range(before);
+    let (db, file_id) = with_single_file(&before);
+    let frange = FileRange { file_id, range };
+
     {
         let mut cfg = TEST_CONFIG;
         cfg.allowed = Some(vec![AssistKind::Refactor]);
 
         let assists = Assist::get(&db, &cfg, false, frange);
-        let expected = labels(&assists);
+        let mut assists = assists.iter();
 
-        expect![[r#"
-            Convert integer base
-            Extract into variable
-            Extract into function
-            Replace with match
-        "#]]
-        .assert_eq(&expected);
+        assert_eq!(assists.next().expect("expected assist").label, "Extract into function");
+        assert_eq!(assists.next().expect("expected assist").label, "Extract into variable");
+        assert_eq!(assists.next().expect("expected assist").label, "Replace with match");
     }
 
     {
         let mut cfg = TEST_CONFIG;
         cfg.allowed = Some(vec![AssistKind::RefactorExtract]);
         let assists = Assist::get(&db, &cfg, false, frange);
-        let expected = labels(&assists);
+        assert_eq!(assists.len(), 2);
 
-        expect![[r#"
-            Extract into variable
-            Extract into function
-        "#]]
-        .assert_eq(&expected);
+        let mut assists = assists.iter();
+        assert_eq!(assists.next().expect("expected assist").label, "Extract into function");
+        assert_eq!(assists.next().expect("expected assist").label, "Extract into variable");
     }
 
     {
         let mut cfg = TEST_CONFIG;
         cfg.allowed = Some(vec![AssistKind::QuickFix]);
         let assists = Assist::get(&db, &cfg, false, frange);
-        let expected = labels(&assists);
-
-        expect![[r#""#]].assert_eq(&expected);
+        assert!(assists.is_empty(), "All asserts but quickfixes should be filtered out");
     }
 }