mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Merge #5430
5430: Add turbo-fish works after `()` r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
059c0b8f7a
1 changed files with 28 additions and 1 deletions
|
@ -25,7 +25,14 @@ use crate::{
|
||||||
// }
|
// }
|
||||||
// ```
|
// ```
|
||||||
pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
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::<ast::ArgList>()?;
|
||||||
|
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()?;
|
let next_token = ident.next_token()?;
|
||||||
if next_token.kind() == T![::] {
|
if next_token.kind() == T![::] {
|
||||||
mark::hit!(add_turbo_fish_one_fish_is_enough);
|
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>() -> T {}
|
||||||
|
fn main() {
|
||||||
|
make()<|>;
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
fn make<T>() -> T {}
|
||||||
|
fn main() {
|
||||||
|
make::<${0:_}>();
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add_turbo_fish_method() {
|
fn add_turbo_fish_method() {
|
||||||
check_assist(
|
check_assist(
|
||||||
|
|
Loading…
Reference in a new issue