diff options
Diffstat (limited to 'crates/ra_db')
-rw-r--r-- | crates/ra_db/src/input.rs | 21 |
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 | ||
9 | use std::{fmt, ops, str::FromStr}; | 9 | use std::{ |
10 | fmt, ops, | ||
11 | path::{Path, PathBuf}, | ||
12 | str::FromStr, | ||
13 | }; | ||
10 | 14 | ||
11 | use ra_cfg::CfgOptions; | 15 | use ra_cfg::CfgOptions; |
12 | use ra_syntax::SmolStr; | 16 | use 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)] |
146 | pub struct ExternSource { | 150 | pub 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 | ||
296 | impl ExternSource { | 300 | impl 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 | ||