Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #20604 from A4-Tacks/cfg-attr-comp
Add cfg_attr predicate completion
Shoyu Vanilla (Flint) 7 months ago
parent a55e2b5 · parent b7a2f21 · commit 084c1e5
-rw-r--r--crates/ide-completion/src/completions/attribute.rs2
-rw-r--r--crates/ide-completion/src/tests/attribute.rs52
2 files changed, 53 insertions, 1 deletions
diff --git a/crates/ide-completion/src/completions/attribute.rs b/crates/ide-completion/src/completions/attribute.rs
index c542e140df..e174b0c892 100644
--- a/crates/ide-completion/src/completions/attribute.rs
+++ b/crates/ide-completion/src/completions/attribute.rs
@@ -70,7 +70,7 @@ pub(crate) fn complete_known_attribute_input(
lint::complete_lint(acc, ctx, colon_prefix, &existing_lints, &lints);
}
- ["cfg"] => cfg::complete_cfg(acc, ctx),
+ ["cfg"] | ["cfg_attr"] => cfg::complete_cfg(acc, ctx),
["macro_use"] => macro_use::complete_macro_use(
acc,
ctx,
diff --git a/crates/ide-completion/src/tests/attribute.rs b/crates/ide-completion/src/tests/attribute.rs
index 46a3630045..30e1e108c6 100644
--- a/crates/ide-completion/src/tests/attribute.rs
+++ b/crates/ide-completion/src/tests/attribute.rs
@@ -836,6 +836,58 @@ mod cfg {
}
#[test]
+ fn inside_cfg_attr() {
+ check(
+ r#"
+//- /main.rs cfg:test,dbg=false,opt_level=2
+#[cfg_attr($0)]
+"#,
+ expect![[r#"
+ ba dbg
+ ba opt_level
+ ba test
+ ba true
+ "#]],
+ );
+ check(
+ r#"
+//- /main.rs cfg:test,dbg=false,opt_level=2
+#[cfg_attr(b$0)]
+"#,
+ expect![[r#"
+ ba dbg
+ ba opt_level
+ ba test
+ ba true
+ "#]],
+ );
+ check(
+ r#"
+//- /main.rs cfg:test,dbg=false,opt_level=2
+#[cfg_attr($0, allow(deprecated))]
+"#,
+ expect![[r#"
+ ba dbg
+ ba opt_level
+ ba test
+ ba true
+ "#]],
+ );
+ check(
+ r#"
+//- /main.rs cfg:test,dbg=false,opt_level=2
+#[cfg_attr(b$0, allow(deprecated))]
+"#,
+ expect![[r#"
+ ba dbg
+ ba opt_level
+ ba test
+ ba true
+ "#]],
+ );
+ }
+
+ #[test]
fn cfg_target_endian() {
check(
r#"#[cfg(target_endian = $0"#,