aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_db/src/input.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index 1a1c64202..18d8e2a53 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -122,9 +122,16 @@ pub enum Edition {
122 Edition2015, 122 Edition2015,
123} 123}
124 124
125#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
126pub struct ExternSourceId(pub u32);
127
125#[derive(Default, Debug, Clone, PartialEq, Eq)] 128#[derive(Default, Debug, Clone, PartialEq, Eq)]
126pub struct Env { 129pub struct Env {
127 entries: FxHashMap<String, String>, 130 entries: FxHashMap<String, String>,
131
132 // Note: Some env variables (e.g. OUT_DIR) are located outside of the
133 // crate. We store a map to allow remap it to ExternSourceId
134 extern_paths: FxHashMap<String, ExternSourceId>,
128} 135}
129 136
130#[derive(Debug, Clone, PartialEq, Eq)] 137#[derive(Debug, Clone, PartialEq, Eq)]
@@ -269,6 +276,26 @@ impl Env {
269 pub fn get(&self, env: &str) -> Option<String> { 276 pub fn get(&self, env: &str) -> Option<String> {
270 self.entries.get(env).cloned() 277 self.entries.get(env).cloned()
271 } 278 }
279
280 pub fn extern_path(&self, path: &str) -> Option<(ExternSourceId, RelativePathBuf)> {
281 self.extern_paths.iter().find_map(|(root_path, id)| {
282 if path.starts_with(root_path) {
283 let mut rel_path = &path[root_path.len()..];
284 if rel_path.starts_with("/") {
285 rel_path = &rel_path[1..];
286 }
287 let rel_path = RelativePathBuf::from_path(rel_path).ok()?;
288 Some((id.clone(), rel_path))
289 } else {
290 None
291 }
292 })
293 }
294
295 pub fn set_extern_path(&mut self, env: &str, 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);
298 }
272} 299}
273 300
274#[derive(Debug)] 301#[derive(Debug)]