aboutsummaryrefslogtreecommitdiff
path: root/crates/completion/src/render/function.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/completion/src/render/function.rs')
-rw-r--r--crates/completion/src/render/function.rs210
1 files changed, 210 insertions, 0 deletions
diff --git a/crates/completion/src/render/function.rs b/crates/completion/src/render/function.rs
index d22081236..cf3852bf6 100644
--- a/crates/completion/src/render/function.rs
+++ b/crates/completion/src/render/function.rs
@@ -81,3 +81,213 @@ impl<'a> FunctionRender<'a> {
81 } 81 }
82 } 82 }
83} 83}
84
85#[cfg(test)]
86mod tests {
87 use test_utils::mark;
88
89 use crate::{
90 test_utils::{check_edit, check_edit_with_config},
91 CompletionConfig,
92 };
93
94 #[test]
95 fn inserts_parens_for_function_calls() {
96 mark::check!(inserts_parens_for_function_calls);
97 check_edit(
98 "no_args",
99 r#"
100fn no_args() {}
101fn main() { no_<|> }
102"#,
103 r#"
104fn no_args() {}
105fn main() { no_args()$0 }
106"#,
107 );
108
109 check_edit(
110 "with_args",
111 r#"
112fn with_args(x: i32, y: String) {}
113fn main() { with_<|> }
114"#,
115 r#"
116fn with_args(x: i32, y: String) {}
117fn main() { with_args(${1:x}, ${2:y})$0 }
118"#,
119 );
120
121 check_edit(
122 "foo",
123 r#"
124struct S;
125impl S {
126 fn foo(&self) {}
127}
128fn bar(s: &S) { s.f<|> }
129"#,
130 r#"
131struct S;
132impl S {
133 fn foo(&self) {}
134}
135fn bar(s: &S) { s.foo()$0 }
136"#,
137 );
138
139 check_edit(
140 "foo",
141 r#"
142struct S {}
143impl S {
144 fn foo(&self, x: i32) {}
145}
146fn bar(s: &S) {
147 s.f<|>
148}
149"#,
150 r#"
151struct S {}
152impl S {
153 fn foo(&self, x: i32) {}
154}
155fn bar(s: &S) {
156 s.foo(${1:x})$0
157}
158"#,
159 );
160 }
161
162 #[test]
163 fn suppress_arg_snippets() {
164 mark::check!(suppress_arg_snippets);
165 check_edit_with_config(
166 CompletionConfig { add_call_argument_snippets: false, ..CompletionConfig::default() },
167 "with_args",
168 r#"
169fn with_args(x: i32, y: String) {}
170fn main() { with_<|> }
171"#,
172 r#"
173fn with_args(x: i32, y: String) {}
174fn main() { with_args($0) }
175"#,
176 );
177 }
178
179 #[test]
180 fn strips_underscores_from_args() {
181 check_edit(
182 "foo",
183 r#"
184fn foo(_foo: i32, ___bar: bool, ho_ge_: String) {}
185fn main() { f<|> }
186"#,
187 r#"
188fn foo(_foo: i32, ___bar: bool, ho_ge_: String) {}
189fn main() { foo(${1:foo}, ${2:bar}, ${3:ho_ge_})$0 }
190"#,
191 );
192 }
193
194 #[test]
195 fn insert_ref_when_matching_local_in_scope() {
196 check_edit(
197 "ref_arg",
198 r#"
199struct Foo {}
200fn ref_arg(x: &Foo) {}
201fn main() {
202 let x = Foo {};
203 ref_ar<|>
204}
205"#,
206 r#"
207struct Foo {}
208fn ref_arg(x: &Foo) {}
209fn main() {
210 let x = Foo {};
211 ref_arg(${1:&x})$0
212}
213"#,
214 );
215 }
216
217 #[test]
218 fn insert_mut_ref_when_matching_local_in_scope() {
219 check_edit(
220 "ref_arg",
221 r#"
222struct Foo {}
223fn ref_arg(x: &mut Foo) {}
224fn main() {
225 let x = Foo {};
226 ref_ar<|>
227}
228"#,
229 r#"
230struct Foo {}
231fn ref_arg(x: &mut Foo) {}
232fn main() {
233 let x = Foo {};
234 ref_arg(${1:&mut x})$0
235}
236"#,
237 );
238 }
239
240 #[test]
241 fn insert_ref_when_matching_local_in_scope_for_method() {
242 check_edit(
243 "apply_foo",
244 r#"
245struct Foo {}
246struct Bar {}
247impl Bar {
248 fn apply_foo(&self, x: &Foo) {}
249}
250
251fn main() {
252 let x = Foo {};
253 let y = Bar {};
254 y.<|>
255}
256"#,
257 r#"
258struct Foo {}
259struct Bar {}
260impl Bar {
261 fn apply_foo(&self, x: &Foo) {}
262}
263
264fn main() {
265 let x = Foo {};
266 let y = Bar {};
267 y.apply_foo(${1:&x})$0
268}
269"#,
270 );
271 }
272
273 #[test]
274 fn trim_mut_keyword_in_func_completion() {
275 check_edit(
276 "take_mutably",
277 r#"
278fn take_mutably(mut x: &i32) {}
279
280fn main() {
281 take_m<|>
282}
283"#,
284 r#"
285fn take_mutably(mut x: &i32) {}
286
287fn main() {
288 take_mutably(${1:x})$0
289}
290"#,
291 );
292 }
293}