Repository: rust-analyzer/rust-analyzer
Pull request #11153 (2022-01-01 16:55:36)

internal: add more prefix entry point tests
bors r+
🤖

bors[bot]: Build failed:
  * [Rust (ubuntu-latest)](https://github.com/rust-analyzer/rust-analyzer/runs/4680159820?check_suite_focus=true)

Patch:
diff --git a/crates/ide_assists/src/handlers/add_turbo_fish.rs b/crates/ide_assists/src/handlers/add_turbo_fish.rs
index b73942c3c5..64f9eb9586 100644
--- a/crates/ide_assists/src/handlers/add_turbo_fish.rs
+++ b/crates/ide_assists/src/handlers/add_turbo_fish.rs
@@ -1,5 +1,4 @@
 use ide_db::defs::{Definition, NameRefClass};
-use itertools::Itertools;
 use syntax::{ast, AstNode, SyntaxKind, T};
 
 use crate::{
@@ -78,22 +77,13 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<(
         }
     }
 
-    let number_of_arguments = generics.len();
-    let fish_head = std::iter::repeat("_").take(number_of_arguments).collect_vec().join(",");
-
     acc.add(
         AssistId("add_turbo_fish", AssistKind::RefactorRewrite),
         "Add `::<>`",
         ident.text_range(),
         |builder| match ctx.config.snippet_cap {
-            Some(cap) => {
-                let snip = format!("::<${{0:{}}}>", fish_head);
-                builder.insert_snippet(cap, ident.text_range().end(), snip)
-            }
-            None => {
-                let snip = format!("::<{}>", fish_head);
-                builder.insert(ident.text_range().end(), snip);
-            }
+            Some(cap) => builder.insert_snippet(cap, ident.text_range().end(), "::<${0:_}>"),
+            None => builder.insert(ident.text_range().end(), "::<_>"),
         },
     )
 }
@@ -123,44 +113,6 @@ fn main() {
         );
     }
 
-    #[test]
-    fn add_turbo_fish_function_multiple_generic_types() {
-        check_assist(
-            add_turbo_fish,
-            r#"
-fn make<T, A>() -> T {}
-fn main() {
-    make$0();
-}
-"#,
-            r#"
-fn make<T, A>() -> T {}
-fn main() {
-    make::<${0:_,_}>();
-}
-"#,
-        );
-    }
-
-    #[test]
-    fn add_turbo_fish_function_many_generic_types() {
-        check_assist(
-            add_turbo_fish,
-            r#"
-fn make<T, A, B, C, D, E, F>() -> T {}
-fn main() {
-    make$0();
-}
-"#,
-            r#"
-fn make<T, A, B, C, D, E, F>() -> T {}
-fn main() {
-    make::<${0:_,_,_,_,_,_,_}>();
-}
-"#,
-        );
-    }
-
     #[test]
     fn add_turbo_fish_after_call() {
         cov_mark::check!(add_turbo_fish_after_call);


Test patch:
diff --git a/crates/parser/src/tests/entries.rs b/crates/parser/src/tests/entries.rs
index 1174e33f5f..d52c6fbb16 100644
--- a/crates/parser/src/tests/entries.rs
+++ b/crates/parser/src/tests/entries.rs
@@ -59,10 +59,30 @@ fn path() {
     check_prefix(PrefixEntryPoint::Path, "foo::<> baz", "foo::<>");
     check_prefix(PrefixEntryPoint::Path, "foo<> baz", "foo<>");
     check_prefix(PrefixEntryPoint::Path, "Fn() -> i32?", "Fn() -> i32");
-    // FIXME: this shouldn't be accepted as path actually.
+    // FIXME: This shouldn't be accepted as path actually.
     check_prefix(PrefixEntryPoint::Path, "<_>::foo", "<_>::foo");
 }
 
+#[test]
+fn item() {
+    // FIXME: This shouldn't consume the semicolon.
+    check_prefix(PrefixEntryPoint::Item, "fn foo() {};", "fn foo() {};");
+    check_prefix(PrefixEntryPoint::Item, "#[attr] pub struct S {} 92", "#[attr] pub struct S {}");
+    check_prefix(PrefixEntryPoint::Item, "item!{}?", "item!{}");
+    check_prefix(PrefixEntryPoint::Item, "????", "?");
+}
+
+#[test]
+fn meta_item() {
+    check_prefix(PrefixEntryPoint::MetaItem, "attr, ", "attr");
+    check_prefix(
+        PrefixEntryPoint::MetaItem,
+        "attr(some token {stream});",
+        "attr(some token {stream})",
+    );
+    check_prefix(PrefixEntryPoint::MetaItem, "path::attr = 2 * 2!", "path::attr = 2 * 2");
+}
+
 fn check_prefix(entry: PrefixEntryPoint, input: &str, prefix: &str) {
     let lexed = LexedStr::new(input);
     let input = lexed.to_input();