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