aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/completion/complete_macro_in_item_position.rs135
-rw-r--r--crates/ra_ide/src/completion/presentation.rs54
2 files changed, 70 insertions, 119 deletions
diff --git a/crates/ra_ide/src/completion/complete_macro_in_item_position.rs b/crates/ra_ide/src/completion/complete_macro_in_item_position.rs
index 4c33f41d4..d6613ed7b 100644
--- a/crates/ra_ide/src/completion/complete_macro_in_item_position.rs
+++ b/crates/ra_ide/src/completion/complete_macro_in_item_position.rs
@@ -15,130 +15,27 @@ pub(super) fn complete_macro_in_item_position(acc: &mut Completions, ctx: &Compl
15 15
16#[cfg(test)] 16#[cfg(test)]
17mod tests { 17mod tests {
18 use insta::assert_debug_snapshot; 18 use expect::{expect, Expect};
19 19
20 use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; 20 use crate::completion::{test_utils::completion_list, CompletionKind};
21 21
22 fn do_reference_completion(code: &str) -> Vec<CompletionItem> { 22 fn check(ra_fixture: &str, expect: Expect) {
23 do_completion(code, CompletionKind::Reference) 23 let actual = completion_list(ra_fixture, CompletionKind::Reference);
24 expect.assert_eq(&actual)
24 } 25 }
25 26
26 #[test] 27 #[test]
27 fn completes_macros_as_item() { 28 fn completes_macros_as_item() {
28 assert_debug_snapshot!( 29 check(
29 do_reference_completion( 30 r#"
30 " 31macro_rules! foo { () => {} }
31 //- /main.rs 32fn foo() {}
32 macro_rules! foo { 33
33 () => {} 34<|>
34 } 35"#,
35 36 expect![[r#"
36 fn foo() {} 37 ma foo!(…) macro_rules! foo
37 38 "#]],
38 <|> 39 )
39 "
40 ),
41 @r###"
42 [
43 CompletionItem {
44 label: "foo!(…)",
45 source_range: 48..48,
46 delete: 48..48,
47 insert: "foo!($0)",
48 kind: Macro,
49 detail: "macro_rules! foo",
50 },
51 ]
52 "###
53 );
54 }
55
56 #[test]
57 fn completes_vec_macros_with_square_brackets() {
58 assert_debug_snapshot!(
59 do_reference_completion(
60 "
61 //- /main.rs
62 /// Creates a [`Vec`] containing the arguments.
63 ///
64 /// - Create a [`Vec`] containing a given list of elements:
65 ///
66 /// ```
67 /// let v = vec![1, 2, 3];
68 /// assert_eq!(v[0], 1);
69 /// assert_eq!(v[1], 2);
70 /// assert_eq!(v[2], 3);
71 /// ```
72 macro_rules! vec {
73 () => {}
74 }
75
76 fn foo() {}
77
78 <|>
79 "
80 ),
81 @r###"
82 [
83 CompletionItem {
84 label: "vec![…]",
85 source_range: 282..282,
86 delete: 282..282,
87 insert: "vec![$0]",
88 kind: Macro,
89 detail: "macro_rules! vec",
90 documentation: Documentation(
91 "Creates a [`Vec`] containing the arguments.\n\n- Create a [`Vec`] containing a given list of elements:\n\n```\nlet v = vec![1, 2, 3];\nassert_eq!(v[0], 1);\nassert_eq!(v[1], 2);\nassert_eq!(v[2], 3);\n```",
92 ),
93 },
94 ]
95 "###
96 );
97 }
98
99 #[test]
100 fn completes_macros_braces_guessing() {
101 assert_debug_snapshot!(
102 do_reference_completion(
103 "
104 //- /main.rs
105 /// Foo
106 ///
107 /// Not call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`.
108 /// Call as `let _=foo! { hello world };`
109 macro_rules! foo {
110 () => {}
111 }
112
113 fn main() {
114 <|>
115 }
116 "
117 ),
118 @r###"
119 [
120 CompletionItem {
121 label: "foo! {…}",
122 source_range: 164..164,
123 delete: 164..164,
124 insert: "foo! {$0}",
125 kind: Macro,
126 detail: "macro_rules! foo",
127 documentation: Documentation(
128 "Foo\n\nNot call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`.\nCall as `let _=foo! { hello world };`",
129 ),
130 },
131 CompletionItem {
132 label: "main()",
133 source_range: 164..164,
134 delete: 164..164,
135 insert: "main()$0",
136 kind: Function,
137 lookup: "main",
138 detail: "fn main()",
139 },
140 ]
141 "###
142 );
143 } 40 }
144} 41}
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs
index dc391c46b..946bbef7c 100644
--- a/crates/ra_ide/src/completion/presentation.rs
+++ b/crates/ra_ide/src/completion/presentation.rs
@@ -174,6 +174,7 @@ impl Completions {
174 builder 174 builder
175 .insert_snippet(cap, format!("{}!{}$0{}", name, bra, ket)) 175 .insert_snippet(cap, format!("{}!{}$0{}", name, bra, ket))
176 .label(format!("{}!{}…{}", name, bra, ket)) 176 .label(format!("{}!{}…{}", name, bra, ket))
177 .lookup_by(format!("{}!", name))
177 } 178 }
178 None if needs_bang => builder.insert_text(format!("{}!", name)), 179 None if needs_bang => builder.insert_text(format!("{}!", name)),
179 _ => { 180 _ => {
@@ -1079,4 +1080,57 @@ fn go(world: &WorldSnapshot) { go(w<|>) }
1079 "#]], 1080 "#]],
1080 ); 1081 );
1081 } 1082 }
1083
1084 #[test]
1085 fn guesses_macro_braces() {
1086 check_edit(
1087 "vec!",
1088 r#"
1089/// Creates a [`Vec`] containing the arguments.
1090///
1091/// ```
1092/// let v = vec![1, 2, 3];
1093/// assert_eq!(v[0], 1);
1094/// assert_eq!(v[1], 2);
1095/// assert_eq!(v[2], 3);
1096/// ```
1097macro_rules! vec { () => {} }
1098
1099fn fn main() { v<|> }
1100"#,
1101 r#"
1102/// Creates a [`Vec`] containing the arguments.
1103///
1104/// ```
1105/// let v = vec![1, 2, 3];
1106/// assert_eq!(v[0], 1);
1107/// assert_eq!(v[1], 2);
1108/// assert_eq!(v[2], 3);
1109/// ```
1110macro_rules! vec { () => {} }
1111
1112fn fn main() { vec![$0] }
1113"#,
1114 );
1115
1116 check_edit(
1117 "foo!",
1118 r#"
1119/// Foo
1120///
1121/// Don't call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`,
1122/// call as `let _=foo! { hello world };`
1123macro_rules! foo { () => {} }
1124fn main() { <|> }
1125"#,
1126 r#"
1127/// Foo
1128///
1129/// Don't call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`,
1130/// call as `let _=foo! { hello world };`
1131macro_rules! foo { () => {} }
1132fn main() { foo! {$0} }
1133"#,
1134 )
1135 }
1082} 1136}