Skip to content

Commit b7a2f21

Browse files
committed
Add cfg_attr predicate completion
Example --- ```rust #[cfg_attr($0, must_use)] struct Foo; ```
1 parent 1f4e5e8 commit b7a2f21

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

crates/ide-completion/src/completions/attribute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub(crate) fn complete_known_attribute_input(
7070

7171
lint::complete_lint(acc, ctx, colon_prefix, &existing_lints, &lints);
7272
}
73-
["cfg"] => cfg::complete_cfg(acc, ctx),
73+
["cfg"] | ["cfg_attr"] => cfg::complete_cfg(acc, ctx),
7474
["macro_use"] => macro_use::complete_macro_use(
7575
acc,
7676
ctx,

crates/ide-completion/src/tests/attribute.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,58 @@ mod cfg {
835835
);
836836
}
837837

838+
#[test]
839+
fn inside_cfg_attr() {
840+
check(
841+
r#"
842+
//- /main.rs cfg:test,dbg=false,opt_level=2
843+
#[cfg_attr($0)]
844+
"#,
845+
expect![[r#"
846+
ba dbg
847+
ba opt_level
848+
ba test
849+
ba true
850+
"#]],
851+
);
852+
check(
853+
r#"
854+
//- /main.rs cfg:test,dbg=false,opt_level=2
855+
#[cfg_attr(b$0)]
856+
"#,
857+
expect![[r#"
858+
ba dbg
859+
ba opt_level
860+
ba test
861+
ba true
862+
"#]],
863+
);
864+
check(
865+
r#"
866+
//- /main.rs cfg:test,dbg=false,opt_level=2
867+
#[cfg_attr($0, allow(deprecated))]
868+
"#,
869+
expect![[r#"
870+
ba dbg
871+
ba opt_level
872+
ba test
873+
ba true
874+
"#]],
875+
);
876+
check(
877+
r#"
878+
//- /main.rs cfg:test,dbg=false,opt_level=2
879+
#[cfg_attr(b$0, allow(deprecated))]
880+
"#,
881+
expect![[r#"
882+
ba dbg
883+
ba opt_level
884+
ba test
885+
ba true
886+
"#]],
887+
);
888+
}
889+
838890
#[test]
839891
fn cfg_target_endian() {
840892
check(

0 commit comments

Comments
 (0)