]> git.lizzy.rs Git - rust.git/blobdiff - crates/ide_completion/src/completions/attribute.rs
Improve completion of cfg attributes
[rust.git] / crates / ide_completion / src / completions / attribute.rs
index 3866c5917d658306416b02c75ba91c154e7bb532..cc4f4b2af728e973af0fcae689eddde843574fbb 100644 (file)
     Completions,
 };
 
+mod cfg;
 mod derive;
 mod lint;
+mod repr;
 
 pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
     let attribute = ctx.attribute_under_caret.as_ref()?;
     match (attribute.path().and_then(|p| p.as_single_name_ref()), attribute.token_tree()) {
         (Some(path), Some(token_tree)) => match path.text().as_str() {
             "derive" => derive::complete_derive(acc, ctx, token_tree),
+            "repr" => repr::complete_repr(acc, ctx, token_tree),
             "feature" => lint::complete_lint(acc, ctx, token_tree, FEATURES),
             "allow" | "warn" | "deny" | "forbid" => {
                 lint::complete_lint(acc, ctx, token_tree.clone(), DEFAULT_LINTS);
                 lint::complete_lint(acc, ctx, token_tree, CLIPPY_LINTS);
             }
+            "cfg" => {
+                cfg::complete_cfg(acc, ctx);
+            }
             _ => (),
         },
         (None, Some(_)) => (),
@@ -322,7 +328,7 @@ mod tests {
 
     use expect_test::{expect, Expect};
 
-    use crate::{tests::filtered_completion_list, CompletionKind};
+    use crate::tests::completion_list;
 
     #[test]
     fn attributes_are_sorted() {
@@ -341,7 +347,7 @@ fn attributes_are_sorted() {
     }
 
     fn check(ra_fixture: &str, expect: Expect) {
-        let actual = filtered_completion_list(ra_fixture, CompletionKind::Attribute);
+        let actual = completion_list(ra_fixture);
         expect.assert_eq(&actual);
     }
 
@@ -792,6 +798,7 @@ fn complete_attribute_on_fn() {
 
     #[test]
     fn complete_attribute_on_expr() {
+        cov_mark::check!(no_keyword_completion_in_attr_of_expr);
         check(
             r#"fn main() { #[$0] foo() }"#,
             expect![[r#"
@@ -849,4 +856,15 @@ fn complete_attribute_in_source_file_end() {
             "#]],
         );
     }
+
+    #[test]
+    fn test_cfg() {
+        check(
+            r#"#[cfg(target_endian = $0"#,
+            expect![[r#"
+                at little
+                at big
+"#]],
+        );
+    }
 }