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/hir/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'crates/hir') diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 88490fea9..2b2aaec94 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -233,6 +233,10 @@ impl Crate { pub fn cfg(&self, db: &dyn HirDatabase) -> CfgOptions { db.crate_graph()[self.id].cfg_options.clone() } + + pub fn features(&self, db: &dyn HirDatabase) -> Vec { + db.crate_graph()[self.id].features.iter().map(|(feat, _)| feat.clone()).collect() + } } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -- cgit v1.2.3 From ae823aa23f1c4fa55e71dd972d0b10c69148b0b4 Mon Sep 17 00:00:00 2001 From: Jamie Cunliffe Date: Mon, 31 May 2021 20:45:01 +0100 Subject: Move features into potential_cfg_options --- crates/hir/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/hir') diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 2b2aaec94..30cc34403 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -234,8 +234,8 @@ impl Crate { db.crate_graph()[self.id].cfg_options.clone() } - pub fn features(&self, db: &dyn HirDatabase) -> Vec { - db.crate_graph()[self.id].features.iter().map(|(feat, _)| feat.clone()).collect() + pub fn potential_cfg(&self, db: &dyn HirDatabase) -> CfgOptions { + db.crate_graph()[self.id].potential_cfg_options.clone() } } -- cgit v1.2.3