diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-10-10 11:19:11 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-10-10 11:19:11 +0100 |
commit | 72b8cfb5aa99d85cd8cc936232cbbf24d1995547 (patch) | |
tree | 7952b096410ddb74a9ba70b3305902106d969838 /crates/ra_ide_api/src/completion/presentation.rs | |
parent | 793f7e69f298ccb14936a33c59d7df1527b39af6 (diff) | |
parent | 31561b118f1a57c9c1c5145493c5fcd3dd40876e (diff) |
Merge #1978
1978: if completion does auto-insertion, indicate this in the label r=matklad a=matklad
bors try
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src/completion/presentation.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/presentation.rs | 148 |
1 files changed, 86 insertions, 62 deletions
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index b7807ef8e..175a27ba9 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -116,7 +116,10 @@ impl Completions { | |||
116 | if let Some(def) = generic_def { | 116 | if let Some(def) = generic_def { |
117 | if has_non_default_type_params(def, ctx.db) { | 117 | if has_non_default_type_params(def, ctx.db) { |
118 | tested_by!(inserts_angle_brackets_for_generics); | 118 | tested_by!(inserts_angle_brackets_for_generics); |
119 | completion_item = completion_item.insert_snippet(format!("{}<$0>", local_name)); | 119 | completion_item = completion_item |
120 | .lookup_by(local_name.clone()) | ||
121 | .label(format!("{}<…>", local_name)) | ||
122 | .insert_snippet(format!("{}<$0>", local_name)); | ||
120 | } | 123 | } |
121 | } | 124 | } |
122 | } | 125 | } |
@@ -169,14 +172,15 @@ impl Completions { | |||
169 | let ast_node = func.source(ctx.db).ast; | 172 | let ast_node = func.source(ctx.db).ast; |
170 | let detail = function_label(&ast_node); | 173 | let detail = function_label(&ast_node); |
171 | 174 | ||
172 | let mut builder = CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name) | 175 | let mut builder = |
173 | .kind(if data.has_self_param() { | 176 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.clone()) |
174 | CompletionItemKind::Method | 177 | .kind(if data.has_self_param() { |
175 | } else { | 178 | CompletionItemKind::Method |
176 | CompletionItemKind::Function | 179 | } else { |
177 | }) | 180 | CompletionItemKind::Function |
178 | .set_documentation(func.docs(ctx.db)) | 181 | }) |
179 | .detail(detail); | 182 | .set_documentation(func.docs(ctx.db)) |
183 | .detail(detail); | ||
180 | 184 | ||
181 | // Add `<>` for generic types | 185 | // Add `<>` for generic types |
182 | if ctx.use_item_syntax.is_none() | 186 | if ctx.use_item_syntax.is_none() |
@@ -190,7 +194,10 @@ impl Completions { | |||
190 | } else { | 194 | } else { |
191 | format!("{}($0)", data.name()) | 195 | format!("{}($0)", data.name()) |
192 | }; | 196 | }; |
193 | builder = builder.insert_snippet(snippet); | 197 | builder = builder |
198 | .lookup_by(name.clone()) | ||
199 | .label(format!("{}(…)", name)) | ||
200 | .insert_snippet(snippet); | ||
194 | } | 201 | } |
195 | 202 | ||
196 | self.add(builder) | 203 | self.add(builder) |
@@ -269,24 +276,28 @@ mod tests { | |||
269 | fn main() { no_<|> } | 276 | fn main() { no_<|> } |
270 | " | 277 | " |
271 | ), | 278 | ), |
272 | @r###"[ | 279 | @r###" |
273 | CompletionItem { | 280 | [ |
274 | label: "main", | 281 | CompletionItem { |
275 | source_range: [61; 64), | 282 | label: "main(…)", |
276 | delete: [61; 64), | 283 | source_range: [61; 64), |
277 | insert: "main()$0", | 284 | delete: [61; 64), |
278 | kind: Function, | 285 | insert: "main()$0", |
279 | detail: "fn main()", | 286 | kind: Function, |
280 | }, | 287 | lookup: "main", |
281 | CompletionItem { | 288 | detail: "fn main()", |
282 | label: "no_args", | 289 | }, |
283 | source_range: [61; 64), | 290 | CompletionItem { |
284 | delete: [61; 64), | 291 | label: "no_args(…)", |
285 | insert: "no_args()$0", | 292 | source_range: [61; 64), |
286 | kind: Function, | 293 | delete: [61; 64), |
287 | detail: "fn no_args()", | 294 | insert: "no_args()$0", |
288 | }, | 295 | kind: Function, |
289 | ]"### | 296 | lookup: "no_args", |
297 | detail: "fn no_args()", | ||
298 | }, | ||
299 | ] | ||
300 | "### | ||
290 | ); | 301 | ); |
291 | assert_debug_snapshot!( | 302 | assert_debug_snapshot!( |
292 | do_reference_completion( | 303 | do_reference_completion( |
@@ -295,24 +306,28 @@ mod tests { | |||
295 | fn main() { with_<|> } | 306 | fn main() { with_<|> } |
296 | " | 307 | " |
297 | ), | 308 | ), |
298 | @r###"[ | 309 | @r###" |
299 | CompletionItem { | 310 | [ |
300 | label: "main", | 311 | CompletionItem { |
301 | source_range: [80; 85), | 312 | label: "main(…)", |
302 | delete: [80; 85), | 313 | source_range: [80; 85), |
303 | insert: "main()$0", | 314 | delete: [80; 85), |
304 | kind: Function, | 315 | insert: "main()$0", |
305 | detail: "fn main()", | 316 | kind: Function, |
306 | }, | 317 | lookup: "main", |
307 | CompletionItem { | 318 | detail: "fn main()", |
308 | label: "with_args", | 319 | }, |
309 | source_range: [80; 85), | 320 | CompletionItem { |
310 | delete: [80; 85), | 321 | label: "with_args(…)", |
311 | insert: "with_args($0)", | 322 | source_range: [80; 85), |
312 | kind: Function, | 323 | delete: [80; 85), |
313 | detail: "fn with_args(x: i32, y: String)", | 324 | insert: "with_args($0)", |
314 | }, | 325 | kind: Function, |
315 | ]"### | 326 | lookup: "with_args", |
327 | detail: "fn with_args(x: i32, y: String)", | ||
328 | }, | ||
329 | ] | ||
330 | "### | ||
316 | ); | 331 | ); |
317 | assert_debug_snapshot!( | 332 | assert_debug_snapshot!( |
318 | do_reference_completion( | 333 | do_reference_completion( |
@@ -326,16 +341,19 @@ mod tests { | |||
326 | } | 341 | } |
327 | " | 342 | " |
328 | ), | 343 | ), |
329 | @r###"[ | 344 | @r###" |
330 | CompletionItem { | 345 | [ |
331 | label: "foo", | 346 | CompletionItem { |
332 | source_range: [163; 164), | 347 | label: "foo(…)", |
333 | delete: [163; 164), | 348 | source_range: [163; 164), |
334 | insert: "foo()$0", | 349 | delete: [163; 164), |
335 | kind: Method, | 350 | insert: "foo()$0", |
336 | detail: "fn foo(&self)", | 351 | kind: Method, |
337 | }, | 352 | lookup: "foo", |
338 | ]"### | 353 | detail: "fn foo(&self)", |
354 | }, | ||
355 | ] | ||
356 | "### | ||
339 | ); | 357 | ); |
340 | } | 358 | } |
341 | 359 | ||
@@ -430,18 +448,20 @@ mod tests { | |||
430 | @r###" | 448 | @r###" |
431 | [ | 449 | [ |
432 | CompletionItem { | 450 | CompletionItem { |
433 | label: "Vec", | 451 | label: "Vec<…>", |
434 | source_range: [61; 63), | 452 | source_range: [61; 63), |
435 | delete: [61; 63), | 453 | delete: [61; 63), |
436 | insert: "Vec<$0>", | 454 | insert: "Vec<$0>", |
437 | kind: Struct, | 455 | kind: Struct, |
456 | lookup: "Vec", | ||
438 | }, | 457 | }, |
439 | CompletionItem { | 458 | CompletionItem { |
440 | label: "foo", | 459 | label: "foo(…)", |
441 | source_range: [61; 63), | 460 | source_range: [61; 63), |
442 | delete: [61; 63), | 461 | delete: [61; 63), |
443 | insert: "foo($0)", | 462 | insert: "foo($0)", |
444 | kind: Function, | 463 | kind: Function, |
464 | lookup: "foo", | ||
445 | detail: "fn foo(xs: Ve)", | 465 | detail: "fn foo(xs: Ve)", |
446 | }, | 466 | }, |
447 | ] | 467 | ] |
@@ -457,18 +477,20 @@ mod tests { | |||
457 | @r###" | 477 | @r###" |
458 | [ | 478 | [ |
459 | CompletionItem { | 479 | CompletionItem { |
460 | label: "Vec", | 480 | label: "Vec<…>", |
461 | source_range: [64; 66), | 481 | source_range: [64; 66), |
462 | delete: [64; 66), | 482 | delete: [64; 66), |
463 | insert: "Vec<$0>", | 483 | insert: "Vec<$0>", |
464 | kind: TypeAlias, | 484 | kind: TypeAlias, |
485 | lookup: "Vec", | ||
465 | }, | 486 | }, |
466 | CompletionItem { | 487 | CompletionItem { |
467 | label: "foo", | 488 | label: "foo(…)", |
468 | source_range: [64; 66), | 489 | source_range: [64; 66), |
469 | delete: [64; 66), | 490 | delete: [64; 66), |
470 | insert: "foo($0)", | 491 | insert: "foo($0)", |
471 | kind: Function, | 492 | kind: Function, |
493 | lookup: "foo", | ||
472 | detail: "fn foo(xs: Ve)", | 494 | detail: "fn foo(xs: Ve)", |
473 | }, | 495 | }, |
474 | ] | 496 | ] |
@@ -491,11 +513,12 @@ mod tests { | |||
491 | kind: Struct, | 513 | kind: Struct, |
492 | }, | 514 | }, |
493 | CompletionItem { | 515 | CompletionItem { |
494 | label: "foo", | 516 | label: "foo(…)", |
495 | source_range: [68; 70), | 517 | source_range: [68; 70), |
496 | delete: [68; 70), | 518 | delete: [68; 70), |
497 | insert: "foo($0)", | 519 | insert: "foo($0)", |
498 | kind: Function, | 520 | kind: Function, |
521 | lookup: "foo", | ||
499 | detail: "fn foo(xs: Ve)", | 522 | detail: "fn foo(xs: Ve)", |
500 | }, | 523 | }, |
501 | ] | 524 | ] |
@@ -518,11 +541,12 @@ mod tests { | |||
518 | kind: Struct, | 541 | kind: Struct, |
519 | }, | 542 | }, |
520 | CompletionItem { | 543 | CompletionItem { |
521 | label: "foo", | 544 | label: "foo(…)", |
522 | source_range: [61; 63), | 545 | source_range: [61; 63), |
523 | delete: [61; 63), | 546 | delete: [61; 63), |
524 | insert: "foo($0)", | 547 | insert: "foo($0)", |
525 | kind: Function, | 548 | kind: Function, |
549 | lookup: "foo", | ||
526 | detail: "fn foo(xs: Ve<i128>)", | 550 | detail: "fn foo(xs: Ve<i128>)", |
527 | }, | 551 | }, |
528 | ] | 552 | ] |