aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-05-27 13:41:38 +0100
committerGitHub <[email protected]>2020-05-27 13:41:38 +0100
commit59adc7bfb6084e946afbea40351c3f6653c37174 (patch)
treedad3828436c3f8ee65bd2a2e18d04aa3a094d786
parent3c5112b079211640ed865ed1d26d8cd2f041c8c4 (diff)
parentfd83f469e9643c7a9da2d9e4c796bd89c441458d (diff)
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]>
-rw-r--r--crates/ra_ide/src/completion/presentation.rs60
1 files changed, 59 insertions, 1 deletions
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs
index 440ffa31d..61565c84f 100644
--- a/crates/ra_ide/src/completion/presentation.rs
+++ b/crates/ra_ide/src/completion/presentation.rs
@@ -211,7 +211,7 @@ impl Completions {
211 .parameter_names 211 .parameter_names
212 .iter() 212 .iter()
213 .skip(if function_signature.has_self_param { 1 } else { 0 }) 213 .skip(if function_signature.has_self_param { 1 } else { 0 })
214 .cloned() 214 .map(|name| name.trim_start_matches('_').into())
215 .collect(); 215 .collect();
216 216
217 builder = builder.add_call_parens(ctx, name, Params::Named(params)); 217 builder = builder.add_call_parens(ctx, name, Params::Named(params));
@@ -672,6 +672,37 @@ mod tests {
672 assert_debug_snapshot!( 672 assert_debug_snapshot!(
673 do_reference_completion( 673 do_reference_completion(
674 r" 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 );
703 assert_debug_snapshot!(
704 do_reference_completion(
705 r"
675 struct S {} 706 struct S {}
676 impl S { 707 impl S {
677 fn foo(&self) {} 708 fn foo(&self) {}
@@ -695,6 +726,33 @@ mod tests {
695 ] 726 ]
696 "### 727 "###
697 ); 728 );
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 );
698 } 756 }
699 757
700 #[test] 758 #[test]