aboutsummaryrefslogtreecommitdiff
path: root/crates/cfg
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-21 18:05:21 +0100
committerGitHub <[email protected]>2021-06-21 18:05:21 +0100
commitf06ddbea6a038eb546d44cb71f2d4d9c055a8828 (patch)
tree9c39a29bdee4f45dcbd497c25350cbfbb0c5e9c3 /crates/cfg
parent1b05dbba39d5a4d46f321dc962df99038cddbf21 (diff)
parentae823aa23f1c4fa55e71dd972d0b10c69148b0b4 (diff)
Merge #9080
9080: Improve completion of cfg attributes r=JamieCunliffe a=JamieCunliffe This will close #5398 and it also adds some completion for cfg options. Co-authored-by: Jamie Cunliffe <[email protected]>
Diffstat (limited to 'crates/cfg')
-rw-r--r--crates/cfg/src/lib.rs20
1 files changed, 20 insertions, 0 deletions
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 {
50 self.enabled.remove(&atom); 50 self.enabled.remove(&atom);
51 } 51 }
52 } 52 }
53
54 pub fn get_cfg_keys(&self) -> Vec<&SmolStr> {
55 self.enabled
56 .iter()
57 .map(|x| match x {
58 CfgAtom::Flag(key) => key,
59 CfgAtom::KeyValue { key, .. } => key,
60 })
61 .collect()
62 }
63
64 pub fn get_cfg_values(&self, cfg_key: &str) -> Vec<&SmolStr> {
65 self.enabled
66 .iter()
67 .filter_map(|x| match x {
68 CfgAtom::KeyValue { key, value } if cfg_key == key => Some(value),
69 _ => None,
70 })
71 .collect()
72 }
53} 73}
54 74
55#[derive(Clone, Debug, PartialEq, Eq)] 75#[derive(Clone, Debug, PartialEq, Eq)]