From 284483b347d15bee3a7bf293d33e5f19a9740102 Mon Sep 17 00:00:00 2001 From: Jamie Cunliffe Date: Sun, 30 May 2021 14:52:19 +0100 Subject: Improve completion of cfg attributes The completion of cfg will look at the enabled cfg keys when performing completion. It will also look crate features when completing a feature cfg option. A fixed list of known values for some cfg options are provided. For unknown keys it will look at the enabled values for that cfg key, which means that completion will only show enabled options for those. --- crates/ide_completion/src/completions/attribute.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'crates/ide_completion/src/completions/attribute.rs') diff --git a/crates/ide_completion/src/completions/attribute.rs b/crates/ide_completion/src/completions/attribute.rs index 78fc30e16..cc4f4b2af 100644 --- a/crates/ide_completion/src/completions/attribute.rs +++ b/crates/ide_completion/src/completions/attribute.rs @@ -15,6 +15,7 @@ use crate::{ 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(_)) => (), @@ -852,4 +856,15 @@ mod tests { "#]], ); } + + #[test] + fn test_cfg() { + check( + r#"#[cfg(target_endian = $0"#, + expect![[r#" + at little + at big +"#]], + ); + } } -- cgit v1.2.3