aboutsummaryrefslogtreecommitdiff
path: root/crates/base_db/src
diff options
context:
space:
mode:
authorJamie Cunliffe <[email protected]>2021-05-30 14:52:19 +0100
committerJamie Cunliffe <[email protected]>2021-06-21 17:47:00 +0100
commit284483b347d15bee3a7bf293d33e5f19a9740102 (patch)
treee582a7ecdef30511b8982529f11889f1aab3ca5e /crates/base_db/src
parent1b05dbba39d5a4d46f321dc962df99038cddbf21 (diff)
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.
Diffstat (limited to 'crates/base_db/src')
-rw-r--r--crates/base_db/src/fixture.rs2
-rw-r--r--crates/base_db/src/input.rs13
2 files changed, 15 insertions, 0 deletions
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 {
131 meta.cfg, 131 meta.cfg,
132 meta.env, 132 meta.env,
133 Default::default(), 133 Default::default(),
134 Default::default(),
134 ); 135 );
135 let prev = crates.insert(crate_name.clone(), crate_id); 136 let prev = crates.insert(crate_name.clone(), crate_id);
136 assert!(prev.is_none()); 137 assert!(prev.is_none());
@@ -160,6 +161,7 @@ impl ChangeFixture {
160 default_cfg, 161 default_cfg,
161 Env::default(), 162 Env::default(),
162 Default::default(), 163 Default::default(),
164 Default::default(),
163 ); 165 );
164 } else { 166 } else {
165 for (from, to) in crate_deps { 167 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 {
192 pub env: Env, 192 pub env: Env,
193 pub dependencies: Vec<Dependency>, 193 pub dependencies: Vec<Dependency>,
194 pub proc_macro: Vec<ProcMacro>, 194 pub proc_macro: Vec<ProcMacro>,
195 pub features: FxHashMap<String, Vec<String>>,
195} 196}
196 197
197#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 198#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -221,6 +222,7 @@ impl CrateGraph {
221 cfg_options: CfgOptions, 222 cfg_options: CfgOptions,
222 env: Env, 223 env: Env,
223 proc_macro: Vec<ProcMacro>, 224 proc_macro: Vec<ProcMacro>,
225 features: FxHashMap<String, Vec<String>>,
224 ) -> CrateId { 226 ) -> CrateId {
225 let data = CrateData { 227 let data = CrateData {
226 root_file_id: file_id, 228 root_file_id: file_id,
@@ -230,6 +232,7 @@ impl CrateGraph {
230 env, 232 env,
231 proc_macro, 233 proc_macro,
232 dependencies: Vec::new(), 234 dependencies: Vec::new(),
235 features,
233 }; 236 };
234 let crate_id = CrateId(self.arena.len() as u32); 237 let crate_id = CrateId(self.arena.len() as u32);
235 let prev = self.arena.insert(crate_id, data); 238 let prev = self.arena.insert(crate_id, data);
@@ -506,6 +509,7 @@ mod tests {
506 CfgOptions::default(), 509 CfgOptions::default(),
507 Env::default(), 510 Env::default(),
508 Default::default(), 511 Default::default(),
512 Default::default(),
509 ); 513 );
510 let crate2 = graph.add_crate_root( 514 let crate2 = graph.add_crate_root(
511 FileId(2u32), 515 FileId(2u32),
@@ -514,6 +518,7 @@ mod tests {
514 CfgOptions::default(), 518 CfgOptions::default(),
515 Env::default(), 519 Env::default(),
516 Default::default(), 520 Default::default(),
521 Default::default(),
517 ); 522 );
518 let crate3 = graph.add_crate_root( 523 let crate3 = graph.add_crate_root(
519 FileId(3u32), 524 FileId(3u32),
@@ -522,6 +527,7 @@ mod tests {
522 CfgOptions::default(), 527 CfgOptions::default(),
523 Env::default(), 528 Env::default(),
524 Default::default(), 529 Default::default(),
530 Default::default(),
525 ); 531 );
526 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok()); 532 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok());
527 assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok()); 533 assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok());
@@ -538,6 +544,7 @@ mod tests {
538 CfgOptions::default(), 544 CfgOptions::default(),
539 Env::default(), 545 Env::default(),
540 Default::default(), 546 Default::default(),
547 Default::default(),
541 ); 548 );
542 let crate2 = graph.add_crate_root( 549 let crate2 = graph.add_crate_root(
543 FileId(2u32), 550 FileId(2u32),
@@ -546,6 +553,7 @@ mod tests {
546 CfgOptions::default(), 553 CfgOptions::default(),
547 Env::default(), 554 Env::default(),
548 Default::default(), 555 Default::default(),
556 Default::default(),
549 ); 557 );
550 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok()); 558 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok());
551 assert!(graph.add_dep(crate2, CrateName::new("crate2").unwrap(), crate2).is_err()); 559 assert!(graph.add_dep(crate2, CrateName::new("crate2").unwrap(), crate2).is_err());
@@ -561,6 +569,7 @@ mod tests {
561 CfgOptions::default(), 569 CfgOptions::default(),
562 Env::default(), 570 Env::default(),
563 Default::default(), 571 Default::default(),
572 Default::default(),
564 ); 573 );
565 let crate2 = graph.add_crate_root( 574 let crate2 = graph.add_crate_root(
566 FileId(2u32), 575 FileId(2u32),
@@ -569,6 +578,7 @@ mod tests {
569 CfgOptions::default(), 578 CfgOptions::default(),
570 Env::default(), 579 Env::default(),
571 Default::default(), 580 Default::default(),
581 Default::default(),
572 ); 582 );
573 let crate3 = graph.add_crate_root( 583 let crate3 = graph.add_crate_root(
574 FileId(3u32), 584 FileId(3u32),
@@ -577,6 +587,7 @@ mod tests {
577 CfgOptions::default(), 587 CfgOptions::default(),
578 Env::default(), 588 Env::default(),
579 Default::default(), 589 Default::default(),
590 Default::default(),
580 ); 591 );
581 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok()); 592 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok());
582 assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok()); 593 assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok());
@@ -592,6 +603,7 @@ mod tests {
592 CfgOptions::default(), 603 CfgOptions::default(),
593 Env::default(), 604 Env::default(),
594 Default::default(), 605 Default::default(),
606 Default::default(),
595 ); 607 );
596 let crate2 = graph.add_crate_root( 608 let crate2 = graph.add_crate_root(
597 FileId(2u32), 609 FileId(2u32),
@@ -600,6 +612,7 @@ mod tests {
600 CfgOptions::default(), 612 CfgOptions::default(),
601 Env::default(), 613 Env::default(),
602 Default::default(), 614 Default::default(),
615 Default::default(),
603 ); 616 );
604 assert!(graph 617 assert!(graph
605 .add_dep(crate1, CrateName::normalize_dashes("crate-name-with-dashes"), crate2) 618 .add_dep(crate1, CrateName::normalize_dashes("crate-name-with-dashes"), crate2)