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/base_db/src/fixture.rs | 2 ++ crates/base_db/src/input.rs | 13 +++++++++++++ 2 files changed, 15 insertions(+) (limited to 'crates/base_db') diff --git a/crates/base_db/src/fixture.rs b/crates/base_db/src/fixture.rs index 6ce377710..6d3b1266e 100644 --- a/crates/base_db/src/fixture.rs +++ b/crates/base_db/src/fixture.rs @@ -131,6 +131,7 @@ impl ChangeFixture { meta.cfg, meta.env, Default::default(), + Default::default(), ); let prev = crates.insert(crate_name.clone(), crate_id); assert!(prev.is_none()); @@ -160,6 +161,7 @@ impl ChangeFixture { default_cfg, Env::default(), Default::default(), + Default::default(), ); } else { for (from, to) in crate_deps { diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs index 23cb0c839..d99388f71 100644 --- a/crates/base_db/src/input.rs +++ b/crates/base_db/src/input.rs @@ -192,6 +192,7 @@ pub struct CrateData { pub env: Env, pub dependencies: Vec, pub proc_macro: Vec, + pub features: FxHashMap>, } #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -221,6 +222,7 @@ impl CrateGraph { cfg_options: CfgOptions, env: Env, proc_macro: Vec, + features: FxHashMap>, ) -> CrateId { let data = CrateData { root_file_id: file_id, @@ -230,6 +232,7 @@ impl CrateGraph { env, proc_macro, dependencies: Vec::new(), + features, }; let crate_id = CrateId(self.arena.len() as u32); let prev = self.arena.insert(crate_id, data); @@ -506,6 +509,7 @@ mod tests { CfgOptions::default(), Env::default(), Default::default(), + Default::default(), ); let crate2 = graph.add_crate_root( FileId(2u32), @@ -514,6 +518,7 @@ mod tests { CfgOptions::default(), Env::default(), Default::default(), + Default::default(), ); let crate3 = graph.add_crate_root( FileId(3u32), @@ -522,6 +527,7 @@ mod tests { CfgOptions::default(), Env::default(), Default::default(), + Default::default(), ); assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok()); assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok()); @@ -538,6 +544,7 @@ mod tests { CfgOptions::default(), Env::default(), Default::default(), + Default::default(), ); let crate2 = graph.add_crate_root( FileId(2u32), @@ -546,6 +553,7 @@ mod tests { CfgOptions::default(), Env::default(), Default::default(), + Default::default(), ); assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok()); assert!(graph.add_dep(crate2, CrateName::new("crate2").unwrap(), crate2).is_err()); @@ -561,6 +569,7 @@ mod tests { CfgOptions::default(), Env::default(), Default::default(), + Default::default(), ); let crate2 = graph.add_crate_root( FileId(2u32), @@ -569,6 +578,7 @@ mod tests { CfgOptions::default(), Env::default(), Default::default(), + Default::default(), ); let crate3 = graph.add_crate_root( FileId(3u32), @@ -577,6 +587,7 @@ mod tests { CfgOptions::default(), Env::default(), Default::default(), + Default::default(), ); assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok()); assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok()); @@ -592,6 +603,7 @@ mod tests { CfgOptions::default(), Env::default(), Default::default(), + Default::default(), ); let crate2 = graph.add_crate_root( FileId(2u32), @@ -600,6 +612,7 @@ mod tests { CfgOptions::default(), Env::default(), Default::default(), + Default::default(), ); assert!(graph .add_dep(crate1, CrateName::normalize_dashes("crate-name-with-dashes"), crate2) -- cgit v1.2.3