aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db
diff options
context:
space:
mode:
authorEmil Lauridsen <[email protected]>2020-03-16 12:43:29 +0000
committerEmil Lauridsen <[email protected]>2020-03-17 13:47:05 +0000
commit33c6c7abc6621f8b0cf083a98f7e4788cf4b5b54 (patch)
tree4b763fd11f25db269eacd9302042a54b50eda174 /crates/ra_db
parent2720e2374be951bb762ff2815dd67c7ffe3419b7 (diff)
Support loading OUT_DIR from cargo check at launch
Diffstat (limited to 'crates/ra_db')
-rw-r--r--crates/ra_db/src/input.rs21
1 files changed, 11 insertions, 10 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index bde843001..e371f849d 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -6,7 +6,11 @@
6//! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how 6//! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how
7//! actual IO is done and lowered to input. 7//! actual IO is done and lowered to input.
8 8
9use std::{fmt, ops, str::FromStr}; 9use std::{
10 fmt, ops,
11 path::{Path, PathBuf},
12 str::FromStr,
13};
10 14
11use ra_cfg::CfgOptions; 15use ra_cfg::CfgOptions;
12use ra_syntax::SmolStr; 16use ra_syntax::SmolStr;
@@ -144,7 +148,7 @@ pub struct Env {
144// crate. We store a map to allow remap it to ExternSourceId 148// crate. We store a map to allow remap it to ExternSourceId
145#[derive(Default, Debug, Clone, PartialEq, Eq)] 149#[derive(Default, Debug, Clone, PartialEq, Eq)]
146pub struct ExternSource { 150pub struct ExternSource {
147 extern_paths: FxHashMap<String, ExternSourceId>, 151 extern_paths: FxHashMap<PathBuf, ExternSourceId>,
148} 152}
149 153
150#[derive(Debug, Clone, PartialEq, Eq)] 154#[derive(Debug, Clone, PartialEq, Eq)]
@@ -294,13 +298,10 @@ impl Env {
294} 298}
295 299
296impl ExternSource { 300impl ExternSource {
297 pub fn extern_path(&self, path: &str) -> Option<(ExternSourceId, RelativePathBuf)> { 301 pub fn extern_path(&self, path: impl AsRef<Path>) -> Option<(ExternSourceId, RelativePathBuf)> {
302 let path = path.as_ref();
298 self.extern_paths.iter().find_map(|(root_path, id)| { 303 self.extern_paths.iter().find_map(|(root_path, id)| {
299 if path.starts_with(root_path) { 304 if let Ok(rel_path) = path.strip_prefix(root_path) {
300 let mut rel_path = &path[root_path.len()..];
301 if rel_path.starts_with("/") {
302 rel_path = &rel_path[1..];
303 }
304 let rel_path = RelativePathBuf::from_path(rel_path).ok()?; 305 let rel_path = RelativePathBuf::from_path(rel_path).ok()?;
305 Some((id.clone(), rel_path)) 306 Some((id.clone(), rel_path))
306 } else { 307 } else {
@@ -309,8 +310,8 @@ impl ExternSource {
309 }) 310 })
310 } 311 }
311 312
312 pub fn set_extern_path(&mut self, root_path: &str, root: ExternSourceId) { 313 pub fn set_extern_path(&mut self, root_path: &Path, root: ExternSourceId) {
313 self.extern_paths.insert(root_path.to_owned(), root); 314 self.extern_paths.insert(root_path.to_path_buf(), root);
314 } 315 }
315} 316}
316 317