]> 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 9780d01aefef37333d6eca4dcfe851874b7622b8..cc4f4b2af728e973af0fcae689eddde843574fbb 100644 (file)
@@ -15,6 +15,7 @@
     Completions,
 };
 
+mod cfg;
 mod derive;
 mod lint;
 mod repr;
@@ -30,6 +31,9 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
                 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(_)) => (),
@@ -788,13 +792,13 @@ fn complete_attribute_on_fn() {
                 at target_feature = "…"
                 at test
                 at track_caller
-                kw return
             "#]],
         );
     }
 
     #[test]
     fn complete_attribute_on_expr() {
+        cov_mark::check!(no_keyword_completion_in_attr_of_expr);
         check(
             r#"fn main() { #[$0] foo() }"#,
             expect![[r#"
@@ -804,7 +808,6 @@ fn complete_attribute_on_expr() {
                 at deny(…)
                 at forbid(…)
                 at warn(…)
-                kw return
             "#]],
         );
     }
@@ -853,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
+"#]],
+        );
+    }
 }