aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_db/src/fixture.rs12
-rw-r--r--crates/ra_db/src/input.rs24
-rw-r--r--crates/ra_db/src/lib.rs4
-rw-r--r--crates/ra_hir_expand/src/builtin_macro.rs3
-rw-r--r--crates/ra_ide/src/lib.rs1
-rw-r--r--crates/ra_ide/src/mock_analysis.rs2
-rw-r--r--crates/ra_ide/src/parent_module.rs1
-rw-r--r--crates/ra_project_model/src/lib.rs13
8 files changed, 49 insertions, 11 deletions
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs
index 7f43c2971..3dc86ca2d 100644
--- a/crates/ra_db/src/fixture.rs
+++ b/crates/ra_db/src/fixture.rs
@@ -61,7 +61,14 @@ fn with_single_file(db: &mut dyn SourceDatabaseExt, ra_fixture: &str) -> FileId
61 }; 61 };
62 62
63 let mut crate_graph = CrateGraph::default(); 63 let mut crate_graph = CrateGraph::default();
64 crate_graph.add_crate_root(file_id, meta.edition, meta.krate, meta.cfg, meta.env); 64 crate_graph.add_crate_root(
65 file_id,
66 meta.edition,
67 meta.krate,
68 meta.cfg,
69 meta.env,
70 Default::default(),
71 );
65 crate_graph 72 crate_graph
66 } else { 73 } else {
67 let mut crate_graph = CrateGraph::default(); 74 let mut crate_graph = CrateGraph::default();
@@ -71,6 +78,7 @@ fn with_single_file(db: &mut dyn SourceDatabaseExt, ra_fixture: &str) -> FileId
71 None, 78 None,
72 CfgOptions::default(), 79 CfgOptions::default(),
73 Env::default(), 80 Env::default(),
81 Default::default(),
74 ); 82 );
75 crate_graph 83 crate_graph
76 }; 84 };
@@ -119,6 +127,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
119 Some(krate.clone()), 127 Some(krate.clone()),
120 meta.cfg, 128 meta.cfg,
121 meta.env, 129 meta.env,
130 Default::default(),
122 ); 131 );
123 let prev = crates.insert(krate.clone(), crate_id); 132 let prev = crates.insert(krate.clone(), crate_id);
124 assert!(prev.is_none()); 133 assert!(prev.is_none());
@@ -155,6 +164,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
155 None, 164 None,
156 CfgOptions::default(), 165 CfgOptions::default(),
157 Env::default(), 166 Env::default(),
167 Default::default(),
158 ); 168 );
159 } else { 169 } else {
160 for (from, to) in crate_deps { 170 for (from, to) in crate_deps {
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index 18d8e2a53..06d40db96 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -113,6 +113,7 @@ pub struct CrateData {
113 pub display_name: Option<String>, 113 pub display_name: Option<String>,
114 pub cfg_options: CfgOptions, 114 pub cfg_options: CfgOptions,
115 pub env: Env, 115 pub env: Env,
116 pub extern_source: ExternSource,
116 pub dependencies: Vec<Dependency>, 117 pub dependencies: Vec<Dependency>,
117} 118}
118 119
@@ -128,9 +129,13 @@ pub struct ExternSourceId(pub u32);
128#[derive(Default, Debug, Clone, PartialEq, Eq)] 129#[derive(Default, Debug, Clone, PartialEq, Eq)]
129pub struct Env { 130pub struct Env {
130 entries: FxHashMap<String, String>, 131 entries: FxHashMap<String, String>,
132}
131 133
132 // Note: Some env variables (e.g. OUT_DIR) are located outside of the 134// FIXME: Redesign vfs for solve the following limitation ?
133 // crate. We store a map to allow remap it to ExternSourceId 135// Note: Some env variables (e.g. OUT_DIR) are located outside of the
136// crate. We store a map to allow remap it to ExternSourceId
137#[derive(Default, Debug, Clone, PartialEq, Eq)]
138pub struct ExternSource {
134 extern_paths: FxHashMap<String, ExternSourceId>, 139 extern_paths: FxHashMap<String, ExternSourceId>,
135} 140}
136 141
@@ -148,6 +153,7 @@ impl CrateGraph {
148 display_name: Option<String>, 153 display_name: Option<String>,
149 cfg_options: CfgOptions, 154 cfg_options: CfgOptions,
150 env: Env, 155 env: Env,
156 extern_source: ExternSource,
151 ) -> CrateId { 157 ) -> CrateId {
152 let data = CrateData { 158 let data = CrateData {
153 root_file_id: file_id, 159 root_file_id: file_id,
@@ -155,6 +161,7 @@ impl CrateGraph {
155 display_name, 161 display_name,
156 cfg_options, 162 cfg_options,
157 env, 163 env,
164 extern_source,
158 dependencies: Vec::new(), 165 dependencies: Vec::new(),
159 }; 166 };
160 let crate_id = CrateId(self.arena.len() as u32); 167 let crate_id = CrateId(self.arena.len() as u32);
@@ -276,7 +283,9 @@ impl Env {
276 pub fn get(&self, env: &str) -> Option<String> { 283 pub fn get(&self, env: &str) -> Option<String> {
277 self.entries.get(env).cloned() 284 self.entries.get(env).cloned()
278 } 285 }
286}
279 287
288impl ExternSource {
280 pub fn extern_path(&self, path: &str) -> Option<(ExternSourceId, RelativePathBuf)> { 289 pub fn extern_path(&self, path: &str) -> Option<(ExternSourceId, RelativePathBuf)> {
281 self.extern_paths.iter().find_map(|(root_path, id)| { 290 self.extern_paths.iter().find_map(|(root_path, id)| {
282 if path.starts_with(root_path) { 291 if path.starts_with(root_path) {
@@ -292,8 +301,7 @@ impl Env {
292 }) 301 })
293 } 302 }
294 303
295 pub fn set_extern_path(&mut self, env: &str, root_path: &str, root: ExternSourceId) { 304 pub fn set_extern_path(&mut self, root_path: &str, root: ExternSourceId) {
296 self.entries.insert(env.to_owned(), root_path.to_owned());
297 self.extern_paths.insert(root_path.to_owned(), root); 305 self.extern_paths.insert(root_path.to_owned(), root);
298 } 306 }
299} 307}
@@ -327,6 +335,7 @@ mod tests {
327 None, 335 None,
328 CfgOptions::default(), 336 CfgOptions::default(),
329 Env::default(), 337 Env::default(),
338 Default::default(),
330 ); 339 );
331 let crate2 = graph.add_crate_root( 340 let crate2 = graph.add_crate_root(
332 FileId(2u32), 341 FileId(2u32),
@@ -334,6 +343,7 @@ mod tests {
334 None, 343 None,
335 CfgOptions::default(), 344 CfgOptions::default(),
336 Env::default(), 345 Env::default(),
346 Default::default(),
337 ); 347 );
338 let crate3 = graph.add_crate_root( 348 let crate3 = graph.add_crate_root(
339 FileId(3u32), 349 FileId(3u32),
@@ -341,6 +351,7 @@ mod tests {
341 None, 351 None,
342 CfgOptions::default(), 352 CfgOptions::default(),
343 Env::default(), 353 Env::default(),
354 Default::default(),
344 ); 355 );
345 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok()); 356 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok());
346 assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok()); 357 assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok());
@@ -356,6 +367,7 @@ mod tests {
356 None, 367 None,
357 CfgOptions::default(), 368 CfgOptions::default(),
358 Env::default(), 369 Env::default(),
370 Default::default(),
359 ); 371 );
360 let crate2 = graph.add_crate_root( 372 let crate2 = graph.add_crate_root(
361 FileId(2u32), 373 FileId(2u32),
@@ -363,6 +375,7 @@ mod tests {
363 None, 375 None,
364 CfgOptions::default(), 376 CfgOptions::default(),
365 Env::default(), 377 Env::default(),
378 Default::default(),
366 ); 379 );
367 let crate3 = graph.add_crate_root( 380 let crate3 = graph.add_crate_root(
368 FileId(3u32), 381 FileId(3u32),
@@ -370,6 +383,7 @@ mod tests {
370 None, 383 None,
371 CfgOptions::default(), 384 CfgOptions::default(),
372 Env::default(), 385 Env::default(),
386 Default::default(),
373 ); 387 );
374 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok()); 388 assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok());
375 assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok()); 389 assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok());
@@ -384,6 +398,7 @@ mod tests {
384 None, 398 None,
385 CfgOptions::default(), 399 CfgOptions::default(),
386 Env::default(), 400 Env::default(),
401 Default::default(),
387 ); 402 );
388 let crate2 = graph.add_crate_root( 403 let crate2 = graph.add_crate_root(
389 FileId(2u32), 404 FileId(2u32),
@@ -391,6 +406,7 @@ mod tests {
391 None, 406 None,
392 CfgOptions::default(), 407 CfgOptions::default(),
393 Env::default(), 408 Env::default(),
409 Default::default(),
394 ); 410 );
395 assert!(graph 411 assert!(graph
396 .add_dep(crate1, CrateName::normalize_dashes("crate-name-with-dashes"), crate2) 412 .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 9bf3fe248..d500d5e85 100644
--- a/crates/ra_db/src/lib.rs
+++ b/crates/ra_db/src/lib.rs
@@ -11,8 +11,8 @@ use ra_syntax::{ast, Parse, SourceFile, TextRange, TextUnit};
11pub use crate::{ 11pub use crate::{
12 cancellation::Canceled, 12 cancellation::Canceled,
13 input::{ 13 input::{
14 CrateGraph, CrateId, CrateName, Dependency, Edition, Env, ExternSourceId, FileId, 14 CrateGraph, CrateId, CrateName, Dependency, Edition, Env, ExternSource, ExternSourceId,
15 SourceRoot, SourceRootId, 15 FileId, SourceRoot, SourceRootId,
16 }, 16 },
17}; 17};
18pub use relative_path::{RelativePath, RelativePathBuf}; 18pub use relative_path::{RelativePath, RelativePathBuf};
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs
index 298ec22ff..a90007f26 100644
--- a/crates/ra_hir_expand/src/builtin_macro.rs
+++ b/crates/ra_hir_expand/src/builtin_macro.rs
@@ -262,7 +262,8 @@ fn relative_file(db: &dyn AstDatabase, call_id: MacroCallId, path: &str) -> Opti
262 262
263 // Extern paths ? 263 // Extern paths ?
264 let krate = db.relevant_crates(call_site).get(0)?.clone(); 264 let krate = db.relevant_crates(call_site).get(0)?.clone();
265 let (extern_source_id, relative_file) = db.crate_graph()[krate].env.extern_path(path)?; 265 let (extern_source_id, relative_file) =
266 db.crate_graph()[krate].extern_source.extern_path(path)?;
266 267
267 db.resolve_extern_path(extern_source_id, &relative_file) 268 db.resolve_extern_path(extern_source_id, &relative_file)
268} 269}
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index c60e86aea..39981ed3b 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -217,6 +217,7 @@ impl Analysis {
217 None, 217 None,
218 cfg_options, 218 cfg_options,
219 Env::default(), 219 Env::default(),
220 Default::default(),
220 ); 221 );
221 change.add_file(source_root, file_id, "main.rs".into(), Arc::new(text)); 222 change.add_file(source_root, file_id, "main.rs".into(), Arc::new(text));
222 change.set_crate_graph(crate_graph); 223 change.set_crate_graph(crate_graph);
diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs
index 90f84b052..25816cf6f 100644
--- a/crates/ra_ide/src/mock_analysis.rs
+++ b/crates/ra_ide/src/mock_analysis.rs
@@ -102,6 +102,7 @@ impl MockAnalysis {
102 None, 102 None,
103 cfg_options, 103 cfg_options,
104 Env::default(), 104 Env::default(),
105 Default::default(),
105 )); 106 ));
106 } else if path.ends_with("/lib.rs") { 107 } else if path.ends_with("/lib.rs") {
107 let crate_name = path.parent().unwrap().file_name().unwrap(); 108 let crate_name = path.parent().unwrap().file_name().unwrap();
@@ -111,6 +112,7 @@ impl MockAnalysis {
111 Some(crate_name.to_owned()), 112 Some(crate_name.to_owned()),
112 cfg_options, 113 cfg_options,
113 Env::default(), 114 Env::default(),
115 Default::default(),
114 ); 116 );
115 if let Some(root_crate) = root_crate { 117 if let Some(root_crate) = root_crate {
116 crate_graph 118 crate_graph
diff --git a/crates/ra_ide/src/parent_module.rs b/crates/ra_ide/src/parent_module.rs
index b73cefd97..76d130b9b 100644
--- a/crates/ra_ide/src/parent_module.rs
+++ b/crates/ra_ide/src/parent_module.rs
@@ -136,6 +136,7 @@ mod tests {
136 None, 136 None,
137 CfgOptions::default(), 137 CfgOptions::default(),
138 Env::default(), 138 Env::default(),
139 Default::default(),
139 ); 140 );
140 let mut change = AnalysisChange::new(); 141 let mut change = AnalysisChange::new();
141 change.set_crate_graph(crate_graph); 142 change.set_crate_graph(crate_graph);
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index b46320304..a6274709d 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -14,7 +14,7 @@ use std::{
14 14
15use anyhow::{bail, Context, Result}; 15use anyhow::{bail, Context, Result};
16use ra_cfg::CfgOptions; 16use ra_cfg::CfgOptions;
17use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSourceId, FileId}; 17use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSource, ExternSourceId, FileId};
18use rustc_hash::FxHashMap; 18use rustc_hash::FxHashMap;
19use serde_json::from_reader; 19use serde_json::from_reader;
20 20
@@ -197,6 +197,7 @@ impl ProjectWorkspace {
197 None, 197 None,
198 cfg_options, 198 cfg_options,
199 Env::default(), 199 Env::default(),
200 Default::default(),
200 ), 201 ),
201 ); 202 );
202 } 203 }
@@ -235,8 +236,10 @@ impl ProjectWorkspace {
235 }; 236 };
236 237
237 let mut env = Env::default(); 238 let mut env = Env::default();
239 let mut extern_source = ExternSource::default();
238 if let Some((id, path)) = outdirs.get(krate.name(&sysroot)) { 240 if let Some((id, path)) = outdirs.get(krate.name(&sysroot)) {
239 env.set_extern_path("OUT_DIR", &path, *id); 241 env.set("OUT_DIR", path.clone());
242 extern_source.set_extern_path(&path, *id);
240 } 243 }
241 244
242 let crate_id = crate_graph.add_crate_root( 245 let crate_id = crate_graph.add_crate_root(
@@ -245,6 +248,7 @@ impl ProjectWorkspace {
245 Some(krate.name(&sysroot).to_string()), 248 Some(krate.name(&sysroot).to_string()),
246 cfg_options, 249 cfg_options,
247 env, 250 env,
251 extern_source,
248 ); 252 );
249 sysroot_crates.insert(krate, crate_id); 253 sysroot_crates.insert(krate, crate_id);
250 } 254 }
@@ -284,8 +288,10 @@ impl ProjectWorkspace {
284 opts 288 opts
285 }; 289 };
286 let mut env = Env::default(); 290 let mut env = Env::default();
291 let mut extern_source = ExternSource::default();
287 if let Some((id, path)) = outdirs.get(pkg.name(&cargo)) { 292 if let Some((id, path)) = outdirs.get(pkg.name(&cargo)) {
288 env.set_extern_path("OUT_DIR", &path, *id); 293 env.set("OUT_DIR", path.clone());
294 extern_source.set_extern_path(&path, *id);
289 } 295 }
290 let crate_id = crate_graph.add_crate_root( 296 let crate_id = crate_graph.add_crate_root(
291 file_id, 297 file_id,
@@ -293,6 +299,7 @@ impl ProjectWorkspace {
293 Some(pkg.name(&cargo).to_string()), 299 Some(pkg.name(&cargo).to_string()),
294 cfg_options, 300 cfg_options,
295 env, 301 env,
302 extern_source,
296 ); 303 );
297 if tgt.kind(&cargo) == TargetKind::Lib { 304 if tgt.kind(&cargo) == TargetKind::Lib {
298 lib_tgt = Some(crate_id); 305 lib_tgt = Some(crate_id);