diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-06-22 13:13:18 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-06-22 13:13:18 +0100 |
commit | d8842e89e9053b62c081d2995cbf43b8fd5c51b2 (patch) | |
tree | c4c4c7f99efdcd289038fbd91dc7578dc7a494a2 /crates/ra_ide | |
parent | d144d69d2eded43a59c8edb59419b1b9e85c10a5 (diff) | |
parent | 5aad6c9fa69915c4810a8e93d793d76de211f2ca (diff) |
Merge #4899
4899: don't complete top level attrs inside nested attrs and add better labels r=matklad a=bnjjj
close #4890
Co-authored-by: Benjamin Coenen <[email protected]>
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/completion/complete_attribute.rs | 278 |
1 files changed, 206 insertions, 72 deletions
diff --git a/crates/ra_ide/src/completion/complete_attribute.rs b/crates/ra_ide/src/completion/complete_attribute.rs index fb3f0b743..ade17a1ff 100644 --- a/crates/ra_ide/src/completion/complete_attribute.rs +++ b/crates/ra_ide/src/completion/complete_attribute.rs | |||
@@ -20,6 +20,7 @@ pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) | |||
20 | { | 20 | { |
21 | complete_derive(acc, ctx, token_tree) | 21 | complete_derive(acc, ctx, token_tree) |
22 | } | 22 | } |
23 | (_, Some(ast::AttrInput::TokenTree(_token_tree))) => {} | ||
23 | _ => complete_attribute_start(acc, ctx, attribute), | 24 | _ => complete_attribute_start(acc, ctx, attribute), |
24 | } | 25 | } |
25 | Some(()) | 26 | Some(()) |
@@ -34,6 +35,10 @@ fn complete_attribute_start(acc: &mut Completions, ctx: &CompletionContext, attr | |||
34 | ) | 35 | ) |
35 | .kind(CompletionItemKind::Attribute); | 36 | .kind(CompletionItemKind::Attribute); |
36 | 37 | ||
38 | if let Some(lookup) = attr_completion.lookup { | ||
39 | item = item.lookup_by(lookup); | ||
40 | } | ||
41 | |||
37 | match (attr_completion.snippet, ctx.config.snippet_cap) { | 42 | match (attr_completion.snippet, ctx.config.snippet_cap) { |
38 | (Some(snippet), Some(cap)) => { | 43 | (Some(snippet), Some(cap)) => { |
39 | item = item.insert_snippet(cap, snippet); | 44 | item = item.insert_snippet(cap, snippet); |
@@ -49,84 +54,160 @@ fn complete_attribute_start(acc: &mut Completions, ctx: &CompletionContext, attr | |||
49 | 54 | ||
50 | struct AttrCompletion { | 55 | struct AttrCompletion { |
51 | label: &'static str, | 56 | label: &'static str, |
57 | lookup: Option<&'static str>, | ||
52 | snippet: Option<&'static str>, | 58 | snippet: Option<&'static str>, |
53 | should_be_inner: bool, | 59 | should_be_inner: bool, |
54 | } | 60 | } |
55 | 61 | ||
56 | const ATTRIBUTES: &[AttrCompletion] = &[ | 62 | const ATTRIBUTES: &[AttrCompletion] = &[ |
57 | AttrCompletion { label: "allow", snippet: Some("allow(${0:lint})"), should_be_inner: false }, | ||
58 | AttrCompletion { | 63 | AttrCompletion { |
59 | label: "cfg_attr", | 64 | label: "allow(…)", |
65 | snippet: Some("allow(${0:lint})"), | ||
66 | should_be_inner: false, | ||
67 | lookup: Some("allow"), | ||
68 | }, | ||
69 | AttrCompletion { | ||
70 | label: "cfg_attr(…)", | ||
60 | snippet: Some("cfg_attr(${1:predicate}, ${0:attr})"), | 71 | snippet: Some("cfg_attr(${1:predicate}, ${0:attr})"), |
61 | should_be_inner: false, | 72 | should_be_inner: false, |
73 | lookup: Some("cfg_attr"), | ||
62 | }, | 74 | }, |
63 | AttrCompletion { label: "cfg", snippet: Some("cfg(${0:predicate})"), should_be_inner: false }, | ||
64 | AttrCompletion { label: "deny", snippet: Some("deny(${0:lint})"), should_be_inner: false }, | ||
65 | AttrCompletion { | 75 | AttrCompletion { |
66 | label: "deprecated", | 76 | label: "cfg(…)", |
77 | snippet: Some("cfg(${0:predicate})"), | ||
78 | should_be_inner: false, | ||
79 | lookup: Some("cfg"), | ||
80 | }, | ||
81 | AttrCompletion { | ||
82 | label: "deny(…)", | ||
83 | snippet: Some("deny(${0:lint})"), | ||
84 | should_be_inner: false, | ||
85 | lookup: Some("deny"), | ||
86 | }, | ||
87 | AttrCompletion { | ||
88 | label: r#"deprecated = "…""#, | ||
67 | snippet: Some(r#"deprecated = "${0:reason}""#), | 89 | snippet: Some(r#"deprecated = "${0:reason}""#), |
68 | should_be_inner: false, | 90 | should_be_inner: false, |
91 | lookup: Some("deprecated"), | ||
69 | }, | 92 | }, |
70 | AttrCompletion { | 93 | AttrCompletion { |
71 | label: "derive", | 94 | label: "derive(…)", |
72 | snippet: Some(r#"derive(${0:Debug})"#), | 95 | snippet: Some(r#"derive(${0:Debug})"#), |
73 | should_be_inner: false, | 96 | should_be_inner: false, |
97 | lookup: Some("derive"), | ||
98 | }, | ||
99 | AttrCompletion { | ||
100 | label: r#"doc = "…""#, | ||
101 | snippet: Some(r#"doc = "${0:docs}""#), | ||
102 | should_be_inner: false, | ||
103 | lookup: Some("doc"), | ||
104 | }, | ||
105 | AttrCompletion { | ||
106 | label: "feature(…)", | ||
107 | snippet: Some("feature(${0:flag})"), | ||
108 | should_be_inner: true, | ||
109 | lookup: Some("feature"), | ||
110 | }, | ||
111 | AttrCompletion { | ||
112 | label: "forbid(…)", | ||
113 | snippet: Some("forbid(${0:lint})"), | ||
114 | should_be_inner: false, | ||
115 | lookup: Some("forbid"), | ||
74 | }, | 116 | }, |
75 | AttrCompletion { label: "doc", snippet: Some(r#"doc = "${0:docs}""#), should_be_inner: false }, | ||
76 | AttrCompletion { label: "feature", snippet: Some("feature(${0:flag})"), should_be_inner: true }, | ||
77 | AttrCompletion { label: "forbid", snippet: Some("forbid(${0:lint})"), should_be_inner: false }, | ||
78 | // FIXME: resolve through macro resolution? | 117 | // FIXME: resolve through macro resolution? |
79 | AttrCompletion { label: "global_allocator", snippet: None, should_be_inner: true }, | ||
80 | AttrCompletion { label: "ignore", snippet: Some("ignore(${0:lint})"), should_be_inner: false }, | ||
81 | AttrCompletion { label: "inline", snippet: Some("inline(${0:lint})"), should_be_inner: false }, | ||
82 | AttrCompletion { | 118 | AttrCompletion { |
83 | label: "link_name", | 119 | label: "global_allocator", |
120 | snippet: None, | ||
121 | should_be_inner: true, | ||
122 | lookup: None, | ||
123 | }, | ||
124 | AttrCompletion { | ||
125 | label: "ignore(…)", | ||
126 | snippet: Some("ignore(${0:lint})"), | ||
127 | should_be_inner: false, | ||
128 | lookup: Some("ignore"), | ||
129 | }, | ||
130 | AttrCompletion { | ||
131 | label: "inline(…)", | ||
132 | snippet: Some("inline(${0:lint})"), | ||
133 | should_be_inner: false, | ||
134 | lookup: Some("inline"), | ||
135 | }, | ||
136 | AttrCompletion { | ||
137 | label: r#"link_name = "…""#, | ||
84 | snippet: Some(r#"link_name = "${0:symbol_name}""#), | 138 | snippet: Some(r#"link_name = "${0:symbol_name}""#), |
85 | should_be_inner: false, | 139 | should_be_inner: false, |
140 | lookup: Some("link_name"), | ||
86 | }, | 141 | }, |
87 | AttrCompletion { label: "link", snippet: None, should_be_inner: false }, | 142 | AttrCompletion { label: "link", snippet: None, should_be_inner: false, lookup: None }, |
88 | AttrCompletion { label: "macro_export", snippet: None, should_be_inner: false }, | 143 | AttrCompletion { label: "macro_export", snippet: None, should_be_inner: false, lookup: None }, |
89 | AttrCompletion { label: "macro_use", snippet: None, should_be_inner: false }, | 144 | AttrCompletion { label: "macro_use", snippet: None, should_be_inner: false, lookup: None }, |
90 | AttrCompletion { | 145 | AttrCompletion { |
91 | label: "must_use", | 146 | label: r#"must_use = "…""#, |
92 | snippet: Some(r#"must_use = "${0:reason}""#), | 147 | snippet: Some(r#"must_use = "${0:reason}""#), |
93 | should_be_inner: false, | 148 | should_be_inner: false, |
149 | lookup: Some("must_use"), | ||
94 | }, | 150 | }, |
95 | AttrCompletion { label: "no_mangle", snippet: None, should_be_inner: false }, | 151 | AttrCompletion { label: "no_mangle", snippet: None, should_be_inner: false, lookup: None }, |
96 | AttrCompletion { label: "no_std", snippet: None, should_be_inner: true }, | 152 | AttrCompletion { label: "no_std", snippet: None, should_be_inner: true, lookup: None }, |
97 | AttrCompletion { label: "non_exhaustive", snippet: None, should_be_inner: false }, | 153 | AttrCompletion { label: "non_exhaustive", snippet: None, should_be_inner: false, lookup: None }, |
98 | AttrCompletion { label: "panic_handler", snippet: None, should_be_inner: true }, | 154 | AttrCompletion { label: "panic_handler", snippet: None, should_be_inner: true, lookup: None }, |
99 | AttrCompletion { label: "path", snippet: Some("path =\"${0:path}\""), should_be_inner: false }, | ||
100 | AttrCompletion { label: "proc_macro", snippet: None, should_be_inner: false }, | ||
101 | AttrCompletion { label: "proc_macro_attribute", snippet: None, should_be_inner: false }, | ||
102 | AttrCompletion { | 155 | AttrCompletion { |
103 | label: "proc_macro_derive", | 156 | label: "path = \"…\"", |
157 | snippet: Some("path =\"${0:path}\""), | ||
158 | should_be_inner: false, | ||
159 | lookup: Some("path"), | ||
160 | }, | ||
161 | AttrCompletion { label: "proc_macro", snippet: None, should_be_inner: false, lookup: None }, | ||
162 | AttrCompletion { | ||
163 | label: "proc_macro_attribute", | ||
164 | snippet: None, | ||
165 | should_be_inner: false, | ||
166 | lookup: None, | ||
167 | }, | ||
168 | AttrCompletion { | ||
169 | label: "proc_macro_derive(…)", | ||
104 | snippet: Some("proc_macro_derive(${0:Trait})"), | 170 | snippet: Some("proc_macro_derive(${0:Trait})"), |
105 | should_be_inner: false, | 171 | should_be_inner: false, |
172 | lookup: Some("proc_macro_derive"), | ||
106 | }, | 173 | }, |
107 | AttrCompletion { | 174 | AttrCompletion { |
108 | label: "recursion_limit", | 175 | label: "recursion_limit = …", |
109 | snippet: Some("recursion_limit = ${0:128}"), | 176 | snippet: Some("recursion_limit = ${0:128}"), |
110 | should_be_inner: true, | 177 | should_be_inner: true, |
178 | lookup: Some("recursion_limit"), | ||
179 | }, | ||
180 | AttrCompletion { | ||
181 | label: "repr(…)", | ||
182 | snippet: Some("repr(${0:C})"), | ||
183 | should_be_inner: false, | ||
184 | lookup: Some("repr"), | ||
111 | }, | 185 | }, |
112 | AttrCompletion { label: "repr", snippet: Some("repr(${0:C})"), should_be_inner: false }, | ||
113 | AttrCompletion { | 186 | AttrCompletion { |
114 | label: "should_panic", | 187 | label: "should_panic(…)", |
115 | snippet: Some(r#"should_panic(expected = "${0:reason}")"#), | 188 | snippet: Some(r#"should_panic(expected = "${0:reason}")"#), |
116 | should_be_inner: false, | 189 | should_be_inner: false, |
190 | lookup: Some("should_panic"), | ||
117 | }, | 191 | }, |
118 | AttrCompletion { | 192 | AttrCompletion { |
119 | label: "target_feature", | 193 | label: r#"target_feature = "…""#, |
120 | snippet: Some("target_feature = \"${0:feature}\""), | 194 | snippet: Some("target_feature = \"${0:feature}\""), |
121 | should_be_inner: false, | 195 | should_be_inner: false, |
196 | lookup: Some("target_feature"), | ||
197 | }, | ||
198 | AttrCompletion { label: "test", snippet: None, should_be_inner: false, lookup: None }, | ||
199 | AttrCompletion { label: "used", snippet: None, should_be_inner: false, lookup: None }, | ||
200 | AttrCompletion { | ||
201 | label: "warn(…)", | ||
202 | snippet: Some("warn(${0:lint})"), | ||
203 | should_be_inner: false, | ||
204 | lookup: Some("warn"), | ||
122 | }, | 205 | }, |
123 | AttrCompletion { label: "test", snippet: None, should_be_inner: false }, | ||
124 | AttrCompletion { label: "used", snippet: None, should_be_inner: false }, | ||
125 | AttrCompletion { label: "warn", snippet: Some("warn(${0:lint})"), should_be_inner: false }, | ||
126 | AttrCompletion { | 206 | AttrCompletion { |
127 | label: "windows_subsystem", | 207 | label: r#"windows_subsystem = "…""#, |
128 | snippet: Some(r#"windows_subsystem = "${0:subsystem}""#), | 208 | snippet: Some(r#"windows_subsystem = "${0:subsystem}""#), |
129 | should_be_inner: true, | 209 | should_be_inner: true, |
210 | lookup: Some("windows_subsystem"), | ||
130 | }, | 211 | }, |
131 | ]; | 212 | ]; |
132 | 213 | ||
@@ -414,74 +495,84 @@ mod tests { | |||
414 | @r###" | 495 | @r###" |
415 | [ | 496 | [ |
416 | CompletionItem { | 497 | CompletionItem { |
417 | label: "allow", | 498 | label: "allow(…)", |
418 | source_range: 19..19, | 499 | source_range: 19..19, |
419 | delete: 19..19, | 500 | delete: 19..19, |
420 | insert: "allow(${0:lint})", | 501 | insert: "allow(${0:lint})", |
421 | kind: Attribute, | 502 | kind: Attribute, |
503 | lookup: "allow", | ||
422 | }, | 504 | }, |
423 | CompletionItem { | 505 | CompletionItem { |
424 | label: "cfg", | 506 | label: "cfg(…)", |
425 | source_range: 19..19, | 507 | source_range: 19..19, |
426 | delete: 19..19, | 508 | delete: 19..19, |
427 | insert: "cfg(${0:predicate})", | 509 | insert: "cfg(${0:predicate})", |
428 | kind: Attribute, | 510 | kind: Attribute, |
511 | lookup: "cfg", | ||
429 | }, | 512 | }, |
430 | CompletionItem { | 513 | CompletionItem { |
431 | label: "cfg_attr", | 514 | label: "cfg_attr(…)", |
432 | source_range: 19..19, | 515 | source_range: 19..19, |
433 | delete: 19..19, | 516 | delete: 19..19, |
434 | insert: "cfg_attr(${1:predicate}, ${0:attr})", | 517 | insert: "cfg_attr(${1:predicate}, ${0:attr})", |
435 | kind: Attribute, | 518 | kind: Attribute, |
519 | lookup: "cfg_attr", | ||
436 | }, | 520 | }, |
437 | CompletionItem { | 521 | CompletionItem { |
438 | label: "deny", | 522 | label: "deny(…)", |
439 | source_range: 19..19, | 523 | source_range: 19..19, |
440 | delete: 19..19, | 524 | delete: 19..19, |
441 | insert: "deny(${0:lint})", | 525 | insert: "deny(${0:lint})", |
442 | kind: Attribute, | 526 | kind: Attribute, |
527 | lookup: "deny", | ||
443 | }, | 528 | }, |
444 | CompletionItem { | 529 | CompletionItem { |
445 | label: "deprecated", | 530 | label: "deprecated = \"…\"", |
446 | source_range: 19..19, | 531 | source_range: 19..19, |
447 | delete: 19..19, | 532 | delete: 19..19, |
448 | insert: "deprecated = \"${0:reason}\"", | 533 | insert: "deprecated = \"${0:reason}\"", |
449 | kind: Attribute, | 534 | kind: Attribute, |
535 | lookup: "deprecated", | ||
450 | }, | 536 | }, |
451 | CompletionItem { | 537 | CompletionItem { |
452 | label: "derive", | 538 | label: "derive(…)", |
453 | source_range: 19..19, | 539 | source_range: 19..19, |
454 | delete: 19..19, | 540 | delete: 19..19, |
455 | insert: "derive(${0:Debug})", | 541 | insert: "derive(${0:Debug})", |
456 | kind: Attribute, | 542 | kind: Attribute, |
543 | lookup: "derive", | ||
457 | }, | 544 | }, |
458 | CompletionItem { | 545 | CompletionItem { |
459 | label: "doc", | 546 | label: "doc = \"…\"", |
460 | source_range: 19..19, | 547 | source_range: 19..19, |
461 | delete: 19..19, | 548 | delete: 19..19, |
462 | insert: "doc = \"${0:docs}\"", | 549 | insert: "doc = \"${0:docs}\"", |
463 | kind: Attribute, | 550 | kind: Attribute, |
551 | lookup: "doc", | ||
464 | }, | 552 | }, |
465 | CompletionItem { | 553 | CompletionItem { |
466 | label: "forbid", | 554 | label: "forbid(…)", |
467 | source_range: 19..19, | 555 | source_range: 19..19, |
468 | delete: 19..19, | 556 | delete: 19..19, |
469 | insert: "forbid(${0:lint})", | 557 | insert: "forbid(${0:lint})", |
470 | kind: Attribute, | 558 | kind: Attribute, |
559 | lookup: "forbid", | ||
471 | }, | 560 | }, |
472 | CompletionItem { | 561 | CompletionItem { |
473 | label: "ignore", | 562 | label: "ignore(…)", |
474 | source_range: 19..19, | 563 | source_range: 19..19, |
475 | delete: 19..19, | 564 | delete: 19..19, |
476 | insert: "ignore(${0:lint})", | 565 | insert: "ignore(${0:lint})", |
477 | kind: Attribute, | 566 | kind: Attribute, |
567 | lookup: "ignore", | ||
478 | }, | 568 | }, |
479 | CompletionItem { | 569 | CompletionItem { |
480 | label: "inline", | 570 | label: "inline(…)", |
481 | source_range: 19..19, | 571 | source_range: 19..19, |
482 | delete: 19..19, | 572 | delete: 19..19, |
483 | insert: "inline(${0:lint})", | 573 | insert: "inline(${0:lint})", |
484 | kind: Attribute, | 574 | kind: Attribute, |
575 | lookup: "inline", | ||
485 | }, | 576 | }, |
486 | CompletionItem { | 577 | CompletionItem { |
487 | label: "link", | 578 | label: "link", |
@@ -491,11 +582,12 @@ mod tests { | |||
491 | kind: Attribute, | 582 | kind: Attribute, |
492 | }, | 583 | }, |
493 | CompletionItem { | 584 | CompletionItem { |
494 | label: "link_name", | 585 | label: "link_name = \"…\"", |
495 | source_range: 19..19, | 586 | source_range: 19..19, |
496 | delete: 19..19, | 587 | delete: 19..19, |
497 | insert: "link_name = \"${0:symbol_name}\"", | 588 | insert: "link_name = \"${0:symbol_name}\"", |
498 | kind: Attribute, | 589 | kind: Attribute, |
590 | lookup: "link_name", | ||
499 | }, | 591 | }, |
500 | CompletionItem { | 592 | CompletionItem { |
501 | label: "macro_export", | 593 | label: "macro_export", |
@@ -512,11 +604,12 @@ mod tests { | |||
512 | kind: Attribute, | 604 | kind: Attribute, |
513 | }, | 605 | }, |
514 | CompletionItem { | 606 | CompletionItem { |
515 | label: "must_use", | 607 | label: "must_use = \"…\"", |
516 | source_range: 19..19, | 608 | source_range: 19..19, |
517 | delete: 19..19, | 609 | delete: 19..19, |
518 | insert: "must_use = \"${0:reason}\"", | 610 | insert: "must_use = \"${0:reason}\"", |
519 | kind: Attribute, | 611 | kind: Attribute, |
612 | lookup: "must_use", | ||
520 | }, | 613 | }, |
521 | CompletionItem { | 614 | CompletionItem { |
522 | label: "no_mangle", | 615 | label: "no_mangle", |
@@ -533,11 +626,12 @@ mod tests { | |||
533 | kind: Attribute, | 626 | kind: Attribute, |
534 | }, | 627 | }, |
535 | CompletionItem { | 628 | CompletionItem { |
536 | label: "path", | 629 | label: "path = \"…\"", |
537 | source_range: 19..19, | 630 | source_range: 19..19, |
538 | delete: 19..19, | 631 | delete: 19..19, |
539 | insert: "path =\"${0:path}\"", | 632 | insert: "path =\"${0:path}\"", |
540 | kind: Attribute, | 633 | kind: Attribute, |
634 | lookup: "path", | ||
541 | }, | 635 | }, |
542 | CompletionItem { | 636 | CompletionItem { |
543 | label: "proc_macro", | 637 | label: "proc_macro", |
@@ -554,32 +648,36 @@ mod tests { | |||
554 | kind: Attribute, | 648 | kind: Attribute, |
555 | }, | 649 | }, |
556 | CompletionItem { | 650 | CompletionItem { |
557 | label: "proc_macro_derive", | 651 | label: "proc_macro_derive(…)", |
558 | source_range: 19..19, | 652 | source_range: 19..19, |
559 | delete: 19..19, | 653 | delete: 19..19, |
560 | insert: "proc_macro_derive(${0:Trait})", | 654 | insert: "proc_macro_derive(${0:Trait})", |
561 | kind: Attribute, | 655 | kind: Attribute, |
656 | lookup: "proc_macro_derive", | ||
562 | }, | 657 | }, |
563 | CompletionItem { | 658 | CompletionItem { |
564 | label: "repr", | 659 | label: "repr(…)", |
565 | source_range: 19..19, | 660 | source_range: 19..19, |
566 | delete: 19..19, | 661 | delete: 19..19, |
567 | insert: "repr(${0:C})", | 662 | insert: "repr(${0:C})", |
568 | kind: Attribute, | 663 | kind: Attribute, |
664 | lookup: "repr", | ||
569 | }, | 665 | }, |
570 | CompletionItem { | 666 | CompletionItem { |
571 | label: "should_panic", | 667 | label: "should_panic(…)", |
572 | source_range: 19..19, | 668 | source_range: 19..19, |
573 | delete: 19..19, | 669 | delete: 19..19, |
574 | insert: "should_panic(expected = \"${0:reason}\")", | 670 | insert: "should_panic(expected = \"${0:reason}\")", |
575 | kind: Attribute, | 671 | kind: Attribute, |
672 | lookup: "should_panic", | ||
576 | }, | 673 | }, |
577 | CompletionItem { | 674 | CompletionItem { |
578 | label: "target_feature", | 675 | label: "target_feature = \"…\"", |
579 | source_range: 19..19, | 676 | source_range: 19..19, |
580 | delete: 19..19, | 677 | delete: 19..19, |
581 | insert: "target_feature = \"${0:feature}\"", | 678 | insert: "target_feature = \"${0:feature}\"", |
582 | kind: Attribute, | 679 | kind: Attribute, |
680 | lookup: "target_feature", | ||
583 | }, | 681 | }, |
584 | CompletionItem { | 682 | CompletionItem { |
585 | label: "test", | 683 | label: "test", |
@@ -596,11 +694,12 @@ mod tests { | |||
596 | kind: Attribute, | 694 | kind: Attribute, |
597 | }, | 695 | }, |
598 | CompletionItem { | 696 | CompletionItem { |
599 | label: "warn", | 697 | label: "warn(…)", |
600 | source_range: 19..19, | 698 | source_range: 19..19, |
601 | delete: 19..19, | 699 | delete: 19..19, |
602 | insert: "warn(${0:lint})", | 700 | insert: "warn(${0:lint})", |
603 | kind: Attribute, | 701 | kind: Attribute, |
702 | lookup: "warn", | ||
604 | }, | 703 | }, |
605 | ] | 704 | ] |
606 | "### | 705 | "### |
@@ -608,6 +707,20 @@ mod tests { | |||
608 | } | 707 | } |
609 | 708 | ||
610 | #[test] | 709 | #[test] |
710 | fn test_attribute_completion_inside_nested_attr() { | ||
711 | assert_debug_snapshot!( | ||
712 | do_attr_completion( | ||
713 | r" | ||
714 | #[allow(<|>)] | ||
715 | ", | ||
716 | ), | ||
717 | @r###" | ||
718 | [] | ||
719 | "### | ||
720 | ); | ||
721 | } | ||
722 | |||
723 | #[test] | ||
611 | fn test_inner_attribute_completion() { | 724 | fn test_inner_attribute_completion() { |
612 | assert_debug_snapshot!( | 725 | assert_debug_snapshot!( |
613 | do_attr_completion( | 726 | do_attr_completion( |
@@ -618,67 +731,76 @@ mod tests { | |||
618 | @r###" | 731 | @r###" |
619 | [ | 732 | [ |
620 | CompletionItem { | 733 | CompletionItem { |
621 | label: "allow", | 734 | label: "allow(…)", |
622 | source_range: 20..20, | 735 | source_range: 20..20, |
623 | delete: 20..20, | 736 | delete: 20..20, |
624 | insert: "allow(${0:lint})", | 737 | insert: "allow(${0:lint})", |
625 | kind: Attribute, | 738 | kind: Attribute, |
739 | lookup: "allow", | ||
626 | }, | 740 | }, |
627 | CompletionItem { | 741 | CompletionItem { |
628 | label: "cfg", | 742 | label: "cfg(…)", |
629 | source_range: 20..20, | 743 | source_range: 20..20, |
630 | delete: 20..20, | 744 | delete: 20..20, |
631 | insert: "cfg(${0:predicate})", | 745 | insert: "cfg(${0:predicate})", |
632 | kind: Attribute, | 746 | kind: Attribute, |
747 | lookup: "cfg", | ||
633 | }, | 748 | }, |
634 | CompletionItem { | 749 | CompletionItem { |
635 | label: "cfg_attr", | 750 | label: "cfg_attr(…)", |
636 | source_range: 20..20, | 751 | source_range: 20..20, |
637 | delete: 20..20, | 752 | delete: 20..20, |
638 | insert: "cfg_attr(${1:predicate}, ${0:attr})", | 753 | insert: "cfg_attr(${1:predicate}, ${0:attr})", |
639 | kind: Attribute, | 754 | kind: Attribute, |
755 | lookup: "cfg_attr", | ||
640 | }, | 756 | }, |
641 | CompletionItem { | 757 | CompletionItem { |
642 | label: "deny", | 758 | label: "deny(…)", |
643 | source_range: 20..20, | 759 | source_range: 20..20, |
644 | delete: 20..20, | 760 | delete: 20..20, |
645 | insert: "deny(${0:lint})", | 761 | insert: "deny(${0:lint})", |
646 | kind: Attribute, | 762 | kind: Attribute, |
763 | lookup: "deny", | ||
647 | }, | 764 | }, |
648 | CompletionItem { | 765 | CompletionItem { |
649 | label: "deprecated", | 766 | label: "deprecated = \"…\"", |
650 | source_range: 20..20, | 767 | source_range: 20..20, |
651 | delete: 20..20, | 768 | delete: 20..20, |
652 | insert: "deprecated = \"${0:reason}\"", | 769 | insert: "deprecated = \"${0:reason}\"", |
653 | kind: Attribute, | 770 | kind: Attribute, |
771 | lookup: "deprecated", | ||
654 | }, | 772 | }, |
655 | CompletionItem { | 773 | CompletionItem { |
656 | label: "derive", | 774 | label: "derive(…)", |
657 | source_range: 20..20, | 775 | source_range: 20..20, |
658 | delete: 20..20, | 776 | delete: 20..20, |
659 | insert: "derive(${0:Debug})", | 777 | insert: "derive(${0:Debug})", |
660 | kind: Attribute, | 778 | kind: Attribute, |
779 | lookup: "derive", | ||
661 | }, | 780 | }, |
662 | CompletionItem { | 781 | CompletionItem { |
663 | label: "doc", | 782 | label: "doc = \"…\"", |
664 | source_range: 20..20, | 783 | source_range: 20..20, |
665 | delete: 20..20, | 784 | delete: 20..20, |
666 | insert: "doc = \"${0:docs}\"", | 785 | insert: "doc = \"${0:docs}\"", |
667 | kind: Attribute, | 786 | kind: Attribute, |
787 | lookup: "doc", | ||
668 | }, | 788 | }, |
669 | CompletionItem { | 789 | CompletionItem { |
670 | label: "feature", | 790 | label: "feature(…)", |
671 | source_range: 20..20, | 791 | source_range: 20..20, |
672 | delete: 20..20, | 792 | delete: 20..20, |
673 | insert: "feature(${0:flag})", | 793 | insert: "feature(${0:flag})", |
674 | kind: Attribute, | 794 | kind: Attribute, |
795 | lookup: "feature", | ||
675 | }, | 796 | }, |
676 | CompletionItem { | 797 | CompletionItem { |
677 | label: "forbid", | 798 | label: "forbid(…)", |
678 | source_range: 20..20, | 799 | source_range: 20..20, |
679 | delete: 20..20, | 800 | delete: 20..20, |
680 | insert: "forbid(${0:lint})", | 801 | insert: "forbid(${0:lint})", |
681 | kind: Attribute, | 802 | kind: Attribute, |
803 | lookup: "forbid", | ||
682 | }, | 804 | }, |
683 | CompletionItem { | 805 | CompletionItem { |
684 | label: "global_allocator", | 806 | label: "global_allocator", |
@@ -688,18 +810,20 @@ mod tests { | |||
688 | kind: Attribute, | 810 | kind: Attribute, |
689 | }, | 811 | }, |
690 | CompletionItem { | 812 | CompletionItem { |
691 | label: "ignore", | 813 | label: "ignore(…)", |
692 | source_range: 20..20, | 814 | source_range: 20..20, |
693 | delete: 20..20, | 815 | delete: 20..20, |
694 | insert: "ignore(${0:lint})", | 816 | insert: "ignore(${0:lint})", |
695 | kind: Attribute, | 817 | kind: Attribute, |
818 | lookup: "ignore", | ||
696 | }, | 819 | }, |
697 | CompletionItem { | 820 | CompletionItem { |
698 | label: "inline", | 821 | label: "inline(…)", |
699 | source_range: 20..20, | 822 | source_range: 20..20, |
700 | delete: 20..20, | 823 | delete: 20..20, |
701 | insert: "inline(${0:lint})", | 824 | insert: "inline(${0:lint})", |
702 | kind: Attribute, | 825 | kind: Attribute, |
826 | lookup: "inline", | ||
703 | }, | 827 | }, |
704 | CompletionItem { | 828 | CompletionItem { |
705 | label: "link", | 829 | label: "link", |
@@ -709,11 +833,12 @@ mod tests { | |||
709 | kind: Attribute, | 833 | kind: Attribute, |
710 | }, | 834 | }, |
711 | CompletionItem { | 835 | CompletionItem { |
712 | label: "link_name", | 836 | label: "link_name = \"…\"", |
713 | source_range: 20..20, | 837 | source_range: 20..20, |
714 | delete: 20..20, | 838 | delete: 20..20, |
715 | insert: "link_name = \"${0:symbol_name}\"", | 839 | insert: "link_name = \"${0:symbol_name}\"", |
716 | kind: Attribute, | 840 | kind: Attribute, |
841 | lookup: "link_name", | ||
717 | }, | 842 | }, |
718 | CompletionItem { | 843 | CompletionItem { |
719 | label: "macro_export", | 844 | label: "macro_export", |
@@ -730,11 +855,12 @@ mod tests { | |||
730 | kind: Attribute, | 855 | kind: Attribute, |
731 | }, | 856 | }, |
732 | CompletionItem { | 857 | CompletionItem { |
733 | label: "must_use", | 858 | label: "must_use = \"…\"", |
734 | source_range: 20..20, | 859 | source_range: 20..20, |
735 | delete: 20..20, | 860 | delete: 20..20, |
736 | insert: "must_use = \"${0:reason}\"", | 861 | insert: "must_use = \"${0:reason}\"", |
737 | kind: Attribute, | 862 | kind: Attribute, |
863 | lookup: "must_use", | ||
738 | }, | 864 | }, |
739 | CompletionItem { | 865 | CompletionItem { |
740 | label: "no_mangle", | 866 | label: "no_mangle", |
@@ -765,11 +891,12 @@ mod tests { | |||
765 | kind: Attribute, | 891 | kind: Attribute, |
766 | }, | 892 | }, |
767 | CompletionItem { | 893 | CompletionItem { |
768 | label: "path", | 894 | label: "path = \"…\"", |
769 | source_range: 20..20, | 895 | source_range: 20..20, |
770 | delete: 20..20, | 896 | delete: 20..20, |
771 | insert: "path =\"${0:path}\"", | 897 | insert: "path =\"${0:path}\"", |
772 | kind: Attribute, | 898 | kind: Attribute, |
899 | lookup: "path", | ||
773 | }, | 900 | }, |
774 | CompletionItem { | 901 | CompletionItem { |
775 | label: "proc_macro", | 902 | label: "proc_macro", |
@@ -786,39 +913,44 @@ mod tests { | |||
786 | kind: Attribute, | 913 | kind: Attribute, |
787 | }, | 914 | }, |
788 | CompletionItem { | 915 | CompletionItem { |
789 | label: "proc_macro_derive", | 916 | label: "proc_macro_derive(…)", |
790 | source_range: 20..20, | 917 | source_range: 20..20, |
791 | delete: 20..20, | 918 | delete: 20..20, |
792 | insert: "proc_macro_derive(${0:Trait})", | 919 | insert: "proc_macro_derive(${0:Trait})", |
793 | kind: Attribute, | 920 | kind: Attribute, |
921 | lookup: "proc_macro_derive", | ||
794 | }, | 922 | }, |
795 | CompletionItem { | 923 | CompletionItem { |
796 | label: "recursion_limit", | 924 | label: "recursion_limit = …", |
797 | source_range: 20..20, | 925 | source_range: 20..20, |
798 | delete: 20..20, | 926 | delete: 20..20, |
799 | insert: "recursion_limit = ${0:128}", | 927 | insert: "recursion_limit = ${0:128}", |
800 | kind: Attribute, | 928 | kind: Attribute, |
929 | lookup: "recursion_limit", | ||
801 | }, | 930 | }, |
802 | CompletionItem { | 931 | CompletionItem { |
803 | label: "repr", | 932 | label: "repr(…)", |
804 | source_range: 20..20, | 933 | source_range: 20..20, |
805 | delete: 20..20, | 934 | delete: 20..20, |
806 | insert: "repr(${0:C})", | 935 | insert: "repr(${0:C})", |
807 | kind: Attribute, | 936 | kind: Attribute, |
937 | lookup: "repr", | ||
808 | }, | 938 | }, |
809 | CompletionItem { | 939 | CompletionItem { |
810 | label: "should_panic", | 940 | label: "should_panic(…)", |
811 | source_range: 20..20, | 941 | source_range: 20..20, |
812 | delete: 20..20, | 942 | delete: 20..20, |
813 | insert: "should_panic(expected = \"${0:reason}\")", | 943 | insert: "should_panic(expected = \"${0:reason}\")", |
814 | kind: Attribute, | 944 | kind: Attribute, |
945 | lookup: "should_panic", | ||
815 | }, | 946 | }, |
816 | CompletionItem { | 947 | CompletionItem { |
817 | label: "target_feature", | 948 | label: "target_feature = \"…\"", |
818 | source_range: 20..20, | 949 | source_range: 20..20, |
819 | delete: 20..20, | 950 | delete: 20..20, |
820 | insert: "target_feature = \"${0:feature}\"", | 951 | insert: "target_feature = \"${0:feature}\"", |
821 | kind: Attribute, | 952 | kind: Attribute, |
953 | lookup: "target_feature", | ||
822 | }, | 954 | }, |
823 | CompletionItem { | 955 | CompletionItem { |
824 | label: "test", | 956 | label: "test", |
@@ -835,18 +967,20 @@ mod tests { | |||
835 | kind: Attribute, | 967 | kind: Attribute, |
836 | }, | 968 | }, |
837 | CompletionItem { | 969 | CompletionItem { |
838 | label: "warn", | 970 | label: "warn(…)", |
839 | source_range: 20..20, | 971 | source_range: 20..20, |
840 | delete: 20..20, | 972 | delete: 20..20, |
841 | insert: "warn(${0:lint})", | 973 | insert: "warn(${0:lint})", |
842 | kind: Attribute, | 974 | kind: Attribute, |
975 | lookup: "warn", | ||
843 | }, | 976 | }, |
844 | CompletionItem { | 977 | CompletionItem { |
845 | label: "windows_subsystem", | 978 | label: "windows_subsystem = \"…\"", |
846 | source_range: 20..20, | 979 | source_range: 20..20, |
847 | delete: 20..20, | 980 | delete: 20..20, |
848 | insert: "windows_subsystem = \"${0:subsystem}\"", | 981 | insert: "windows_subsystem = \"${0:subsystem}\"", |
849 | kind: Attribute, | 982 | kind: Attribute, |
983 | lookup: "windows_subsystem", | ||
850 | }, | 984 | }, |
851 | ] | 985 | ] |
852 | "### | 986 | "### |