aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2020-04-25 20:34:38 +0100
committerJonas Schievink <[email protected]>2020-04-25 21:18:57 +0100
commit76d6f54471b5026ff228a58f10c69256a4b931bc (patch)
treed4f4b5abb1376471753242f2bf43d561e578b494 /crates/ra_ide/src
parent45832b990c7f291abe578dff3c460f4a1232f024 (diff)
Don't add call parens when an fn type is expected
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/completion/presentation.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs
index 7633cd7fd..1c516d312 100644
--- a/crates/ra_ide/src/completion/presentation.rs
+++ b/crates/ra_ide/src/completion/presentation.rs
@@ -349,6 +349,14 @@ impl Builder {
349 if ctx.use_item_syntax.is_some() || ctx.is_call { 349 if ctx.use_item_syntax.is_some() || ctx.is_call {
350 return self; 350 return self;
351 } 351 }
352
353 // Don't add parentheses if the expected type is some function reference.
354 if let Some(ty) = ctx.expected_type_of(&ctx.token.parent()) {
355 if ty.is_fn() {
356 return self;
357 }
358 }
359
352 let cap = match ctx.config.snippet_cap { 360 let cap = match ctx.config.snippet_cap {
353 Some(it) => it, 361 Some(it) => it,
354 None => return self, 362 None => return self,
@@ -749,6 +757,54 @@ mod tests {
749 } 757 }
750 758
751 #[test] 759 #[test]
760 fn no_call_parens_if_fn_ptr_needed() {
761 assert_debug_snapshot!(
762 do_reference_completion(
763 r"
764 fn somefn(with: u8, a: u8, lot: u8, of: u8, args: u8) {}
765
766 struct ManualVtable {
767 method: fn(u8, u8, u8, u8, u8),
768 }
769
770 fn main() -> ManualVtable {
771 ManualVtable {
772 method: some<|>
773 }
774 }
775 "
776 ),
777 @r###"
778 [
779 CompletionItem {
780 label: "ManualVtable",
781 source_range: 295..299,
782 delete: 295..299,
783 insert: "ManualVtable",
784 kind: Struct,
785 },
786 CompletionItem {
787 label: "main",
788 source_range: 295..299,
789 delete: 295..299,
790 insert: "main",
791 kind: Function,
792 detail: "fn main() -> ManualVtable",
793 },
794 CompletionItem {
795 label: "somefn",
796 source_range: 295..299,
797 delete: 295..299,
798 insert: "somefn",
799 kind: Function,
800 detail: "fn somefn(with: u8, a: u8, lot: u8, of: u8, args: u8)",
801 },
802 ]
803 "###
804 );
805 }
806
807 #[test]
752 fn arg_snippets_for_method_call() { 808 fn arg_snippets_for_method_call() {
753 assert_debug_snapshot!( 809 assert_debug_snapshot!(
754 do_reference_completion( 810 do_reference_completion(