diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ide_completion/src/completions/attribute.rs | 82 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/attribute/derive.rs | 1 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/attribute/lint.rs | 1 |
3 files changed, 57 insertions, 27 deletions
diff --git a/crates/ide_completion/src/completions/attribute.rs b/crates/ide_completion/src/completions/attribute.rs index e128e307c..246a3270a 100644 --- a/crates/ide_completion/src/completions/attribute.rs +++ b/crates/ide_completion/src/completions/attribute.rs | |||
@@ -109,42 +109,70 @@ const fn attr( | |||
109 | } | 109 | } |
110 | 110 | ||
111 | macro_rules! attrs { | 111 | macro_rules! attrs { |
112 | [$($($mac:ident!),+;)? $($key:literal),*] => { | 112 | [@ { item $($tt:tt)* } {$($acc:tt)*}] => { |
113 | &["allow", "cfg", "cfg_attr", "deny", "forbid", "warn", $($($mac!()),+,)? $($key),*] as _ | 113 | attrs!(@ { $($tt)* } { $($acc)*, "deprecated", "doc", "dochidden", "docalias", "must_use", "no_mangle" }) |
114 | } | 114 | }; |
115 | } | 115 | [@ { adt $($tt:tt)* } {$($acc:tt)*}] => { |
116 | macro_rules! item_attrs { | 116 | attrs!(@ { $($tt)* } { $($acc)*, "derive", "repr" }) |
117 | () => { | 117 | }; |
118 | "deprecated" | 118 | [@ { linkable $($tt:tt)* } {$($acc:tt)*}] => { |
119 | attrs!(@ { $($tt)* } { $($acc)*, "export_name", "link_name", "link_section" }) }; | ||
120 | [@ { $ty:ident $($tt:tt)* } {$($acc:tt)*}] => { compile_error!(concat!("unknown attr subtype ", stringify!($ty))) | ||
121 | }; | ||
122 | [@ { $lit:literal $($tt:tt)*} {$($acc:tt)*}] => { | ||
123 | attrs!(@ { $($tt)* } { $($acc)*, $lit }) | ||
124 | }; | ||
125 | [@ {$($tt:tt)+} {$($tt2:tt)*}] => { | ||
126 | compile_error!(concat!("Unexpected input ", stringify!($($tt)+))) | ||
127 | }; | ||
128 | [@ {} {$($tt:tt)*}] => { &[$($tt)*] as _ }; | ||
129 | [$($tt:tt),*] => { | ||
130 | attrs!(@ { $($tt)* } { "allow", "cfg", "cfg_attr", "deny", "forbid", "warn" }) | ||
119 | }; | 131 | }; |
120 | } | 132 | } |
121 | 133 | ||
134 | #[rustfmt::skip] | ||
122 | static KIND_TO_ATTRIBUTES: Lazy<FxHashMap<SyntaxKind, &[&str]>> = Lazy::new(|| { | 135 | static KIND_TO_ATTRIBUTES: Lazy<FxHashMap<SyntaxKind, &[&str]>> = Lazy::new(|| { |
123 | std::array::IntoIter::new([ | 136 | std::array::IntoIter::new([ |
124 | (SyntaxKind::SOURCE_FILE, attrs!(item_attrs!;"crate_name")), | 137 | ( |
125 | (SyntaxKind::MODULE, attrs!(item_attrs!;)), | 138 | SyntaxKind::SOURCE_FILE, |
126 | (SyntaxKind::ITEM_LIST, attrs!(item_attrs!;)), | 139 | attrs!( |
127 | (SyntaxKind::MACRO_RULES, attrs!(item_attrs!;)), | 140 | item, |
128 | (SyntaxKind::MACRO_DEF, attrs!(item_attrs!;)), | 141 | "crate_name", "feature", "no_implicit_prelude", "no_main", "no_std", |
129 | (SyntaxKind::EXTERN_CRATE, attrs!(item_attrs!;)), | 142 | "recursion_limit", "type_length_limit", "windows_subsystem" |
130 | (SyntaxKind::USE, attrs!(item_attrs!;)), | 143 | ), |
131 | (SyntaxKind::FN, attrs!(item_attrs!;"cold", "must_use")), | 144 | ), |
132 | (SyntaxKind::TYPE_ALIAS, attrs!(item_attrs!;)), | 145 | (SyntaxKind::MODULE, attrs!(item, "no_implicit_prelude", "path")), |
133 | (SyntaxKind::STRUCT, attrs!(item_attrs!;"must_use")), | 146 | (SyntaxKind::ITEM_LIST, attrs!(item, "no_implicit_prelude")), |
134 | (SyntaxKind::ENUM, attrs!(item_attrs!;"must_use")), | 147 | (SyntaxKind::MACRO_RULES, attrs!(item, "macro_export", "macro_use")), |
135 | (SyntaxKind::UNION, attrs!(item_attrs!;"must_use")), | 148 | (SyntaxKind::MACRO_DEF, attrs!(item)), |
136 | (SyntaxKind::CONST, attrs!(item_attrs!;)), | 149 | (SyntaxKind::EXTERN_CRATE, attrs!(item, "macro_use", "no_link")), |
137 | (SyntaxKind::STATIC, attrs!(item_attrs!;)), | 150 | (SyntaxKind::USE, attrs!(item)), |
138 | (SyntaxKind::TRAIT, attrs!(item_attrs!; "must_use")), | 151 | (SyntaxKind::TYPE_ALIAS, attrs!(item)), |
139 | (SyntaxKind::IMPL, attrs!(item_attrs!;"automatically_derived")), | 152 | (SyntaxKind::STRUCT, attrs!(item, adt, "non_exhaustive")), |
140 | (SyntaxKind::ASSOC_ITEM_LIST, attrs!(item_attrs!;)), | 153 | (SyntaxKind::ENUM, attrs!(item, adt, "non_exhaustive")), |
141 | (SyntaxKind::EXTERN_BLOCK, attrs!(item_attrs!;)), | 154 | (SyntaxKind::UNION, attrs!(item, adt)), |
142 | (SyntaxKind::EXTERN_ITEM_LIST, attrs!(item_attrs!;)), | 155 | (SyntaxKind::CONST, attrs!(item)), |
156 | ( | ||
157 | SyntaxKind::FN, | ||
158 | attrs!( | ||
159 | item, linkable, | ||
160 | "cold", "ignore", "inline", "must_use", "panic_handler", "proc_macro", | ||
161 | "proc_macro_derive", "proc_macro_attribute", "should_panic", "target_feature", | ||
162 | "test", "track_caller" | ||
163 | ), | ||
164 | ), | ||
165 | (SyntaxKind::STATIC, attrs!(item, linkable, "global_allocator", "used")), | ||
166 | (SyntaxKind::TRAIT, attrs!(item, "must_use")), | ||
167 | (SyntaxKind::IMPL, attrs!(item, "automatically_derived")), | ||
168 | (SyntaxKind::ASSOC_ITEM_LIST, attrs!(item)), | ||
169 | (SyntaxKind::EXTERN_BLOCK, attrs!(item, "link")), | ||
170 | (SyntaxKind::EXTERN_ITEM_LIST, attrs!(item, "link")), | ||
143 | (SyntaxKind::MACRO_CALL, attrs!()), | 171 | (SyntaxKind::MACRO_CALL, attrs!()), |
144 | (SyntaxKind::SELF_PARAM, attrs!()), | 172 | (SyntaxKind::SELF_PARAM, attrs!()), |
145 | (SyntaxKind::PARAM, attrs!()), | 173 | (SyntaxKind::PARAM, attrs!()), |
146 | (SyntaxKind::RECORD_FIELD, attrs!()), | 174 | (SyntaxKind::RECORD_FIELD, attrs!()), |
147 | (SyntaxKind::VARIANT, attrs!()), | 175 | (SyntaxKind::VARIANT, attrs!("non_exhaustive")), |
148 | (SyntaxKind::TYPE_PARAM, attrs!()), | 176 | (SyntaxKind::TYPE_PARAM, attrs!()), |
149 | (SyntaxKind::CONST_PARAM, attrs!()), | 177 | (SyntaxKind::CONST_PARAM, attrs!()), |
150 | (SyntaxKind::LIFETIME_PARAM, attrs!()), | 178 | (SyntaxKind::LIFETIME_PARAM, attrs!()), |
diff --git a/crates/ide_completion/src/completions/attribute/derive.rs b/crates/ide_completion/src/completions/attribute/derive.rs index c14b03ea4..c213e4792 100644 --- a/crates/ide_completion/src/completions/attribute/derive.rs +++ b/crates/ide_completion/src/completions/attribute/derive.rs | |||
@@ -1,3 +1,4 @@ | |||
1 | //! Completion for derives | ||
1 | use itertools::Itertools; | 2 | use itertools::Itertools; |
2 | use rustc_hash::FxHashSet; | 3 | use rustc_hash::FxHashSet; |
3 | use syntax::ast; | 4 | use syntax::ast; |
diff --git a/crates/ide_completion/src/completions/attribute/lint.rs b/crates/ide_completion/src/completions/attribute/lint.rs index 1f9873d3c..8815e5867 100644 --- a/crates/ide_completion/src/completions/attribute/lint.rs +++ b/crates/ide_completion/src/completions/attribute/lint.rs | |||
@@ -1,3 +1,4 @@ | |||
1 | //! Completion for lints | ||
1 | use syntax::ast; | 2 | use syntax::ast; |
2 | 3 | ||
3 | use crate::{ | 4 | use crate::{ |