aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2020-03-18 12:56:46 +0000
committerEdwin Cheng <[email protected]>2020-03-25 19:29:45 +0000
commitd0b6ed4441469acfb6bc6555d78abf12637b6cf4 (patch)
treea4b39b33590c472a68fd76ceae96732e9cb54ebb /crates/ra_db
parenta617f24eae6c02f087759312e9aa08507fbecdf0 (diff)
Add ProcMacroClient
Diffstat (limited to 'crates/ra_db')
-rw-r--r--crates/ra_db/Cargo.toml1
-rw-r--r--crates/ra_db/src/fixture.rs4
-rw-r--r--crates/ra_db/src/input.rs15
-rw-r--r--crates/ra_db/src/lib.rs3
4 files changed, 22 insertions, 1 deletions
diff --git a/crates/ra_db/Cargo.toml b/crates/ra_db/Cargo.toml
index 878c22ba9..82fd842a6 100644
--- a/crates/ra_db/Cargo.toml
+++ b/crates/ra_db/Cargo.toml
@@ -15,4 +15,5 @@ rustc-hash = "1.1.0"
15ra_syntax = { path = "../ra_syntax" } 15ra_syntax = { path = "../ra_syntax" }
16ra_cfg = { path = "../ra_cfg" } 16ra_cfg = { path = "../ra_cfg" }
17ra_prof = { path = "../ra_prof" } 17ra_prof = { path = "../ra_prof" }
18ra_proc_macro = { path = "../ra_proc_macro" }
18test_utils = { path = "../test_utils" } 19test_utils = { path = "../test_utils" }
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs
index 3464f43df..9d992886e 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..65b553a9f 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -19,6 +19,7 @@ use rustc_hash::FxHashSet;
19 19
20use crate::{RelativePath, RelativePathBuf}; 20use crate::{RelativePath, RelativePathBuf};
21use fmt::Display; 21use fmt::Display;
22use ra_proc_macro::ProcMacro;
22 23
23/// `FileId` is an integer which uniquely identifies a file. File paths are 24/// `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 25/// messy and system-dependent, so most of the code should work directly with
@@ -115,6 +116,9 @@ impl Display for CrateName {
115 } 116 }
116} 117}
117 118
119#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
120pub struct ProcMacroId(pub usize);
121
118#[derive(Debug, Clone, PartialEq, Eq)] 122#[derive(Debug, Clone, PartialEq, Eq)]
119pub struct CrateData { 123pub struct CrateData {
120 pub root_file_id: FileId, 124 pub root_file_id: FileId,
@@ -127,6 +131,7 @@ pub struct CrateData {
127 pub env: Env, 131 pub env: Env,
128 pub extern_source: ExternSource, 132 pub extern_source: ExternSource,
129 pub dependencies: Vec<Dependency>, 133 pub dependencies: Vec<Dependency>,
134 pub proc_macro: Vec<ProcMacro>,
130} 135}
131 136
132#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 137#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -166,6 +171,7 @@ impl CrateGraph {
166 cfg_options: CfgOptions, 171 cfg_options: CfgOptions,
167 env: Env, 172 env: Env,
168 extern_source: ExternSource, 173 extern_source: ExternSource,
174 proc_macro: Vec<ProcMacro>,
169 ) -> CrateId { 175 ) -> CrateId {
170 let data = CrateData { 176 let data = CrateData {
171 root_file_id: file_id, 177 root_file_id: file_id,
@@ -174,6 +180,7 @@ impl CrateGraph {
174 cfg_options, 180 cfg_options,
175 env, 181 env,
176 extern_source, 182 extern_source,
183 proc_macro,
177 dependencies: Vec::new(), 184 dependencies: Vec::new(),
178 }; 185 };
179 let crate_id = CrateId(self.arena.len() as u32); 186 let crate_id = CrateId(self.arena.len() as u32);
@@ -345,6 +352,7 @@ mod tests {
345 CfgOptions::default(), 352 CfgOptions::default(),
346 Env::default(), 353 Env::default(),
347 Default::default(), 354 Default::default(),
355 Default::default(),
348 ); 356 );
349 let crate2 = graph.add_crate_root( 357 let crate2 = graph.add_crate_root(
350 FileId(2u32), 358 FileId(2u32),
@@ -353,6 +361,7 @@ mod tests {
353 CfgOptions::default(), 361 CfgOptions::default(),
354 Env::default(), 362 Env::default(),
355 Default::default(), 363 Default::default(),
364 Default::default(),
356 ); 365 );
357 let crate3 = graph.add_crate_root( 366 let crate3 = graph.add_crate_root(
358 FileId(3u32), 367 FileId(3u32),
@@ -361,6 +370,7 @@ mod tests {
361 CfgOptions::default(), 370 CfgOptions::default(),
362 Env::default(), 371 Env::default(),
363 Default::default(), 372 Default::default(),
373 Default::default(),
364 ); 374 );
365 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok()); 375 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()); 376 assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok());
@@ -377,6 +387,7 @@ mod tests {
377 CfgOptions::default(), 387 CfgOptions::default(),
378 Env::default(), 388 Env::default(),
379 Default::default(), 389 Default::default(),
390 Default::default(),
380 ); 391 );
381 let crate2 = graph.add_crate_root( 392 let crate2 = graph.add_crate_root(
382 FileId(2u32), 393 FileId(2u32),
@@ -385,6 +396,7 @@ mod tests {
385 CfgOptions::default(), 396 CfgOptions::default(),
386 Env::default(), 397 Env::default(),
387 Default::default(), 398 Default::default(),
399 Default::default(),
388 ); 400 );
389 let crate3 = graph.add_crate_root( 401 let crate3 = graph.add_crate_root(
390 FileId(3u32), 402 FileId(3u32),
@@ -393,6 +405,7 @@ mod tests {
393 CfgOptions::default(), 405 CfgOptions::default(),
394 Env::default(), 406 Env::default(),
395 Default::default(), 407 Default::default(),
408 Default::default(),
396 ); 409 );
397 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok()); 410 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()); 411 assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok());
@@ -408,6 +421,7 @@ mod tests {
408 CfgOptions::default(), 421 CfgOptions::default(),
409 Env::default(), 422 Env::default(),
410 Default::default(), 423 Default::default(),
424 Default::default(),
411 ); 425 );
412 let crate2 = graph.add_crate_root( 426 let crate2 = graph.add_crate_root(
413 FileId(2u32), 427 FileId(2u32),
@@ -416,6 +430,7 @@ mod tests {
416 CfgOptions::default(), 430 CfgOptions::default(),
417 Env::default(), 431 Env::default(),
418 Default::default(), 432 Default::default(),
433 Default::default(),
419 ); 434 );
420 assert!(graph 435 assert!(graph
421 .add_dep(crate1, CrateName::normalize_dashes("crate-name-with-dashes"), crate2) 436 .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..5829ae465 100644
--- a/crates/ra_db/src/lib.rs
+++ b/crates/ra_db/src/lib.rs
@@ -12,9 +12,10 @@ 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 ra_proc_macro::ProcMacro;
18pub use relative_path::{RelativePath, RelativePathBuf}; 19pub use relative_path::{RelativePath, RelativePathBuf};
19pub use salsa; 20pub use salsa;
20 21