diff options
author | Martin Asquino <[email protected]> | 2019-11-02 02:52:59 +0000 |
---|---|---|
committer | Martin Asquino <[email protected]> | 2019-11-02 20:37:47 +0000 |
commit | dc3848a6a3e659004ba4f2160503be28ea0f9051 (patch) | |
tree | d146b883f6352cbc647d8ad484377242582a7c39 /crates/ra_ide_api/src/completion | |
parent | eb8f76a86fe88fcad370577b344f397dd6118cfd (diff) |
Set `deprecated` field on `CompletionItem`s
Diffstat (limited to 'crates/ra_ide_api/src/completion')
8 files changed, 185 insertions, 1 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index b4df6ee2a..9c0abd590 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs | |||
@@ -96,6 +96,7 @@ mod tests { | |||
96 | ⋮ insert: "the_field", | 96 | ⋮ insert: "the_field", |
97 | ⋮ kind: Field, | 97 | ⋮ kind: Field, |
98 | ⋮ detail: "u32", | 98 | ⋮ detail: "u32", |
99 | ⋮ deprecated: false, | ||
99 | ⋮ }, | 100 | ⋮ }, |
100 | ⋮] | 101 | ⋮] |
101 | "### | 102 | "### |
@@ -128,6 +129,7 @@ mod tests { | |||
128 | kind: Method, | 129 | kind: Method, |
129 | lookup: "foo", | 130 | lookup: "foo", |
130 | detail: "fn foo(self)", | 131 | detail: "fn foo(self)", |
132 | deprecated: false, | ||
131 | }, | 133 | }, |
132 | CompletionItem { | 134 | CompletionItem { |
133 | label: "the_field", | 135 | label: "the_field", |
@@ -139,6 +141,7 @@ mod tests { | |||
139 | documentation: Documentation( | 141 | documentation: Documentation( |
140 | "This is the_field", | 142 | "This is the_field", |
141 | ), | 143 | ), |
144 | deprecated: false, | ||
142 | }, | 145 | }, |
143 | ] | 146 | ] |
144 | "### | 147 | "### |
@@ -168,6 +171,7 @@ mod tests { | |||
168 | kind: Method, | 171 | kind: Method, |
169 | lookup: "foo", | 172 | lookup: "foo", |
170 | detail: "fn foo(&self)", | 173 | detail: "fn foo(&self)", |
174 | deprecated: false, | ||
171 | }, | 175 | }, |
172 | CompletionItem { | 176 | CompletionItem { |
173 | label: "the_field", | 177 | label: "the_field", |
@@ -176,6 +180,7 @@ mod tests { | |||
176 | insert: "the_field", | 180 | insert: "the_field", |
177 | kind: Field, | 181 | kind: Field, |
178 | detail: "(u32, i32)", | 182 | detail: "(u32, i32)", |
183 | deprecated: false, | ||
179 | }, | 184 | }, |
180 | ] | 185 | ] |
181 | "### | 186 | "### |
@@ -221,6 +226,7 @@ mod tests { | |||
221 | kind: Method, | 226 | kind: Method, |
222 | lookup: "the_method", | 227 | lookup: "the_method", |
223 | detail: "fn the_method(&self)", | 228 | detail: "fn the_method(&self)", |
229 | deprecated: false, | ||
224 | }, | 230 | }, |
225 | ] | 231 | ] |
226 | "### | 232 | "### |
@@ -250,6 +256,7 @@ mod tests { | |||
250 | kind: Method, | 256 | kind: Method, |
251 | lookup: "the_method", | 257 | lookup: "the_method", |
252 | detail: "fn the_method(&self)", | 258 | detail: "fn the_method(&self)", |
259 | deprecated: false, | ||
253 | }, | 260 | }, |
254 | ] | 261 | ] |
255 | "### | 262 | "### |
@@ -279,6 +286,7 @@ mod tests { | |||
279 | kind: Method, | 286 | kind: Method, |
280 | lookup: "the_method", | 287 | lookup: "the_method", |
281 | detail: "fn the_method(&self)", | 288 | detail: "fn the_method(&self)", |
289 | deprecated: false, | ||
282 | }, | 290 | }, |
283 | ] | 291 | ] |
284 | "### | 292 | "### |
@@ -331,6 +339,7 @@ mod tests { | |||
331 | kind: Method, | 339 | kind: Method, |
332 | lookup: "the_method", | 340 | lookup: "the_method", |
333 | detail: "fn the_method(&self)", | 341 | detail: "fn the_method(&self)", |
342 | deprecated: false, | ||
334 | }, | 343 | }, |
335 | ] | 344 | ] |
336 | "### | 345 | "### |
@@ -401,6 +410,7 @@ mod tests { | |||
401 | kind: Method, | 410 | kind: Method, |
402 | lookup: "blah", | 411 | lookup: "blah", |
403 | detail: "pub fn blah(&self)", | 412 | detail: "pub fn blah(&self)", |
413 | deprecated: false, | ||
404 | }, | 414 | }, |
405 | ] | 415 | ] |
406 | "### | 416 | "### |
@@ -427,6 +437,7 @@ mod tests { | |||
427 | ⋮ insert: "the_field", | 437 | ⋮ insert: "the_field", |
428 | ⋮ kind: Field, | 438 | ⋮ kind: Field, |
429 | ⋮ detail: "u32", | 439 | ⋮ detail: "u32", |
440 | ⋮ deprecated: false, | ||
430 | ⋮ }, | 441 | ⋮ }, |
431 | ⋮] | 442 | ⋮] |
432 | "### | 443 | "### |
diff --git a/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs b/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs index 09f743c66..a082a3c7c 100644 --- a/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs +++ b/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs | |||
@@ -45,6 +45,7 @@ mod tests { | |||
45 | insert: "foo!($0)", | 45 | insert: "foo!($0)", |
46 | kind: Macro, | 46 | kind: Macro, |
47 | detail: "macro_rules! foo", | 47 | detail: "macro_rules! foo", |
48 | deprecated: false, | ||
48 | }, | 49 | }, |
49 | ]"## | 50 | ]"## |
50 | ); | 51 | ); |
@@ -86,6 +87,7 @@ mod tests { | |||
86 | documentation: Documentation( | 87 | documentation: Documentation( |
87 | "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```", | 88 | "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```", |
88 | ), | 89 | ), |
90 | deprecated: false, | ||
89 | }, | 91 | }, |
90 | ]"## | 92 | ]"## |
91 | ); | 93 | ); |
@@ -121,6 +123,7 @@ mod tests { | |||
121 | documentation: Documentation( | 123 | documentation: Documentation( |
122 | "Foo\n\nNot call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`.\nCall as `let _=foo! { hello world };`", | 124 | "Foo\n\nNot call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`.\nCall as `let _=foo! { hello world };`", |
123 | ), | 125 | ), |
126 | deprecated: false, | ||
124 | }, | 127 | }, |
125 | CompletionItem { | 128 | CompletionItem { |
126 | label: "main()", | 129 | label: "main()", |
@@ -130,6 +133,7 @@ mod tests { | |||
130 | kind: Function, | 133 | kind: Function, |
131 | lookup: "main", | 134 | lookup: "main", |
132 | detail: "fn main()", | 135 | detail: "fn main()", |
136 | deprecated: false, | ||
133 | }, | 137 | }, |
134 | ] | 138 | ] |
135 | "### | 139 | "### |
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 9ac9768af..2c9c8645b 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -308,6 +308,7 @@ mod tests { | |||
308 | documentation: Documentation( | 308 | documentation: Documentation( |
309 | "Bar Variant with i32", | 309 | "Bar Variant with i32", |
310 | ), | 310 | ), |
311 | deprecated: false, | ||
311 | }, | 312 | }, |
312 | CompletionItem { | 313 | CompletionItem { |
313 | label: "Foo", | 314 | label: "Foo", |
@@ -319,6 +320,7 @@ mod tests { | |||
319 | documentation: Documentation( | 320 | documentation: Documentation( |
320 | "Foo Variant", | 321 | "Foo Variant", |
321 | ), | 322 | ), |
323 | deprecated: false, | ||
322 | }, | 324 | }, |
323 | ]"### | 325 | ]"### |
324 | ); | 326 | ); |
@@ -354,6 +356,7 @@ mod tests { | |||
354 | documentation: Documentation( | 356 | documentation: Documentation( |
355 | "Bar Variant with i32 and u32", | 357 | "Bar Variant with i32 and u32", |
356 | ), | 358 | ), |
359 | deprecated: false, | ||
357 | }, | 360 | }, |
358 | CompletionItem { | 361 | CompletionItem { |
359 | label: "Foo", | 362 | label: "Foo", |
@@ -365,6 +368,7 @@ mod tests { | |||
365 | documentation: Documentation( | 368 | documentation: Documentation( |
366 | "Foo Variant (empty)", | 369 | "Foo Variant (empty)", |
367 | ), | 370 | ), |
371 | deprecated: false, | ||
368 | }, | 372 | }, |
369 | CompletionItem { | 373 | CompletionItem { |
370 | label: "S", | 374 | label: "S", |
@@ -376,6 +380,7 @@ mod tests { | |||
376 | documentation: Documentation( | 380 | documentation: Documentation( |
377 | "", | 381 | "", |
378 | ), | 382 | ), |
383 | deprecated: false, | ||
379 | }, | 384 | }, |
380 | ]"### | 385 | ]"### |
381 | ); | 386 | ); |
@@ -411,6 +416,7 @@ mod tests { | |||
411 | documentation: Documentation( | 416 | documentation: Documentation( |
412 | "An associated method", | 417 | "An associated method", |
413 | ), | 418 | ), |
419 | deprecated: false, | ||
414 | }, | 420 | }, |
415 | ] | 421 | ] |
416 | "### | 422 | "### |
@@ -445,6 +451,7 @@ mod tests { | |||
445 | documentation: Documentation( | 451 | documentation: Documentation( |
446 | "An associated const", | 452 | "An associated const", |
447 | ), | 453 | ), |
454 | deprecated: false, | ||
448 | }, | 455 | }, |
449 | ]"### | 456 | ]"### |
450 | ); | 457 | ); |
@@ -478,6 +485,7 @@ mod tests { | |||
478 | documentation: Documentation( | 485 | documentation: Documentation( |
479 | "An associated type", | 486 | "An associated type", |
480 | ), | 487 | ), |
488 | deprecated: false, | ||
481 | }, | 489 | }, |
482 | ]"### | 490 | ]"### |
483 | ); | 491 | ); |
@@ -513,6 +521,7 @@ mod tests { | |||
513 | documentation: Documentation( | 521 | documentation: Documentation( |
514 | "An associated method", | 522 | "An associated method", |
515 | ), | 523 | ), |
524 | deprecated: false, | ||
516 | }, | 525 | }, |
517 | ] | 526 | ] |
518 | "### | 527 | "### |
@@ -549,6 +558,7 @@ mod tests { | |||
549 | documentation: Documentation( | 558 | documentation: Documentation( |
550 | "An associated method", | 559 | "An associated method", |
551 | ), | 560 | ), |
561 | deprecated: false, | ||
552 | }, | 562 | }, |
553 | ] | 563 | ] |
554 | "### | 564 | "### |
@@ -608,6 +618,7 @@ mod tests { | |||
608 | documentation: Documentation( | 618 | documentation: Documentation( |
609 | "A trait method", | 619 | "A trait method", |
610 | ), | 620 | ), |
621 | deprecated: false, | ||
611 | }, | 622 | }, |
612 | ] | 623 | ] |
613 | "### | 624 | "### |
@@ -644,6 +655,7 @@ mod tests { | |||
644 | documentation: Documentation( | 655 | documentation: Documentation( |
645 | "A trait method", | 656 | "A trait method", |
646 | ), | 657 | ), |
658 | deprecated: false, | ||
647 | }, | 659 | }, |
648 | ] | 660 | ] |
649 | "### | 661 | "### |
@@ -680,6 +692,7 @@ mod tests { | |||
680 | documentation: Documentation( | 692 | documentation: Documentation( |
681 | "A trait method", | 693 | "A trait method", |
682 | ), | 694 | ), |
695 | deprecated: false, | ||
683 | }, | 696 | }, |
684 | ] | 697 | ] |
685 | "### | 698 | "### |
@@ -711,6 +724,7 @@ mod tests { | |||
711 | kind: Function, | 724 | kind: Function, |
712 | lookup: "bar", | 725 | lookup: "bar", |
713 | detail: "fn bar()", | 726 | detail: "fn bar()", |
727 | deprecated: false, | ||
714 | }, | 728 | }, |
715 | CompletionItem { | 729 | CompletionItem { |
716 | label: "foo()", | 730 | label: "foo()", |
@@ -720,6 +734,7 @@ mod tests { | |||
720 | kind: Function, | 734 | kind: Function, |
721 | lookup: "foo", | 735 | lookup: "foo", |
722 | detail: "fn foo()", | 736 | detail: "fn foo()", |
737 | deprecated: false, | ||
723 | }, | 738 | }, |
724 | ] | 739 | ] |
725 | "### | 740 | "### |
@@ -750,6 +765,7 @@ mod tests { | |||
750 | insert: "foo!($0)", | 765 | insert: "foo!($0)", |
751 | kind: Macro, | 766 | kind: Macro, |
752 | detail: "#[macro_export]\nmacro_rules! foo", | 767 | detail: "#[macro_export]\nmacro_rules! foo", |
768 | deprecated: false, | ||
753 | }, | 769 | }, |
754 | CompletionItem { | 770 | CompletionItem { |
755 | label: "main()", | 771 | label: "main()", |
@@ -759,6 +775,7 @@ mod tests { | |||
759 | kind: Function, | 775 | kind: Function, |
760 | lookup: "main", | 776 | lookup: "main", |
761 | detail: "fn main()", | 777 | detail: "fn main()", |
778 | deprecated: false, | ||
762 | }, | 779 | }, |
763 | ] | 780 | ] |
764 | "### | 781 | "### |
diff --git a/crates/ra_ide_api/src/completion/complete_record_literal.rs b/crates/ra_ide_api/src/completion/complete_record_literal.rs index 4406695d5..33bea411f 100644 --- a/crates/ra_ide_api/src/completion/complete_record_literal.rs +++ b/crates/ra_ide_api/src/completion/complete_record_literal.rs | |||
@@ -32,6 +32,34 @@ mod tests { | |||
32 | } | 32 | } |
33 | 33 | ||
34 | #[test] | 34 | #[test] |
35 | fn test_record_literal_deprecated_field() { | ||
36 | let completions = complete( | ||
37 | r" | ||
38 | struct A { | ||
39 | #[deprecated] | ||
40 | the_field: u32, | ||
41 | } | ||
42 | fn foo() { | ||
43 | A { the<|> } | ||
44 | } | ||
45 | ", | ||
46 | ); | ||
47 | assert_debug_snapshot!(completions, @r###" | ||
48 | ⋮[ | ||
49 | ⋮ CompletionItem { | ||
50 | ⋮ label: "the_field", | ||
51 | ⋮ source_range: [142; 145), | ||
52 | ⋮ delete: [142; 145), | ||
53 | ⋮ insert: "the_field", | ||
54 | ⋮ kind: Field, | ||
55 | ⋮ detail: "u32", | ||
56 | ⋮ deprecated: true, | ||
57 | ⋮ }, | ||
58 | ⋮] | ||
59 | "###); | ||
60 | } | ||
61 | |||
62 | #[test] | ||
35 | fn test_record_literal_field() { | 63 | fn test_record_literal_field() { |
36 | let completions = complete( | 64 | let completions = complete( |
37 | r" | 65 | r" |
@@ -50,6 +78,7 @@ mod tests { | |||
50 | ⋮ insert: "the_field", | 78 | ⋮ insert: "the_field", |
51 | ⋮ kind: Field, | 79 | ⋮ kind: Field, |
52 | ⋮ detail: "u32", | 80 | ⋮ detail: "u32", |
81 | ⋮ deprecated: false, | ||
53 | ⋮ }, | 82 | ⋮ }, |
54 | ⋮] | 83 | ⋮] |
55 | "###); | 84 | "###); |
@@ -76,6 +105,7 @@ mod tests { | |||
76 | ⋮ insert: "a", | 105 | ⋮ insert: "a", |
77 | ⋮ kind: Field, | 106 | ⋮ kind: Field, |
78 | ⋮ detail: "u32", | 107 | ⋮ detail: "u32", |
108 | ⋮ deprecated: false, | ||
79 | ⋮ }, | 109 | ⋮ }, |
80 | ⋮] | 110 | ⋮] |
81 | "###); | 111 | "###); |
@@ -102,6 +132,7 @@ mod tests { | |||
102 | ⋮ insert: "b", | 132 | ⋮ insert: "b", |
103 | ⋮ kind: Field, | 133 | ⋮ kind: Field, |
104 | ⋮ detail: "u32", | 134 | ⋮ detail: "u32", |
135 | ⋮ deprecated: false, | ||
105 | ⋮ }, | 136 | ⋮ }, |
106 | ⋮] | 137 | ⋮] |
107 | "###); | 138 | "###); |
@@ -127,6 +158,7 @@ mod tests { | |||
127 | ⋮ insert: "a", | 158 | ⋮ insert: "a", |
128 | ⋮ kind: Field, | 159 | ⋮ kind: Field, |
129 | ⋮ detail: "u32", | 160 | ⋮ detail: "u32", |
161 | ⋮ deprecated: false, | ||
130 | ⋮ }, | 162 | ⋮ }, |
131 | ⋮] | 163 | ⋮] |
132 | "###); | 164 | "###); |
diff --git a/crates/ra_ide_api/src/completion/complete_record_pattern.rs b/crates/ra_ide_api/src/completion/complete_record_pattern.rs index d20fa796c..93c26f229 100644 --- a/crates/ra_ide_api/src/completion/complete_record_pattern.rs +++ b/crates/ra_ide_api/src/completion/complete_record_pattern.rs | |||
@@ -52,6 +52,7 @@ mod tests { | |||
52 | ⋮ insert: "foo", | 52 | ⋮ insert: "foo", |
53 | ⋮ kind: Field, | 53 | ⋮ kind: Field, |
54 | ⋮ detail: "u32", | 54 | ⋮ detail: "u32", |
55 | ⋮ deprecated: false, | ||
55 | ⋮ }, | 56 | ⋮ }, |
56 | ⋮] | 57 | ⋮] |
57 | "###); | 58 | "###); |
@@ -81,6 +82,7 @@ mod tests { | |||
81 | ⋮ insert: "bar", | 82 | ⋮ insert: "bar", |
82 | ⋮ kind: Field, | 83 | ⋮ kind: Field, |
83 | ⋮ detail: "()", | 84 | ⋮ detail: "()", |
85 | ⋮ deprecated: false, | ||
84 | ⋮ }, | 86 | ⋮ }, |
85 | ⋮ CompletionItem { | 87 | ⋮ CompletionItem { |
86 | ⋮ label: "foo", | 88 | ⋮ label: "foo", |
@@ -89,6 +91,7 @@ mod tests { | |||
89 | ⋮ insert: "foo", | 91 | ⋮ insert: "foo", |
90 | ⋮ kind: Field, | 92 | ⋮ kind: Field, |
91 | ⋮ detail: "u32", | 93 | ⋮ detail: "u32", |
94 | ⋮ deprecated: false, | ||
92 | ⋮ }, | 95 | ⋮ }, |
93 | ⋮] | 96 | ⋮] |
94 | "###); | 97 | "###); |
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 4e56de3f5..9d2deee75 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs | |||
@@ -155,6 +155,7 @@ mod tests { | |||
155 | kind: Function, | 155 | kind: Function, |
156 | lookup: "quux", | 156 | lookup: "quux", |
157 | detail: "fn quux(x: i32)", | 157 | detail: "fn quux(x: i32)", |
158 | deprecated: false, | ||
158 | }, | 159 | }, |
159 | CompletionItem { | 160 | CompletionItem { |
160 | label: "x", | 161 | label: "x", |
@@ -218,6 +219,7 @@ mod tests { | |||
218 | kind: Function, | 219 | kind: Function, |
219 | lookup: "quux", | 220 | lookup: "quux", |
220 | detail: "fn quux()", | 221 | detail: "fn quux()", |
222 | deprecated: false, | ||
221 | }, | 223 | }, |
222 | ] | 224 | ] |
223 | "### | 225 | "### |
@@ -246,6 +248,7 @@ mod tests { | |||
246 | kind: Function, | 248 | kind: Function, |
247 | lookup: "quux", | 249 | lookup: "quux", |
248 | detail: "fn quux()", | 250 | detail: "fn quux()", |
251 | deprecated: false, | ||
249 | }, | 252 | }, |
250 | CompletionItem { | 253 | CompletionItem { |
251 | label: "x", | 254 | label: "x", |
@@ -286,6 +289,7 @@ mod tests { | |||
286 | kind: Function, | 289 | kind: Function, |
287 | lookup: "quux", | 290 | lookup: "quux", |
288 | detail: "fn quux<T>()", | 291 | detail: "fn quux<T>()", |
292 | deprecated: false, | ||
289 | }, | 293 | }, |
290 | ] | 294 | ] |
291 | "### | 295 | "### |
@@ -391,6 +395,7 @@ mod tests { | |||
391 | kind: Function, | 395 | kind: Function, |
392 | lookup: "quux", | 396 | lookup: "quux", |
393 | detail: "fn quux()", | 397 | detail: "fn quux()", |
398 | deprecated: false, | ||
394 | }, | 399 | }, |
395 | ] | 400 | ] |
396 | "### | 401 | "### |
@@ -450,6 +455,7 @@ mod tests { | |||
450 | kind: Function, | 455 | kind: Function, |
451 | lookup: "quux", | 456 | lookup: "quux", |
452 | detail: "fn quux()", | 457 | detail: "fn quux()", |
458 | deprecated: false, | ||
453 | }, | 459 | }, |
454 | ] | 460 | ] |
455 | "### | 461 | "### |
@@ -482,6 +488,7 @@ mod tests { | |||
482 | kind: Function, | 488 | kind: Function, |
483 | lookup: "x", | 489 | lookup: "x", |
484 | detail: "fn x()", | 490 | detail: "fn x()", |
491 | deprecated: false, | ||
485 | }, | 492 | }, |
486 | ] | 493 | ] |
487 | "### | 494 | "### |
@@ -520,6 +527,7 @@ mod tests { | |||
520 | kind: Function, | 527 | kind: Function, |
521 | lookup: "foo", | 528 | lookup: "foo", |
522 | detail: "fn foo()", | 529 | detail: "fn foo()", |
530 | deprecated: false, | ||
523 | }, | 531 | }, |
524 | ] | 532 | ] |
525 | "### | 533 | "### |
@@ -584,6 +592,7 @@ mod tests { | |||
584 | kind: Function, | 592 | kind: Function, |
585 | lookup: "foo", | 593 | lookup: "foo", |
586 | detail: "fn foo()", | 594 | detail: "fn foo()", |
595 | deprecated: false, | ||
587 | }, | 596 | }, |
588 | CompletionItem { | 597 | CompletionItem { |
589 | label: "std", | 598 | label: "std", |
@@ -639,6 +648,7 @@ mod tests { | |||
639 | insert: "bar!($0)", | 648 | insert: "bar!($0)", |
640 | kind: Macro, | 649 | kind: Macro, |
641 | detail: "macro_rules! bar", | 650 | detail: "macro_rules! bar", |
651 | deprecated: false, | ||
642 | }, | 652 | }, |
643 | CompletionItem { | 653 | CompletionItem { |
644 | label: "baz!", | 654 | label: "baz!", |
@@ -647,6 +657,7 @@ mod tests { | |||
647 | insert: "baz!($0)", | 657 | insert: "baz!($0)", |
648 | kind: Macro, | 658 | kind: Macro, |
649 | detail: "#[macro_export]\nmacro_rules! baz", | 659 | detail: "#[macro_export]\nmacro_rules! baz", |
660 | deprecated: false, | ||
650 | }, | 661 | }, |
651 | CompletionItem { | 662 | CompletionItem { |
652 | label: "foo!", | 663 | label: "foo!", |
@@ -655,6 +666,7 @@ mod tests { | |||
655 | insert: "foo!($0)", | 666 | insert: "foo!($0)", |
656 | kind: Macro, | 667 | kind: Macro, |
657 | detail: "macro_rules! foo", | 668 | detail: "macro_rules! foo", |
669 | deprecated: false, | ||
658 | }, | 670 | }, |
659 | CompletionItem { | 671 | CompletionItem { |
660 | label: "m1", | 672 | label: "m1", |
@@ -678,6 +690,7 @@ mod tests { | |||
678 | kind: Function, | 690 | kind: Function, |
679 | lookup: "main", | 691 | lookup: "main", |
680 | detail: "fn main()", | 692 | detail: "fn main()", |
693 | deprecated: false, | ||
681 | }, | 694 | }, |
682 | ] | 695 | ] |
683 | "### | 696 | "### |
@@ -708,6 +721,7 @@ mod tests { | |||
708 | insert: "foo!($0)", | 721 | insert: "foo!($0)", |
709 | kind: Macro, | 722 | kind: Macro, |
710 | detail: "macro_rules! foo", | 723 | detail: "macro_rules! foo", |
724 | deprecated: false, | ||
711 | }, | 725 | }, |
712 | CompletionItem { | 726 | CompletionItem { |
713 | label: "foo()", | 727 | label: "foo()", |
@@ -717,6 +731,7 @@ mod tests { | |||
717 | kind: Function, | 731 | kind: Function, |
718 | lookup: "foo", | 732 | lookup: "foo", |
719 | detail: "fn foo()", | 733 | detail: "fn foo()", |
734 | deprecated: false, | ||
720 | }, | 735 | }, |
721 | ] | 736 | ] |
722 | "### | 737 | "### |
@@ -747,6 +762,7 @@ mod tests { | |||
747 | insert: "foo!($0)", | 762 | insert: "foo!($0)", |
748 | kind: Macro, | 763 | kind: Macro, |
749 | detail: "macro_rules! foo", | 764 | detail: "macro_rules! foo", |
765 | deprecated: false, | ||
750 | }, | 766 | }, |
751 | CompletionItem { | 767 | CompletionItem { |
752 | label: "main()", | 768 | label: "main()", |
@@ -756,6 +772,7 @@ mod tests { | |||
756 | kind: Function, | 772 | kind: Function, |
757 | lookup: "main", | 773 | lookup: "main", |
758 | detail: "fn main()", | 774 | detail: "fn main()", |
775 | deprecated: false, | ||
759 | }, | 776 | }, |
760 | ] | 777 | ] |
761 | "### | 778 | "### |
@@ -786,6 +803,7 @@ mod tests { | |||
786 | insert: "foo!($0)", | 803 | insert: "foo!($0)", |
787 | kind: Macro, | 804 | kind: Macro, |
788 | detail: "macro_rules! foo", | 805 | detail: "macro_rules! foo", |
806 | deprecated: false, | ||
789 | }, | 807 | }, |
790 | CompletionItem { | 808 | CompletionItem { |
791 | label: "main()", | 809 | label: "main()", |
@@ -795,6 +813,7 @@ mod tests { | |||
795 | kind: Function, | 813 | kind: Function, |
796 | lookup: "main", | 814 | lookup: "main", |
797 | detail: "fn main()", | 815 | detail: "fn main()", |
816 | deprecated: false, | ||
798 | }, | 817 | }, |
799 | ] | 818 | ] |
800 | "### | 819 | "### |
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index 5c9c44704..6753672ca 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs | |||
@@ -44,6 +44,9 @@ pub struct CompletionItem { | |||
44 | /// Additional info to show in the UI pop up. | 44 | /// Additional info to show in the UI pop up. |
45 | detail: Option<String>, | 45 | detail: Option<String>, |
46 | documentation: Option<Documentation>, | 46 | documentation: Option<Documentation>, |
47 | |||
48 | /// Whether this item is marked as deprecated | ||
49 | deprecated: Option<bool>, | ||
47 | } | 50 | } |
48 | 51 | ||
49 | // We use custom debug for CompletionItem to make `insta`'s diffs more readable. | 52 | // We use custom debug for CompletionItem to make `insta`'s diffs more readable. |
@@ -70,6 +73,9 @@ impl fmt::Debug for CompletionItem { | |||
70 | if let Some(documentation) = self.documentation() { | 73 | if let Some(documentation) = self.documentation() { |
71 | s.field("documentation", &documentation); | 74 | s.field("documentation", &documentation); |
72 | } | 75 | } |
76 | if let Some(deprecated) = self.deprecated { | ||
77 | s.field("deprecated", &deprecated); | ||
78 | } | ||
73 | s.finish() | 79 | s.finish() |
74 | } | 80 | } |
75 | } | 81 | } |
@@ -132,6 +138,7 @@ impl CompletionItem { | |||
132 | lookup: None, | 138 | lookup: None, |
133 | kind: None, | 139 | kind: None, |
134 | text_edit: None, | 140 | text_edit: None, |
141 | deprecated: None, | ||
135 | } | 142 | } |
136 | } | 143 | } |
137 | /// What user sees in pop-up in the UI. | 144 | /// What user sees in pop-up in the UI. |
@@ -166,6 +173,10 @@ impl CompletionItem { | |||
166 | pub fn kind(&self) -> Option<CompletionItemKind> { | 173 | pub fn kind(&self) -> Option<CompletionItemKind> { |
167 | self.kind | 174 | self.kind |
168 | } | 175 | } |
176 | |||
177 | pub fn deprecated(&self) -> Option<bool> { | ||
178 | self.deprecated | ||
179 | } | ||
169 | } | 180 | } |
170 | 181 | ||
171 | /// A helper to make `CompletionItem`s. | 182 | /// A helper to make `CompletionItem`s. |
@@ -181,6 +192,7 @@ pub(crate) struct Builder { | |||
181 | lookup: Option<String>, | 192 | lookup: Option<String>, |
182 | kind: Option<CompletionItemKind>, | 193 | kind: Option<CompletionItemKind>, |
183 | text_edit: Option<TextEdit>, | 194 | text_edit: Option<TextEdit>, |
195 | deprecated: Option<bool>, | ||
184 | } | 196 | } |
185 | 197 | ||
186 | impl Builder { | 198 | impl Builder { |
@@ -208,6 +220,7 @@ impl Builder { | |||
208 | lookup: self.lookup, | 220 | lookup: self.lookup, |
209 | kind: self.kind, | 221 | kind: self.kind, |
210 | completion_kind: self.completion_kind, | 222 | completion_kind: self.completion_kind, |
223 | deprecated: self.deprecated, | ||
211 | } | 224 | } |
212 | } | 225 | } |
213 | pub(crate) fn lookup_by(mut self, lookup: impl Into<String>) -> Builder { | 226 | pub(crate) fn lookup_by(mut self, lookup: impl Into<String>) -> Builder { |
@@ -254,6 +267,10 @@ impl Builder { | |||
254 | self.documentation = docs.map(Into::into); | 267 | self.documentation = docs.map(Into::into); |
255 | self | 268 | self |
256 | } | 269 | } |
270 | pub(crate) fn set_deprecated(mut self, deprecated: bool) -> Builder { | ||
271 | self.deprecated = Some(deprecated); | ||
272 | self | ||
273 | } | ||
257 | } | 274 | } |
258 | 275 | ||
259 | impl<'a> Into<CompletionItem> for Builder { | 276 | impl<'a> Into<CompletionItem> for Builder { |
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 65bb639ed..d98201887 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use hir::{db::HirDatabase, Docs, HasSource, HirDisplay, ScopeDef, Ty, TypeWalk}; | 3 | use hir::{db::HirDatabase, Docs, HasSource, HirDisplay, ScopeDef, Ty, TypeWalk}; |
4 | use join_to_string::join; | 4 | use join_to_string::join; |
5 | use ra_syntax::ast::NameOwner; | 5 | use ra_syntax::ast::{AttrsOwner, NameOwner}; |
6 | use test_utils::tested_by; | 6 | use test_utils::tested_by; |
7 | 7 | ||
8 | use crate::completion::{ | 8 | use crate::completion::{ |
@@ -18,6 +18,11 @@ impl Completions { | |||
18 | field: hir::StructField, | 18 | field: hir::StructField, |
19 | substs: &hir::Substs, | 19 | substs: &hir::Substs, |
20 | ) { | 20 | ) { |
21 | let ast_node = field.source(ctx.db).ast; | ||
22 | let is_deprecated = match ast_node { | ||
23 | hir::FieldSource::Named(m) => is_deprecated(m), | ||
24 | hir::FieldSource::Pos(m) => is_deprecated(m), | ||
25 | }; | ||
21 | CompletionItem::new( | 26 | CompletionItem::new( |
22 | CompletionKind::Reference, | 27 | CompletionKind::Reference, |
23 | ctx.source_range(), | 28 | ctx.source_range(), |
@@ -26,6 +31,7 @@ impl Completions { | |||
26 | .kind(CompletionItemKind::Field) | 31 | .kind(CompletionItemKind::Field) |
27 | .detail(field.ty(ctx.db).subst(substs).display(ctx.db).to_string()) | 32 | .detail(field.ty(ctx.db).subst(substs).display(ctx.db).to_string()) |
28 | .set_documentation(field.docs(ctx.db)) | 33 | .set_documentation(field.docs(ctx.db)) |
34 | .set_deprecated(is_deprecated) | ||
29 | .add_to(self); | 35 | .add_to(self); |
30 | } | 36 | } |
31 | 37 | ||
@@ -179,6 +185,7 @@ impl Completions { | |||
179 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), ¯o_declaration) | 185 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), ¯o_declaration) |
180 | .kind(CompletionItemKind::Macro) | 186 | .kind(CompletionItemKind::Macro) |
181 | .set_documentation(docs.clone()) | 187 | .set_documentation(docs.clone()) |
188 | .set_deprecated(is_deprecated(ast_node)) | ||
182 | .detail(detail); | 189 | .detail(detail); |
183 | 190 | ||
184 | builder = if ctx.use_item_syntax.is_some() { | 191 | builder = if ctx.use_item_syntax.is_some() { |
@@ -211,6 +218,7 @@ impl Completions { | |||
211 | CompletionItemKind::Function | 218 | CompletionItemKind::Function |
212 | }) | 219 | }) |
213 | .set_documentation(func.docs(ctx.db)) | 220 | .set_documentation(func.docs(ctx.db)) |
221 | .set_deprecated(is_deprecated(ast_node)) | ||
214 | .detail(detail); | 222 | .detail(detail); |
215 | 223 | ||
216 | // Add `<>` for generic types | 224 | // Add `<>` for generic types |
@@ -242,6 +250,7 @@ impl Completions { | |||
242 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string()) | 250 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string()) |
243 | .kind(CompletionItemKind::Const) | 251 | .kind(CompletionItemKind::Const) |
244 | .set_documentation(constant.docs(ctx.db)) | 252 | .set_documentation(constant.docs(ctx.db)) |
253 | .set_deprecated(is_deprecated(ast_node)) | ||
245 | .detail(detail) | 254 | .detail(detail) |
246 | .add_to(self); | 255 | .add_to(self); |
247 | } | 256 | } |
@@ -257,11 +266,13 @@ impl Completions { | |||
257 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string()) | 266 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string()) |
258 | .kind(CompletionItemKind::TypeAlias) | 267 | .kind(CompletionItemKind::TypeAlias) |
259 | .set_documentation(type_alias.docs(ctx.db)) | 268 | .set_documentation(type_alias.docs(ctx.db)) |
269 | .set_deprecated(is_deprecated(type_def)) | ||
260 | .detail(detail) | 270 | .detail(detail) |
261 | .add_to(self); | 271 | .add_to(self); |
262 | } | 272 | } |
263 | 273 | ||
264 | pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) { | 274 | pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) { |
275 | let is_deprecated = is_deprecated(variant.source(ctx.db).ast); | ||
265 | let name = match variant.name(ctx.db) { | 276 | let name = match variant.name(ctx.db) { |
266 | Some(it) => it, | 277 | Some(it) => it, |
267 | None => return, | 278 | None => return, |
@@ -274,11 +285,16 @@ impl Completions { | |||
274 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string()) | 285 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string()) |
275 | .kind(CompletionItemKind::EnumVariant) | 286 | .kind(CompletionItemKind::EnumVariant) |
276 | .set_documentation(variant.docs(ctx.db)) | 287 | .set_documentation(variant.docs(ctx.db)) |
288 | .set_deprecated(is_deprecated) | ||
277 | .detail(detail) | 289 | .detail(detail) |
278 | .add_to(self); | 290 | .add_to(self); |
279 | } | 291 | } |
280 | } | 292 | } |
281 | 293 | ||
294 | fn is_deprecated(node: impl AttrsOwner) -> bool { | ||
295 | node.attrs().filter_map(|x| x.simple_name()).any(|x| x == "deprecated") | ||
296 | } | ||
297 | |||
282 | fn has_non_default_type_params(def: hir::GenericDef, db: &db::RootDatabase) -> bool { | 298 | fn has_non_default_type_params(def: hir::GenericDef, db: &db::RootDatabase) -> bool { |
283 | let subst = db.generic_defaults(def); | 299 | let subst = db.generic_defaults(def); |
284 | subst.iter().any(|ty| ty == &Ty::Unknown) | 300 | subst.iter().any(|ty| ty == &Ty::Unknown) |
@@ -296,6 +312,57 @@ mod tests { | |||
296 | } | 312 | } |
297 | 313 | ||
298 | #[test] | 314 | #[test] |
315 | fn sets_deprecated_flag_in_completion_items() { | ||
316 | assert_debug_snapshot!( | ||
317 | do_reference_completion( | ||
318 | r#" | ||
319 | #[deprecated] | ||
320 | fn something_deprecated() {} | ||
321 | |||
322 | #[deprecated(since = "1.0.0")] | ||
323 | fn something_else_deprecated() {} | ||
324 | |||
325 | fn main() { som<|> } | ||
326 | "#, | ||
327 | ), | ||
328 | @r###" | ||
329 | [ | ||
330 | CompletionItem { | ||
331 | label: "main()", | ||
332 | source_range: [203; 206), | ||
333 | delete: [203; 206), | ||
334 | insert: "main()$0", | ||
335 | kind: Function, | ||
336 | lookup: "main", | ||
337 | detail: "fn main()", | ||
338 | deprecated: false, | ||
339 | }, | ||
340 | CompletionItem { | ||
341 | label: "something_deprecated()", | ||
342 | source_range: [203; 206), | ||
343 | delete: [203; 206), | ||
344 | insert: "something_deprecated()$0", | ||
345 | kind: Function, | ||
346 | lookup: "something_deprecated", | ||
347 | detail: "fn something_deprecated()", | ||
348 | deprecated: true, | ||
349 | }, | ||
350 | CompletionItem { | ||
351 | label: "something_else_deprecated()", | ||
352 | source_range: [203; 206), | ||
353 | delete: [203; 206), | ||
354 | insert: "something_else_deprecated()$0", | ||
355 | kind: Function, | ||
356 | lookup: "something_else_deprecated", | ||
357 | detail: "fn something_else_deprecated()", | ||
358 | deprecated: true, | ||
359 | }, | ||
360 | ] | ||
361 | "### | ||
362 | ); | ||
363 | } | ||
364 | |||
365 | #[test] | ||
299 | fn inserts_parens_for_function_calls() { | 366 | fn inserts_parens_for_function_calls() { |
300 | covers!(inserts_parens_for_function_calls); | 367 | covers!(inserts_parens_for_function_calls); |
301 | assert_debug_snapshot!( | 368 | assert_debug_snapshot!( |
@@ -315,6 +382,7 @@ mod tests { | |||
315 | kind: Function, | 382 | kind: Function, |
316 | lookup: "main", | 383 | lookup: "main", |
317 | detail: "fn main()", | 384 | detail: "fn main()", |
385 | deprecated: false, | ||
318 | }, | 386 | }, |
319 | CompletionItem { | 387 | CompletionItem { |
320 | label: "no_args()", | 388 | label: "no_args()", |
@@ -324,6 +392,7 @@ mod tests { | |||
324 | kind: Function, | 392 | kind: Function, |
325 | lookup: "no_args", | 393 | lookup: "no_args", |
326 | detail: "fn no_args()", | 394 | detail: "fn no_args()", |
395 | deprecated: false, | ||
327 | }, | 396 | }, |
328 | ] | 397 | ] |
329 | "### | 398 | "### |
@@ -345,6 +414,7 @@ mod tests { | |||
345 | kind: Function, | 414 | kind: Function, |
346 | lookup: "main", | 415 | lookup: "main", |
347 | detail: "fn main()", | 416 | detail: "fn main()", |
417 | deprecated: false, | ||
348 | }, | 418 | }, |
349 | CompletionItem { | 419 | CompletionItem { |
350 | label: "with_args(…)", | 420 | label: "with_args(…)", |
@@ -354,6 +424,7 @@ mod tests { | |||
354 | kind: Function, | 424 | kind: Function, |
355 | lookup: "with_args", | 425 | lookup: "with_args", |
356 | detail: "fn with_args(x: i32, y: String)", | 426 | detail: "fn with_args(x: i32, y: String)", |
427 | deprecated: false, | ||
357 | }, | 428 | }, |
358 | ] | 429 | ] |
359 | "### | 430 | "### |
@@ -380,6 +451,7 @@ mod tests { | |||
380 | kind: Method, | 451 | kind: Method, |
381 | lookup: "foo", | 452 | lookup: "foo", |
382 | detail: "fn foo(&self)", | 453 | detail: "fn foo(&self)", |
454 | deprecated: false, | ||
383 | }, | 455 | }, |
384 | ] | 456 | ] |
385 | "### | 457 | "### |
@@ -404,6 +476,7 @@ mod tests { | |||
404 | insert: "foo", | 476 | insert: "foo", |
405 | kind: Function, | 477 | kind: Function, |
406 | detail: "pub fn foo()", | 478 | detail: "pub fn foo()", |
479 | deprecated: false, | ||
407 | }, | 480 | }, |
408 | ]"# | 481 | ]"# |
409 | ); | 482 | ); |
@@ -429,6 +502,7 @@ mod tests { | |||
429 | insert: "frobnicate", | 502 | insert: "frobnicate", |
430 | kind: Function, | 503 | kind: Function, |
431 | detail: "fn frobnicate()", | 504 | detail: "fn frobnicate()", |
505 | deprecated: false, | ||
432 | }, | 506 | }, |
433 | CompletionItem { | 507 | CompletionItem { |
434 | label: "main", | 508 | label: "main", |
@@ -437,6 +511,7 @@ mod tests { | |||
437 | insert: "main", | 511 | insert: "main", |
438 | kind: Function, | 512 | kind: Function, |
439 | detail: "fn main()", | 513 | detail: "fn main()", |
514 | deprecated: false, | ||
440 | }, | 515 | }, |
441 | ]"# | 516 | ]"# |
442 | ); | 517 | ); |
@@ -459,6 +534,7 @@ mod tests { | |||
459 | insert: "new", | 534 | insert: "new", |
460 | kind: Function, | 535 | kind: Function, |
461 | detail: "fn new() -> Foo", | 536 | detail: "fn new() -> Foo", |
537 | deprecated: false, | ||
462 | }, | 538 | }, |
463 | ]"# | 539 | ]"# |
464 | ); | 540 | ); |
@@ -492,6 +568,7 @@ mod tests { | |||
492 | kind: Function, | 568 | kind: Function, |
493 | lookup: "foo", | 569 | lookup: "foo", |
494 | detail: "fn foo(xs: Ve)", | 570 | detail: "fn foo(xs: Ve)", |
571 | deprecated: false, | ||
495 | }, | 572 | }, |
496 | ] | 573 | ] |
497 | "### | 574 | "### |
@@ -521,6 +598,7 @@ mod tests { | |||
521 | kind: Function, | 598 | kind: Function, |
522 | lookup: "foo", | 599 | lookup: "foo", |
523 | detail: "fn foo(xs: Ve)", | 600 | detail: "fn foo(xs: Ve)", |
601 | deprecated: false, | ||
524 | }, | 602 | }, |
525 | ] | 603 | ] |
526 | "### | 604 | "### |
@@ -549,6 +627,7 @@ mod tests { | |||
549 | kind: Function, | 627 | kind: Function, |
550 | lookup: "foo", | 628 | lookup: "foo", |
551 | detail: "fn foo(xs: Ve)", | 629 | detail: "fn foo(xs: Ve)", |
630 | deprecated: false, | ||
552 | }, | 631 | }, |
553 | ] | 632 | ] |
554 | "### | 633 | "### |
@@ -577,6 +656,7 @@ mod tests { | |||
577 | kind: Function, | 656 | kind: Function, |
578 | lookup: "foo", | 657 | lookup: "foo", |
579 | detail: "fn foo(xs: Ve<i128>)", | 658 | detail: "fn foo(xs: Ve<i128>)", |
659 | deprecated: false, | ||
580 | }, | 660 | }, |
581 | ] | 661 | ] |
582 | "### | 662 | "### |
@@ -607,6 +687,7 @@ mod tests { | |||
607 | insert: "frobnicate", | 687 | insert: "frobnicate", |
608 | kind: Macro, | 688 | kind: Macro, |
609 | detail: "#[macro_export]\nmacro_rules! frobnicate", | 689 | detail: "#[macro_export]\nmacro_rules! frobnicate", |
690 | deprecated: false, | ||
610 | }, | 691 | }, |
611 | ] | 692 | ] |
612 | "### | 693 | "### |