diff options
Diffstat (limited to 'crates/ra_assists/src/handlers/add_turbo_fish.rs')
-rw-r--r-- | crates/ra_assists/src/handlers/add_turbo_fish.rs | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/crates/ra_assists/src/handlers/add_turbo_fish.rs b/crates/ra_assists/src/handlers/add_turbo_fish.rs index 26acf81f2..0c565e89a 100644 --- a/crates/ra_assists/src/handlers/add_turbo_fish.rs +++ b/crates/ra_assists/src/handlers/add_turbo_fish.rs | |||
@@ -4,7 +4,7 @@ use test_utils::mark; | |||
4 | 4 | ||
5 | use crate::{ | 5 | use crate::{ |
6 | assist_context::{AssistContext, Assists}, | 6 | assist_context::{AssistContext, Assists}, |
7 | AssistId, | 7 | AssistId, AssistKind, |
8 | }; | 8 | }; |
9 | 9 | ||
10 | // Assist: add_turbo_fish | 10 | // Assist: add_turbo_fish |
@@ -25,7 +25,14 @@ use crate::{ | |||
25 | // } | 25 | // } |
26 | // ``` | 26 | // ``` |
27 | pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | 27 | pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { |
28 | let ident = ctx.find_token_at_offset(SyntaxKind::IDENT)?; | 28 | let ident = ctx.find_token_at_offset(SyntaxKind::IDENT).or_else(|| { |
29 | let arg_list = ctx.find_node_at_offset::<ast::ArgList>()?; | ||
30 | if arg_list.args().count() > 0 { | ||
31 | return None; | ||
32 | } | ||
33 | mark::hit!(add_turbo_fish_after_call); | ||
34 | arg_list.l_paren_token()?.prev_token().filter(|it| it.kind() == SyntaxKind::IDENT) | ||
35 | })?; | ||
29 | let next_token = ident.next_token()?; | 36 | let next_token = ident.next_token()?; |
30 | if next_token.kind() == T![::] { | 37 | if next_token.kind() == T![::] { |
31 | mark::hit!(add_turbo_fish_one_fish_is_enough); | 38 | mark::hit!(add_turbo_fish_one_fish_is_enough); |
@@ -45,12 +52,15 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<( | |||
45 | mark::hit!(add_turbo_fish_non_generic); | 52 | mark::hit!(add_turbo_fish_non_generic); |
46 | return None; | 53 | return None; |
47 | } | 54 | } |
48 | acc.add(AssistId("add_turbo_fish"), "Add `::<>`", ident.text_range(), |builder| { | 55 | acc.add( |
49 | match ctx.config.snippet_cap { | 56 | AssistId("add_turbo_fish", AssistKind::RefactorRewrite), |
57 | "Add `::<>`", | ||
58 | ident.text_range(), | ||
59 | |builder| match ctx.config.snippet_cap { | ||
50 | Some(cap) => builder.insert_snippet(cap, ident.text_range().end(), "::<${0:_}>"), | 60 | Some(cap) => builder.insert_snippet(cap, ident.text_range().end(), "::<${0:_}>"), |
51 | None => builder.insert(ident.text_range().end(), "::<_>"), | 61 | None => builder.insert(ident.text_range().end(), "::<_>"), |
52 | } | 62 | }, |
53 | }) | 63 | ) |
54 | } | 64 | } |
55 | 65 | ||
56 | #[cfg(test)] | 66 | #[cfg(test)] |
@@ -80,6 +90,26 @@ fn main() { | |||
80 | } | 90 | } |
81 | 91 | ||
82 | #[test] | 92 | #[test] |
93 | fn add_turbo_fish_after_call() { | ||
94 | mark::check!(add_turbo_fish_after_call); | ||
95 | check_assist( | ||
96 | add_turbo_fish, | ||
97 | r#" | ||
98 | fn make<T>() -> T {} | ||
99 | fn main() { | ||
100 | make()<|>; | ||
101 | } | ||
102 | "#, | ||
103 | r#" | ||
104 | fn make<T>() -> T {} | ||
105 | fn main() { | ||
106 | make::<${0:_}>(); | ||
107 | } | ||
108 | "#, | ||
109 | ); | ||
110 | } | ||
111 | |||
112 | #[test] | ||
83 | fn add_turbo_fish_method() { | 113 | fn add_turbo_fish_method() { |
84 | check_assist( | 114 | check_assist( |
85 | add_turbo_fish, | 115 | add_turbo_fish, |