diff --git a/crates/ide_assists/src/handlers/add_turbo_fish.rs b/crates/ide_assists/src/handlers/add_turbo_fish.rs index 64f9eb9586..010a74f030 100644 --- a/crates/ide_assists/src/handlers/add_turbo_fish.rs +++ b/crates/ide_assists/src/handlers/add_turbo_fish.rs @@ -1,4 +1,5 @@ use ide_db::defs::{Definition, NameRefClass}; +use itertools::Itertools; use syntax::{ast, AstNode, SyntaxKind, T}; use crate::{ @@ -77,13 +78,22 @@ 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) => builder.insert_snippet(cap, ident.text_range().end(), "::<${0:_}>"), - None => builder.insert(ident.text_range().end(), "::<_>"), + 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); + }, }, ) } @@ -113,6 +123,44 @@ fn main() { ); } + #[test] + fn add_turbo_fish_function_multiple_generic_types() { + check_assist( + add_turbo_fish, + r#" +fn make() -> T {} +fn main() { + make$0(); +} +"#, + r#" +fn make() -> T {} +fn main() { + make::<${0:_,_}>(); +} +"#, + ); + } + + #[test] + fn add_turbo_fish_function_many_generic_types() { + check_assist( + add_turbo_fish, + r#" +fn make() -> T {} +fn main() { + make$0(); +} +"#, + r#" +fn make() -> T {} +fn main() { + make::<${0:_,_,_,_,_,_,_}>(); +} +"#, + ); + } + #[test] fn add_turbo_fish_after_call() { cov_mark::check!(add_turbo_fish_after_call);