Merge #4596
4596: Strip leading underscores of argument names in function/method r=matklad a=kuy Closes #4510 ### Goal When I select a function/method from completions, I get a snippet that doesn't contain leading underscores of argument names. ### Solution - Option 1: All signatures don't contain underscores - Option 2: Keep same signature, but inserted snippet doesn't contain underscores I choose Option 2 because I think that leading underscores is a part of "signature". Users should get correct signatures. On the other hand, trimming underscores is an assist by IDE. ### Other impls. rls: Complete argument names with underscores (same as actual ra) IntelliJ Rust: Doesn't complete argument names VSCode (TypeScript): Doesn't complete argument names ### Working example  Co-authored-by: Yuki Kodama <endflow.net@gmail.com>
This commit is contained in:
commit
59adc7bfb6
@ -211,7 +211,7 @@ impl Completions {
|
||||
.parameter_names
|
||||
.iter()
|
||||
.skip(if function_signature.has_self_param { 1 } else { 0 })
|
||||
.cloned()
|
||||
.map(|name| name.trim_start_matches('_').into())
|
||||
.collect();
|
||||
|
||||
builder = builder.add_call_parens(ctx, name, Params::Named(params));
|
||||
@ -669,6 +669,37 @@ mod tests {
|
||||
]
|
||||
"###
|
||||
);
|
||||
assert_debug_snapshot!(
|
||||
do_reference_completion(
|
||||
r"
|
||||
fn with_ignored_args(_foo: i32, ___bar: bool, ho_ge_: String) {}
|
||||
fn main() { with_<|> }
|
||||
"
|
||||
),
|
||||
@r###"
|
||||
[
|
||||
CompletionItem {
|
||||
label: "main()",
|
||||
source_range: 110..115,
|
||||
delete: 110..115,
|
||||
insert: "main()$0",
|
||||
kind: Function,
|
||||
lookup: "main",
|
||||
detail: "fn main()",
|
||||
},
|
||||
CompletionItem {
|
||||
label: "with_ignored_args(…)",
|
||||
source_range: 110..115,
|
||||
delete: 110..115,
|
||||
insert: "with_ignored_args(${1:foo}, ${2:bar}, ${3:ho_ge_})$0",
|
||||
kind: Function,
|
||||
lookup: "with_ignored_args",
|
||||
detail: "fn with_ignored_args(_foo: i32, ___bar: bool, ho_ge_: String)",
|
||||
trigger_call_info: true,
|
||||
},
|
||||
]
|
||||
"###
|
||||
);
|
||||
assert_debug_snapshot!(
|
||||
do_reference_completion(
|
||||
r"
|
||||
@ -695,6 +726,33 @@ mod tests {
|
||||
]
|
||||
"###
|
||||
);
|
||||
assert_debug_snapshot!(
|
||||
do_reference_completion(
|
||||
r"
|
||||
struct S {}
|
||||
impl S {
|
||||
fn foo_ignored_args(&self, _a: bool, b: i32) {}
|
||||
}
|
||||
fn bar(s: &S) {
|
||||
s.f<|>
|
||||
}
|
||||
"
|
||||
),
|
||||
@r###"
|
||||
[
|
||||
CompletionItem {
|
||||
label: "foo_ignored_args(…)",
|
||||
source_range: 194..195,
|
||||
delete: 194..195,
|
||||
insert: "foo_ignored_args(${1:a}, ${2:b})$0",
|
||||
kind: Method,
|
||||
lookup: "foo_ignored_args",
|
||||
detail: "fn foo_ignored_args(&self, _a: bool, b: i32)",
|
||||
trigger_call_info: true,
|
||||
},
|
||||
]
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user