succinct code

This commit is contained in:
Jeroen Vannevel 2022-01-07 13:53:42 +00:00
parent 4bcdb05325
commit 0a240e31c5
No known key found for this signature in database
GPG key ID: 78EF5F52F38C49BD

View file

@ -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);
}
"#,
);