mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-27 18:26:19 +00:00
Merge pull request #20760 from A4-Tacks/all-any-not-attr-comp
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
Add `all` `any` and `not` attribute completions
This commit is contained in:
commit
062ac7a545
2 changed files with 56 additions and 6 deletions
|
|
@ -53,15 +53,33 @@ pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext<'_>) {
|
|||
acc.add(item.build(ctx.db));
|
||||
}),
|
||||
},
|
||||
None => ctx.krate.potential_cfg(ctx.db).get_cfg_keys().cloned().unique().for_each(|s| {
|
||||
let s = s.as_str();
|
||||
let item =
|
||||
CompletionItem::new(SymbolKind::BuiltinAttr, ctx.source_range(), s, ctx.edition);
|
||||
acc.add(item.build(ctx.db));
|
||||
}),
|
||||
None => ctx
|
||||
.krate
|
||||
.potential_cfg(ctx.db)
|
||||
.get_cfg_keys()
|
||||
.unique()
|
||||
.map(|s| (s.as_str(), ""))
|
||||
.chain(CFG_CONDITION.iter().copied())
|
||||
.for_each(|(s, snippet)| {
|
||||
let mut item = CompletionItem::new(
|
||||
SymbolKind::BuiltinAttr,
|
||||
ctx.source_range(),
|
||||
s,
|
||||
ctx.edition,
|
||||
);
|
||||
if let Some(cap) = ctx.config.snippet_cap
|
||||
&& !snippet.is_empty()
|
||||
{
|
||||
item.insert_snippet(cap, snippet);
|
||||
}
|
||||
acc.add(item.build(ctx.db));
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
const CFG_CONDITION: &[(&str, &str)] =
|
||||
&[("all", "all($0)"), ("any", "any($0)"), ("not", "not($0)")];
|
||||
|
||||
const KNOWN_ARCH: [&str; 20] = [
|
||||
"aarch64",
|
||||
"arm",
|
||||
|
|
|
|||
|
|
@ -815,7 +815,10 @@ mod cfg {
|
|||
#[cfg($0)]
|
||||
"#,
|
||||
expect![[r#"
|
||||
ba all
|
||||
ba any
|
||||
ba dbg
|
||||
ba not
|
||||
ba opt_level
|
||||
ba test
|
||||
ba true
|
||||
|
|
@ -827,7 +830,10 @@ mod cfg {
|
|||
#[cfg(b$0)]
|
||||
"#,
|
||||
expect![[r#"
|
||||
ba all
|
||||
ba any
|
||||
ba dbg
|
||||
ba not
|
||||
ba opt_level
|
||||
ba test
|
||||
ba true
|
||||
|
|
@ -843,7 +849,10 @@ mod cfg {
|
|||
#[cfg_attr($0)]
|
||||
"#,
|
||||
expect![[r#"
|
||||
ba all
|
||||
ba any
|
||||
ba dbg
|
||||
ba not
|
||||
ba opt_level
|
||||
ba test
|
||||
ba true
|
||||
|
|
@ -855,7 +864,10 @@ mod cfg {
|
|||
#[cfg_attr(b$0)]
|
||||
"#,
|
||||
expect![[r#"
|
||||
ba all
|
||||
ba any
|
||||
ba dbg
|
||||
ba not
|
||||
ba opt_level
|
||||
ba test
|
||||
ba true
|
||||
|
|
@ -867,7 +879,10 @@ mod cfg {
|
|||
#[cfg_attr($0, allow(deprecated))]
|
||||
"#,
|
||||
expect![[r#"
|
||||
ba all
|
||||
ba any
|
||||
ba dbg
|
||||
ba not
|
||||
ba opt_level
|
||||
ba test
|
||||
ba true
|
||||
|
|
@ -879,7 +894,10 @@ mod cfg {
|
|||
#[cfg_attr(b$0, allow(deprecated))]
|
||||
"#,
|
||||
expect![[r#"
|
||||
ba all
|
||||
ba any
|
||||
ba dbg
|
||||
ba not
|
||||
ba opt_level
|
||||
ba test
|
||||
ba true
|
||||
|
|
@ -904,6 +922,20 @@ mod cfg {
|
|||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inside_conditional() {
|
||||
check_edit(
|
||||
"all",
|
||||
r#"
|
||||
//- /main.rs cfg:test,dbg=false,opt_level=2
|
||||
#[cfg($0)]
|
||||
"#,
|
||||
r#"
|
||||
#[cfg(all($0))]
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod derive {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue