mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 01:17:27 +00:00
succinct code
This commit is contained in:
parent
4bcdb05325
commit
0a240e31c5
1 changed files with 9 additions and 12 deletions
|
@ -1,4 +1,5 @@
|
|||
use ide_db::defs::{Definition, NameRefClass};
|
||||
use itertools::Itertools;
|
||||
use syntax::{ast, AstNode, SyntaxKind, T};
|
||||
|
||||
use crate::{
|
||||
|
@ -94,8 +95,7 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<(
|
|||
builder.insert_snippet(cap, ident.text_range().end(), snip)
|
||||
}
|
||||
None => {
|
||||
let fish_head =
|
||||
std::iter::repeat("_").take(number_of_arguments).collect::<Vec<_>>().join(", ");
|
||||
let fish_head = std::iter::repeat("_").take(number_of_arguments).format(", ");
|
||||
let snip = format!("::<{}>", fish_head);
|
||||
builder.insert(ident.text_range().end(), snip);
|
||||
}
|
||||
|
@ -105,12 +105,9 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<(
|
|||
|
||||
/// This will create a snippet string with tabstops marked
|
||||
fn get_snippet_fish_head(number_of_arguments: usize) -> String {
|
||||
let mut fish_head = String::new();
|
||||
let mut i = 1;
|
||||
while i < number_of_arguments {
|
||||
fish_head.push_str(&format!("${{{}:_}},", i));
|
||||
i = i + 1;
|
||||
}
|
||||
let mut fish_head = (1..number_of_arguments)
|
||||
.format_with("", |i, f| f(&format_args!("${{{}:_}}, ", i)))
|
||||
.to_string();
|
||||
|
||||
// tabstop 0 is a special case and always the last one
|
||||
fish_head.push_str("${0:_}");
|
||||
|
@ -155,7 +152,7 @@ fn main() {
|
|||
r#"
|
||||
fn make<T, A>() -> T {}
|
||||
fn main() {
|
||||
make::<${1:_},${0:_}>();
|
||||
make::<${1:_}, ${0:_}>();
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
@ -174,7 +171,7 @@ fn main() {
|
|||
r#"
|
||||
fn make<T, A, B, C, D, E, F>() -> T {}
|
||||
fn main() {
|
||||
make::<${1:_},${2:_},${3:_},${4:_},${5:_},${6:_},${0:_}>();
|
||||
make::<${1:_}, ${2:_}, ${3:_}, ${4:_}, ${5:_}, ${6:_}, ${0:_}>();
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
@ -373,7 +370,7 @@ fn main() {
|
|||
r#"
|
||||
fn make<'a, T, A>(t: T, a: A) {}
|
||||
fn main() {
|
||||
make::<${1:_},${0:_}>(5, 2);
|
||||
make::<${1:_}, ${0:_}>(5, 2);
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
@ -392,7 +389,7 @@ fn main() {
|
|||
r#"
|
||||
fn make<T, const N: usize>(t: T) {}
|
||||
fn main() {
|
||||
make::<${1:_},${0:_}>(3);
|
||||
make::<${1:_}, ${0:_}>(3);
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue