Skip to content

Commit 59adc7b

Browse files
bors[bot]kuy
andauthored
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 ![Screen Shot 2020-05-25 at 0 03 21](https://user-images.githubusercontent.com/151614/82757771-a05e5b80-9e1d-11ea-9dbc-1263c960e2ae.png) Co-authored-by: Yuki Kodama <[email protected]>
2 parents 3c5112b + fd83f46 commit 59adc7b

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

crates/ra_ide/src/completion/presentation.rs

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl Completions {
211211
.parameter_names
212212
.iter()
213213
.skip(if function_signature.has_self_param { 1 } else { 0 })
214-
.cloned()
214+
.map(|name| name.trim_start_matches('_').into())
215215
.collect();
216216

217217
builder = builder.add_call_parens(ctx, name, Params::Named(params));
@@ -669,6 +669,37 @@ mod tests {
669669
]
670670
"###
671671
);
672+
assert_debug_snapshot!(
673+
do_reference_completion(
674+
r"
675+
fn with_ignored_args(_foo: i32, ___bar: bool, ho_ge_: String) {}
676+
fn main() { with_<|> }
677+
"
678+
),
679+
@r###"
680+
[
681+
CompletionItem {
682+
label: "main()",
683+
source_range: 110..115,
684+
delete: 110..115,
685+
insert: "main()$0",
686+
kind: Function,
687+
lookup: "main",
688+
detail: "fn main()",
689+
},
690+
CompletionItem {
691+
label: "with_ignored_args(…)",
692+
source_range: 110..115,
693+
delete: 110..115,
694+
insert: "with_ignored_args(${1:foo}, ${2:bar}, ${3:ho_ge_})$0",
695+
kind: Function,
696+
lookup: "with_ignored_args",
697+
detail: "fn with_ignored_args(_foo: i32, ___bar: bool, ho_ge_: String)",
698+
trigger_call_info: true,
699+
},
700+
]
701+
"###
702+
);
672703
assert_debug_snapshot!(
673704
do_reference_completion(
674705
r"
@@ -695,6 +726,33 @@ mod tests {
695726
]
696727
"###
697728
);
729+
assert_debug_snapshot!(
730+
do_reference_completion(
731+
r"
732+
struct S {}
733+
impl S {
734+
fn foo_ignored_args(&self, _a: bool, b: i32) {}
735+
}
736+
fn bar(s: &S) {
737+
s.f<|>
738+
}
739+
"
740+
),
741+
@r###"
742+
[
743+
CompletionItem {
744+
label: "foo_ignored_args(…)",
745+
source_range: 194..195,
746+
delete: 194..195,
747+
insert: "foo_ignored_args(${1:a}, ${2:b})$0",
748+
kind: Method,
749+
lookup: "foo_ignored_args",
750+
detail: "fn foo_ignored_args(&self, _a: bool, b: i32)",
751+
trigger_call_info: true,
752+
},
753+
]
754+
"###
755+
);
698756
}
699757

700758
#[test]

0 commit comments

Comments
 (0)