diff options
Diffstat (limited to 'crates/ra_ide/src/completion/complete_attribute.rs')
-rw-r--r-- | crates/ra_ide/src/completion/complete_attribute.rs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/crates/ra_ide/src/completion/complete_attribute.rs b/crates/ra_ide/src/completion/complete_attribute.rs index 109c5e9a8..7a4274645 100644 --- a/crates/ra_ide/src/completion/complete_attribute.rs +++ b/crates/ra_ide/src/completion/complete_attribute.rs | |||
@@ -9,8 +9,11 @@ use rustc_hash::FxHashSet; | |||
9 | use crate::completion::{ | 9 | use crate::completion::{ |
10 | completion_context::CompletionContext, | 10 | completion_context::CompletionContext, |
11 | completion_item::{CompletionItem, CompletionItemKind, CompletionKind, Completions}, | 11 | completion_item::{CompletionItem, CompletionItemKind, CompletionKind, Completions}, |
12 | unstable_feature_descriptor | ||
12 | }; | 13 | }; |
13 | 14 | ||
15 | use crate::completion::UNSTABLE_FEATURE_DESCRIPTOR; | ||
16 | |||
14 | pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { | 17 | pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { |
15 | let attribute = ctx.attribute_under_caret.as_ref()?; | 18 | let attribute = ctx.attribute_under_caret.as_ref()?; |
16 | match (attribute.path(), attribute.input()) { | 19 | match (attribute.path(), attribute.input()) { |
@@ -20,11 +23,16 @@ pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) | |||
20 | complete_derive(acc, ctx, token_tree) | 23 | complete_derive(acc, ctx, token_tree) |
21 | } | 24 | } |
22 | (Some(path), Some(ast::AttrInput::TokenTree(token_tree))) | 25 | (Some(path), Some(ast::AttrInput::TokenTree(token_tree))) |
26 | if path.to_string() == "feature" => | ||
27 | { | ||
28 | complete_lint(acc, ctx, token_tree, UNSTABLE_FEATURE_DESCRIPTOR); | ||
29 | } | ||
30 | (Some(path), Some(ast::AttrInput::TokenTree(token_tree))) | ||
23 | if ["allow", "warn", "deny", "forbid"] | 31 | if ["allow", "warn", "deny", "forbid"] |
24 | .iter() | 32 | .iter() |
25 | .any(|lint_level| lint_level == &path.to_string()) => | 33 | .any(|lint_level| lint_level == &path.to_string()) => |
26 | { | 34 | { |
27 | complete_lint(acc, ctx, token_tree) | 35 | complete_lint(acc, ctx, token_tree, DEFAULT_LINT_COMPLETIONS) |
28 | } | 36 | } |
29 | (_, Some(ast::AttrInput::TokenTree(_token_tree))) => {} | 37 | (_, Some(ast::AttrInput::TokenTree(_token_tree))) => {} |
30 | _ => complete_attribute_start(acc, ctx, attribute), | 38 | _ => complete_attribute_start(acc, ctx, attribute), |
@@ -87,7 +95,7 @@ const ATTRIBUTES: &[AttrCompletion] = &[ | |||
87 | attr(r#"deprecated = "…""#, Some("deprecated"), Some(r#"deprecated = "${0:reason}""#)), | 95 | attr(r#"deprecated = "…""#, Some("deprecated"), Some(r#"deprecated = "${0:reason}""#)), |
88 | attr("derive(…)", Some("derive"), Some(r#"derive(${0:Debug})"#)), | 96 | attr("derive(…)", Some("derive"), Some(r#"derive(${0:Debug})"#)), |
89 | attr(r#"doc = "…""#, Some("doc"), Some(r#"doc = "${0:docs}""#)), | 97 | attr(r#"doc = "…""#, Some("doc"), Some(r#"doc = "${0:docs}""#)), |
90 | attr("feature(…)", Some("feature"), Some("feature(${0:flag})")).prefer_inner(), | 98 | attr("feature(…)", Some("feature"), Some("feature(${0:lint})")).prefer_inner(), |
91 | attr("forbid(…)", Some("forbid"), Some("forbid(${0:lint})")), | 99 | attr("forbid(…)", Some("forbid"), Some("forbid(${0:lint})")), |
92 | // FIXME: resolve through macro resolution? | 100 | // FIXME: resolve through macro resolution? |
93 | attr("global_allocator", None, None).prefer_inner(), | 101 | attr("global_allocator", None, None).prefer_inner(), |
@@ -164,9 +172,9 @@ fn complete_derive(acc: &mut Completions, ctx: &CompletionContext, derive_input: | |||
164 | } | 172 | } |
165 | } | 173 | } |
166 | 174 | ||
167 | fn complete_lint(acc: &mut Completions, ctx: &CompletionContext, derive_input: ast::TokenTree) { | 175 | fn complete_lint(acc: &mut Completions, ctx: &CompletionContext, derive_input: ast::TokenTree, lints_completions: &[LintCompletion]) { |
168 | if let Ok(existing_lints) = parse_comma_sep_input(derive_input) { | 176 | if let Ok(existing_lints) = parse_comma_sep_input(derive_input) { |
169 | for lint_completion in DEFAULT_LINT_COMPLETIONS | 177 | for lint_completion in lints_completions |
170 | .into_iter() | 178 | .into_iter() |
171 | .filter(|completion| !existing_lints.contains(completion.label)) | 179 | .filter(|completion| !existing_lints.contains(completion.label)) |
172 | { | 180 | { |
@@ -250,9 +258,9 @@ const DEFAULT_DERIVE_COMPLETIONS: &[DeriveCompletion] = &[ | |||
250 | DeriveCompletion { label: "Ord", dependencies: &["PartialOrd", "Eq", "PartialEq"] }, | 258 | DeriveCompletion { label: "Ord", dependencies: &["PartialOrd", "Eq", "PartialEq"] }, |
251 | ]; | 259 | ]; |
252 | 260 | ||
253 | struct LintCompletion { | 261 | pub struct LintCompletion { |
254 | label: &'static str, | 262 | pub label: &'static str, |
255 | description: &'static str, | 263 | pub description: &'static str, |
256 | } | 264 | } |
257 | 265 | ||
258 | #[rustfmt::skip] | 266 | #[rustfmt::skip] |