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/cfg/src/lib.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'crates/cfg') diff --git a/crates/cfg/src/lib.rs b/crates/cfg/src/lib.rs index 916d39a0b..9a4baa636 100644 --- a/crates/cfg/src/lib.rs +++ b/crates/cfg/src/lib.rs @@ -50,6 +50,26 @@ impl CfgOptions { self.enabled.remove(&atom); } } + + pub fn get_cfg_keys(&self) -> Vec<&SmolStr> { + self.enabled + .iter() + .map(|x| match x { + CfgAtom::Flag(key) => key, + CfgAtom::KeyValue { key, .. } => key, + }) + .collect() + } + + pub fn get_cfg_values(&self, cfg_key: &str) -> Vec<&SmolStr> { + self.enabled + .iter() + .filter_map(|x| match x { + CfgAtom::KeyValue { key, value } if cfg_key == key => Some(value), + _ => None, + }) + .collect() + } } #[derive(Clone, Debug, PartialEq, Eq)] -- cgit v1.2.3