aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_db/src')
-rw-r--r--crates/ra_db/src/fixture.rs4
-rw-r--r--crates/ra_db/src/input.rs32
-rw-r--r--crates/ra_db/src/lib.rs2
3 files changed, 37 insertions, 1 deletions
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs
index 5e3e9203c..7777ce81e 100644
--- a/crates/ra_db/src/fixture.rs
+++ b/crates/ra_db/src/fixture.rs
@@ -70,6 +70,7 @@ fn with_single_file(db: &mut dyn SourceDatabaseExt, ra_fixture: &str) -> FileId
70 meta.cfg, 70 meta.cfg,
71 meta.env, 71 meta.env,
72 Default::default(), 72 Default::default(),
73 Default::default(),
73 ); 74 );
74 crate_graph 75 crate_graph
75 } else { 76 } else {
@@ -81,6 +82,7 @@ fn with_single_file(db: &mut dyn SourceDatabaseExt, ra_fixture: &str) -> FileId
81 CfgOptions::default(), 82 CfgOptions::default(),
82 Env::default(), 83 Env::default(),
83 Default::default(), 84 Default::default(),
85 Default::default(),
84 ); 86 );
85 crate_graph 87 crate_graph
86 }; 88 };
@@ -130,6 +132,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
130 meta.cfg, 132 meta.cfg,
131 meta.env, 133 meta.env,
132 Default::default(), 134 Default::default(),
135 Default::default(),
133 ); 136 );
134 let prev = crates.insert(krate.clone(), crate_id); 137 let prev = crates.insert(krate.clone(), crate_id);
135 assert!(prev.is_none()); 138 assert!(prev.is_none());
@@ -167,6 +170,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
167 CfgOptions::default(), 170 CfgOptions::default(),
168 Env::default(), 171 Env::default(),
169 Default::default(), 172 Default::default(),
173 Default::default(),
170 ); 174 );
171 } else { 175 } else {
172 for (from, to) in crate_deps { 176 for (from, to) in crate_deps {
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index e371f849d..5ddce98c6 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -10,6 +10,7 @@ use std::{
10 fmt, ops, 10 fmt, ops,
11 path::{Path, PathBuf}, 11 path::{Path, PathBuf},
12 str::FromStr, 12 str::FromStr,
13 sync::Arc,
13}; 14};
14 15
15use ra_cfg::CfgOptions; 16use ra_cfg::CfgOptions;
@@ -19,6 +20,7 @@ use rustc_hash::FxHashSet;
19 20
20use crate::{RelativePath, RelativePathBuf}; 21use crate::{RelativePath, RelativePathBuf};
21use fmt::Display; 22use fmt::Display;
23use ra_tt::TokenExpander;
22 24
23/// `FileId` is an integer which uniquely identifies a file. File paths are 25/// `FileId` is an integer which uniquely identifies a file. File paths are
24/// messy and system-dependent, so most of the code should work directly with 26/// messy and system-dependent, so most of the code should work directly with
@@ -115,6 +117,22 @@ impl Display for CrateName {
115 } 117 }
116} 118}
117 119
120#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
121pub struct ProcMacroId(pub u32);
122
123#[derive(Debug, Clone)]
124pub struct ProcMacro {
125 pub name: SmolStr,
126 pub expander: Arc<dyn TokenExpander>,
127}
128
129impl Eq for ProcMacro {}
130impl PartialEq for ProcMacro {
131 fn eq(&self, other: &ProcMacro) -> bool {
132 self.name == other.name && Arc::ptr_eq(&self.expander, &other.expander)
133 }
134}
135
118#[derive(Debug, Clone, PartialEq, Eq)] 136#[derive(Debug, Clone, PartialEq, Eq)]
119pub struct CrateData { 137pub struct CrateData {
120 pub root_file_id: FileId, 138 pub root_file_id: FileId,
@@ -127,6 +145,7 @@ pub struct CrateData {
127 pub env: Env, 145 pub env: Env,
128 pub extern_source: ExternSource, 146 pub extern_source: ExternSource,
129 pub dependencies: Vec<Dependency>, 147 pub dependencies: Vec<Dependency>,
148 pub proc_macro: Vec<ProcMacro>,
130} 149}
131 150
132#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 151#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -166,7 +185,11 @@ impl CrateGraph {
166 cfg_options: CfgOptions, 185 cfg_options: CfgOptions,
167 env: Env, 186 env: Env,
168 extern_source: ExternSource, 187 extern_source: ExternSource,
188 proc_macro: Vec<(SmolStr, Arc<dyn ra_tt::TokenExpander>)>,
169 ) -> CrateId { 189 ) -> CrateId {
190 let proc_macro =
191 proc_macro.into_iter().map(|(name, it)| ProcMacro { name, expander: it }).collect();
192
170 let data = CrateData { 193 let data = CrateData {
171 root_file_id: file_id, 194 root_file_id: file_id,
172 edition, 195 edition,
@@ -174,6 +197,7 @@ impl CrateGraph {
174 cfg_options, 197 cfg_options,
175 env, 198 env,
176 extern_source, 199 extern_source,
200 proc_macro,
177 dependencies: Vec::new(), 201 dependencies: Vec::new(),
178 }; 202 };
179 let crate_id = CrateId(self.arena.len() as u32); 203 let crate_id = CrateId(self.arena.len() as u32);
@@ -345,6 +369,7 @@ mod tests {
345 CfgOptions::default(), 369 CfgOptions::default(),
346 Env::default(), 370 Env::default(),
347 Default::default(), 371 Default::default(),
372 Default::default(),
348 ); 373 );
349 let crate2 = graph.add_crate_root( 374 let crate2 = graph.add_crate_root(
350 FileId(2u32), 375 FileId(2u32),
@@ -353,6 +378,7 @@ mod tests {
353 CfgOptions::default(), 378 CfgOptions::default(),
354 Env::default(), 379 Env::default(),
355 Default::default(), 380 Default::default(),
381 Default::default(),
356 ); 382 );
357 let crate3 = graph.add_crate_root( 383 let crate3 = graph.add_crate_root(
358 FileId(3u32), 384 FileId(3u32),
@@ -361,6 +387,7 @@ mod tests {
361 CfgOptions::default(), 387 CfgOptions::default(),
362 Env::default(), 388 Env::default(),
363 Default::default(), 389 Default::default(),
390 Default::default(),
364 ); 391 );
365 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok()); 392 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok());
366 assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok()); 393 assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok());
@@ -377,6 +404,7 @@ mod tests {
377 CfgOptions::default(), 404 CfgOptions::default(),
378 Env::default(), 405 Env::default(),
379 Default::default(), 406 Default::default(),
407 Default::default(),
380 ); 408 );
381 let crate2 = graph.add_crate_root( 409 let crate2 = graph.add_crate_root(
382 FileId(2u32), 410 FileId(2u32),
@@ -385,6 +413,7 @@ mod tests {
385 CfgOptions::default(), 413 CfgOptions::default(),
386 Env::default(), 414 Env::default(),
387 Default::default(), 415 Default::default(),
416 Default::default(),
388 ); 417 );
389 let crate3 = graph.add_crate_root( 418 let crate3 = graph.add_crate_root(
390 FileId(3u32), 419 FileId(3u32),
@@ -393,6 +422,7 @@ mod tests {
393 CfgOptions::default(), 422 CfgOptions::default(),
394 Env::default(), 423 Env::default(),
395 Default::default(), 424 Default::default(),
425 Default::default(),
396 ); 426 );
397 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok()); 427 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok());
398 assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok()); 428 assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok());
@@ -408,6 +438,7 @@ mod tests {
408 CfgOptions::default(), 438 CfgOptions::default(),
409 Env::default(), 439 Env::default(),
410 Default::default(), 440 Default::default(),
441 Default::default(),
411 ); 442 );
412 let crate2 = graph.add_crate_root( 443 let crate2 = graph.add_crate_root(
413 FileId(2u32), 444 FileId(2u32),
@@ -416,6 +447,7 @@ mod tests {
416 CfgOptions::default(), 447 CfgOptions::default(),
417 Env::default(), 448 Env::default(),
418 Default::default(), 449 Default::default(),
450 Default::default(),
419 ); 451 );
420 assert!(graph 452 assert!(graph
421 .add_dep(crate1, CrateName::normalize_dashes("crate-name-with-dashes"), crate2) 453 .add_dep(crate1, CrateName::normalize_dashes("crate-name-with-dashes"), crate2)
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs
index bac24e218..a06f59c14 100644
--- a/crates/ra_db/src/lib.rs
+++ b/crates/ra_db/src/lib.rs
@@ -12,7 +12,7 @@ pub use crate::{
12 cancellation::Canceled, 12 cancellation::Canceled,
13 input::{ 13 input::{
14 CrateGraph, CrateId, CrateName, Dependency, Edition, Env, ExternSource, ExternSourceId, 14 CrateGraph, CrateId, CrateName, Dependency, Edition, Env, ExternSource, ExternSourceId,
15 FileId, SourceRoot, SourceRootId, 15 FileId, ProcMacroId, SourceRoot, SourceRootId,
16 }, 16 },
17}; 17};
18pub use relative_path::{RelativePath, RelativePathBuf}; 18pub use relative_path::{RelativePath, RelativePathBuf};