aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion/complete_attribute.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/completion/complete_attribute.rs')
-rw-r--r--crates/ra_ide/src/completion/complete_attribute.rs22
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 2faaae974..089d806d8 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;
9use crate::completion::{ 9use 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
15use crate::completion::UNSTABLE_FEATURE_DESCRIPTOR;
16
14pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { 17pub(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.token_tree()) { 19 match (attribute.path(), attribute.token_tree()) {
@@ -18,11 +21,16 @@ pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
18 complete_derive(acc, ctx, token_tree) 21 complete_derive(acc, ctx, token_tree)
19 } 22 }
20 (Some(path), Some(token_tree)) 23 (Some(path), Some(token_tree))
24 if path.to_string() == "feature" =>
25 {
26 complete_lint(acc, ctx, token_tree, UNSTABLE_FEATURE_DESCRIPTOR);
27 }
28 (Some(path), Some(token_tree))
21 if ["allow", "warn", "deny", "forbid"] 29 if ["allow", "warn", "deny", "forbid"]
22 .iter() 30 .iter()
23 .any(|lint_level| lint_level == &path.to_string()) => 31 .any(|lint_level| lint_level == &path.to_string()) =>
24 { 32 {
25 complete_lint(acc, ctx, token_tree) 33 complete_lint(acc, ctx, token_tree, DEFAULT_LINT_COMPLETIONS)
26 } 34 }
27 (_, Some(_token_tree)) => {} 35 (_, Some(_token_tree)) => {}
28 _ => complete_attribute_start(acc, ctx, attribute), 36 _ => complete_attribute_start(acc, ctx, attribute),
@@ -85,7 +93,7 @@ const ATTRIBUTES: &[AttrCompletion] = &[
85 attr(r#"deprecated = "…""#, Some("deprecated"), Some(r#"deprecated = "${0:reason}""#)), 93 attr(r#"deprecated = "…""#, Some("deprecated"), Some(r#"deprecated = "${0:reason}""#)),
86 attr("derive(…)", Some("derive"), Some(r#"derive(${0:Debug})"#)), 94 attr("derive(…)", Some("derive"), Some(r#"derive(${0:Debug})"#)),
87 attr(r#"doc = "…""#, Some("doc"), Some(r#"doc = "${0:docs}""#)), 95 attr(r#"doc = "…""#, Some("doc"), Some(r#"doc = "${0:docs}""#)),
88 attr("feature(…)", Some("feature"), Some("feature(${0:flag})")).prefer_inner(), 96 attr("feature(…)", Some("feature"), Some("feature(${0:lint})")).prefer_inner(),
89 attr("forbid(…)", Some("forbid"), Some("forbid(${0:lint})")), 97 attr("forbid(…)", Some("forbid"), Some("forbid(${0:lint})")),
90 // FIXME: resolve through macro resolution? 98 // FIXME: resolve through macro resolution?
91 attr("global_allocator", None, None).prefer_inner(), 99 attr("global_allocator", None, None).prefer_inner(),
@@ -162,9 +170,9 @@ fn complete_derive(acc: &mut Completions, ctx: &CompletionContext, derive_input:
162 } 170 }
163} 171}
164 172
165fn complete_lint(acc: &mut Completions, ctx: &CompletionContext, derive_input: ast::TokenTree) { 173fn complete_lint(acc: &mut Completions, ctx: &CompletionContext, derive_input: ast::TokenTree, lints_completions: &[LintCompletion]) {
166 if let Ok(existing_lints) = parse_comma_sep_input(derive_input) { 174 if let Ok(existing_lints) = parse_comma_sep_input(derive_input) {
167 for lint_completion in DEFAULT_LINT_COMPLETIONS 175 for lint_completion in lints_completions
168 .into_iter() 176 .into_iter()
169 .filter(|completion| !existing_lints.contains(completion.label)) 177 .filter(|completion| !existing_lints.contains(completion.label))
170 { 178 {
@@ -248,9 +256,9 @@ const DEFAULT_DERIVE_COMPLETIONS: &[DeriveCompletion] = &[
248 DeriveCompletion { label: "Ord", dependencies: &["PartialOrd", "Eq", "PartialEq"] }, 256 DeriveCompletion { label: "Ord", dependencies: &["PartialOrd", "Eq", "PartialEq"] },
249]; 257];
250 258
251struct LintCompletion { 259pub struct LintCompletion {
252 label: &'static str, 260 pub label: &'static str,
253 description: &'static str, 261 pub description: &'static str,
254} 262}
255 263
256#[rustfmt::skip] 264#[rustfmt::skip]