From a28aa175d43d9f2db3e18cc83005601cf8a26c8d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 18 Jul 2020 14:48:28 +0200 Subject: Add turbo-fish works after `()` --- crates/ra_assists/src/handlers/add_turbo_fish.rs | 29 +++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'crates/ra_assists') diff --git a/crates/ra_assists/src/handlers/add_turbo_fish.rs b/crates/ra_assists/src/handlers/add_turbo_fish.rs index f7e1a7b05..0c565e89a 100644 --- a/crates/ra_assists/src/handlers/add_turbo_fish.rs +++ b/crates/ra_assists/src/handlers/add_turbo_fish.rs @@ -25,7 +25,14 @@ use crate::{ // } // ``` pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { - let ident = ctx.find_token_at_offset(SyntaxKind::IDENT)?; + let ident = ctx.find_token_at_offset(SyntaxKind::IDENT).or_else(|| { + let arg_list = ctx.find_node_at_offset::()?; + if arg_list.args().count() > 0 { + return None; + } + mark::hit!(add_turbo_fish_after_call); + arg_list.l_paren_token()?.prev_token().filter(|it| it.kind() == SyntaxKind::IDENT) + })?; let next_token = ident.next_token()?; if next_token.kind() == T![::] { mark::hit!(add_turbo_fish_one_fish_is_enough); @@ -82,6 +89,26 @@ fn main() { ); } + #[test] + fn add_turbo_fish_after_call() { + mark::check!(add_turbo_fish_after_call); + check_assist( + add_turbo_fish, + r#" +fn make() -> T {} +fn main() { + make()<|>; +} +"#, + r#" +fn make() -> T {} +fn main() { + make::<${0:_}>(); +} +"#, + ); + } + #[test] fn add_turbo_fish_method() { check_assist( -- cgit v1.2.3