aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_api/src/completion/presentation.rs209
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call.snap24
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call_assoc_fn.snap16
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_in_use_item.snap16
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls1.snap24
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls2.snap24
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls3.snap16
7 files changed, 152 insertions, 177 deletions
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs
index 5cf55a496..fe7581adf 100644
--- a/crates/ra_ide_api/src/completion/presentation.rs
+++ b/crates/ra_ide_api/src/completion/presentation.rs
@@ -183,79 +183,174 @@ impl Completions {
183#[cfg(test)] 183#[cfg(test)]
184mod tests { 184mod tests {
185 use test_utils::covers; 185 use test_utils::covers;
186 use crate::completion::{do_completion, CompletionItem, CompletionKind};
187 use insta::assert_debug_snapshot_matches;
186 188
187 use crate::completion::{check_completion, CompletionKind}; 189 fn do_reference_completion(code: &str) -> Vec<CompletionItem> {
188 190 do_completion(code, CompletionKind::Reference)
189 fn check_reference_completion(code: &str, expected_completions: &str) {
190 check_completion(code, expected_completions, CompletionKind::Reference);
191 } 191 }
192 192
193 #[test] 193 #[test]
194 fn inserts_parens_for_function_calls() { 194 fn inserts_parens_for_function_calls() {
195 covers!(inserts_parens_for_function_calls); 195 covers!(inserts_parens_for_function_calls);
196 check_reference_completion( 196 assert_debug_snapshot_matches!(
197 "inserts_parens_for_function_calls1", 197 do_reference_completion(
198 r" 198 r"
199 fn no_args() {} 199 fn no_args() {}
200 fn main() { no_<|> } 200 fn main() { no_<|> }
201 ", 201 "
202 ),
203@r###"
204 ⋮[
205 ⋮ CompletionItem {
206 ⋮ label: "main",
207 ⋮ source_range: [61; 64),
208 ⋮ delete: [61; 64),
209 ⋮ insert: "main()$0",
210 ⋮ kind: Function,
211 ⋮ detail: "fn main()",
212 ⋮ },
213 ⋮ CompletionItem {
214 ⋮ label: "no_args",
215 ⋮ source_range: [61; 64),
216 ⋮ delete: [61; 64),
217 ⋮ insert: "no_args()$0",
218 ⋮ kind: Function,
219 ⋮ detail: "fn no_args()",
220 ⋮ },
221 ⋮]
222 "###
202 ); 223 );
203 check_reference_completion( 224 assert_debug_snapshot_matches!(
204 "inserts_parens_for_function_calls2", 225 do_reference_completion(
205 r" 226 r"
206 fn with_args(x: i32, y: String) {} 227 fn with_args(x: i32, y: String) {}
207 fn main() { with_<|> } 228 fn main() { with_<|> }
208 ", 229 "
230 ),
231@r###"
232 ⋮[
233 ⋮ CompletionItem {
234 ⋮ label: "main",
235 ⋮ source_range: [80; 85),
236 ⋮ delete: [80; 85),
237 ⋮ insert: "main()$0",
238 ⋮ kind: Function,
239 ⋮ detail: "fn main()",
240 ⋮ },
241 ⋮ CompletionItem {
242 ⋮ label: "with_args",
243 ⋮ source_range: [80; 85),
244 ⋮ delete: [80; 85),
245 ⋮ insert: "with_args($0)",
246 ⋮ kind: Function,
247 ⋮ detail: "fn with_args(x: i32, y: String)",
248 ⋮ },
249 ⋮]
250 "###
251 );
252 assert_debug_snapshot_matches!(
253 do_reference_completion(
254 r"
255 struct S {}
256 impl S {
257 fn foo(&self) {}
258 }
259 fn bar(s: &S) {
260 s.f<|>
261 }
262 "
263 ),
264@r###"
265 ⋮[
266 ⋮ CompletionItem {
267 ⋮ label: "foo",
268 ⋮ source_range: [163; 164),
269 ⋮ delete: [163; 164),
270 ⋮ insert: "foo()$0",
271 ⋮ kind: Method,
272 ⋮ detail: "fn foo(&self)",
273 ⋮ },
274 ⋮]
275 "###
209 ); 276 );
210 check_reference_completion(
211 "inserts_parens_for_function_calls3",
212 r"
213 struct S {}
214 impl S {
215 fn foo(&self) {}
216 }
217 fn bar(s: &S) {
218 s.f<|>
219 }
220 ",
221 )
222 } 277 }
223 278
224 #[test] 279 #[test]
225 fn dont_render_function_parens_in_use_item() { 280 fn dont_render_function_parens_in_use_item() {
226 check_reference_completion( 281 assert_debug_snapshot_matches!(
227 "dont_render_function_parens_in_use_item", 282 do_reference_completion(
228 " 283 "
229 //- /lib.rs 284 //- /lib.rs
230 mod m { pub fn foo() {} } 285 mod m { pub fn foo() {} }
231 use crate::m::f<|>; 286 use crate::m::f<|>;
232 ", 287 "
233 ) 288 ),
289@r#"[
290 CompletionItem {
291 label: "foo",
292 source_range: [40; 41),
293 delete: [40; 41),
294 insert: "foo",
295 kind: Function,
296 detail: "pub fn foo()",
297 },
298]"#
299 );
234 } 300 }
235 301
236 #[test] 302 #[test]
237 fn dont_render_function_parens_if_already_call() { 303 fn dont_render_function_parens_if_already_call() {
238 check_reference_completion( 304 assert_debug_snapshot_matches!(
239 "dont_render_function_parens_if_already_call", 305 do_reference_completion(
240 " 306 "
241 //- /lib.rs 307 //- /lib.rs
242 fn frobnicate() {} 308 fn frobnicate() {}
243 fn main() { 309 fn main() {
244 frob<|>(); 310 frob<|>();
245 } 311 }
246 ", 312 "
313 ),
314@r#"[
315 CompletionItem {
316 label: "frobnicate",
317 source_range: [35; 39),
318 delete: [35; 39),
319 insert: "frobnicate",
320 kind: Function,
321 detail: "fn frobnicate()",
322 },
323 CompletionItem {
324 label: "main",
325 source_range: [35; 39),
326 delete: [35; 39),
327 insert: "main",
328 kind: Function,
329 detail: "fn main()",
330 },
331]"#
332 );
333 assert_debug_snapshot_matches!(
334 do_reference_completion(
335 "
336 //- /lib.rs
337 struct Foo {}
338 impl Foo { fn new() -> Foo {} }
339 fn main() {
340 Foo::ne<|>();
341 }
342 "
343 ),
344@r#"[
345 CompletionItem {
346 label: "new",
347 source_range: [67; 69),
348 delete: [67; 69),
349 insert: "new",
350 kind: Function,
351 detail: "fn new() -> Foo",
352 },
353]"#
247 ); 354 );
248 check_reference_completion(
249 "dont_render_function_parens_if_already_call_assoc_fn",
250 "
251 //- /lib.rs
252 struct Foo {}
253 impl Foo { fn new() -> Foo {} }
254 fn main() {
255 Foo::ne<|>();
256 }
257 ",
258 )
259 } 355 }
260
261} 356}
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call.snap
deleted file mode 100644
index 46bea2ccd..000000000
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call.snap
+++ /dev/null
@@ -1,24 +0,0 @@
1---
2created: "2019-05-23T22:23:35.158296242Z"
3creator: [email protected]
4source: crates/ra_ide_api/src/completion/completion_item.rs
5expression: kind_completions
6---
7[
8 CompletionItem {
9 label: "frobnicate",
10 source_range: [35; 39),
11 delete: [35; 39),
12 insert: "frobnicate",
13 kind: Function,
14 detail: "fn frobnicate()",
15 },
16 CompletionItem {
17 label: "main",
18 source_range: [35; 39),
19 delete: [35; 39),
20 insert: "main",
21 kind: Function,
22 detail: "fn main()",
23 },
24]
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call_assoc_fn.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call_assoc_fn.snap
deleted file mode 100644
index b09a6745e..000000000
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call_assoc_fn.snap
+++ /dev/null
@@ -1,16 +0,0 @@
1---
2created: "2019-05-23T22:44:10.920136527Z"
3creator: [email protected]
4source: crates/ra_ide_api/src/completion/completion_item.rs
5expression: kind_completions
6---
7[
8 CompletionItem {
9 label: "new",
10 source_range: [67; 69),
11 delete: [67; 69),
12 insert: "new",
13 kind: Function,
14 detail: "fn new() -> Foo",
15 },
16]
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_in_use_item.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_in_use_item.snap
deleted file mode 100644
index 84ccc8160..000000000
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_in_use_item.snap
+++ /dev/null
@@ -1,16 +0,0 @@
1---
2created: "2019-05-23T22:23:35.154795561Z"
3creator: [email protected]
4source: crates/ra_ide_api/src/completion/completion_item.rs
5expression: kind_completions
6---
7[
8 CompletionItem {
9 label: "foo",
10 source_range: [40; 41),
11 delete: [40; 41),
12 insert: "foo",
13 kind: Function,
14 detail: "pub fn foo()",
15 },
16]
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls1.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls1.snap
deleted file mode 100644
index c795b9aae..000000000
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls1.snap
+++ /dev/null
@@ -1,24 +0,0 @@
1---
2created: "2019-05-23T22:23:35.156115632Z"
3creator: [email protected]
4source: crates/ra_ide_api/src/completion/completion_item.rs
5expression: kind_completions
6---
7[
8 CompletionItem {
9 label: "main",
10 source_range: [53; 56),
11 delete: [53; 56),
12 insert: "main()$0",
13 kind: Function,
14 detail: "fn main()",
15 },
16 CompletionItem {
17 label: "no_args",
18 source_range: [53; 56),
19 delete: [53; 56),
20 insert: "no_args()$0",
21 kind: Function,
22 detail: "fn no_args()",
23 },
24]
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls2.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls2.snap
deleted file mode 100644
index b49a838e0..000000000
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls2.snap
+++ /dev/null
@@ -1,24 +0,0 @@
1---
2created: "2019-05-23T22:44:10.916806744Z"
3creator: [email protected]
4source: crates/ra_ide_api/src/completion/completion_item.rs
5expression: kind_completions
6---
7[
8 CompletionItem {
9 label: "main",
10 source_range: [72; 77),
11 delete: [72; 77),
12 insert: "main()$0",
13 kind: Function,
14 detail: "fn main()",
15 },
16 CompletionItem {
17 label: "with_args",
18 source_range: [72; 77),
19 delete: [72; 77),
20 insert: "with_args($0)",
21 kind: Function,
22 detail: "fn with_args(x: i32, y: String)",
23 },
24]
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls3.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls3.snap
deleted file mode 100644
index b62cb7aa1..000000000
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls3.snap
+++ /dev/null
@@ -1,16 +0,0 @@
1---
2created: "2019-05-23T22:44:40.543731193Z"
3creator: [email protected]
4source: crates/ra_ide_api/src/completion/completion_item.rs
5expression: kind_completions
6---
7[
8 CompletionItem {
9 label: "foo",
10 source_range: [139; 140),
11 delete: [139; 140),
12 insert: "foo()$0",
13 kind: Method,
14 detail: "fn foo(&self)",
15 },
16]