aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/path_map.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src/path_map.rs')
-rw-r--r--crates/ra_lsp_server/src/path_map.rs28
1 files changed, 15 insertions, 13 deletions
diff --git a/crates/ra_lsp_server/src/path_map.rs b/crates/ra_lsp_server/src/path_map.rs
index 19c3b1d3b..585013acd 100644
--- a/crates/ra_lsp_server/src/path_map.rs
+++ b/crates/ra_lsp_server/src/path_map.rs
@@ -1,11 +1,13 @@
1use std::path::{PathBuf, Path, Component};
2use im; 1use im;
3use relative_path::RelativePath;
4use ra_analysis::{FileId, FileResolver}; 2use ra_analysis::{FileId, FileResolver};
3use relative_path::RelativePath;
4
5use std::path::{Component, Path, PathBuf};
5 6
6#[derive(Debug, Clone, Copy, PartialEq, Eq)] 7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum Root { 8pub enum Root {
8 Workspace, Lib 9 Workspace,
10 Lib,
9} 11}
10 12
11#[derive(Debug, Default, Clone)] 13#[derive(Debug, Default, Clone)]
@@ -21,7 +23,8 @@ impl PathMap {
21 Default::default() 23 Default::default()
22 } 24 }
23 pub fn get_or_insert(&mut self, path: PathBuf, root: Root) -> FileId { 25 pub fn get_or_insert(&mut self, path: PathBuf, root: Root) -> FileId {
24 self.path2id.get(path.as_path()) 26 self.path2id
27 .get(path.as_path())
25 .map(|&id| id) 28 .map(|&id| id)
26 .unwrap_or_else(|| { 29 .unwrap_or_else(|| {
27 let id = self.new_file_id(); 30 let id = self.new_file_id();
@@ -33,9 +36,7 @@ impl PathMap {
33 self.path2id.get(path).map(|&id| id) 36 self.path2id.get(path).map(|&id| id)
34 } 37 }
35 pub fn get_path(&self, file_id: FileId) -> &Path { 38 pub fn get_path(&self, file_id: FileId) -> &Path {
36 self.id2path.get(&file_id) 39 self.id2path.get(&file_id).unwrap().as_path()
37 .unwrap()
38 .as_path()
39 } 40 }
40 pub fn get_root(&self, file_id: FileId) -> Root { 41 pub fn get_root(&self, file_id: FileId) -> Root {
41 self.id2root[&file_id] 42 self.id2root[&file_id]
@@ -55,7 +56,12 @@ impl PathMap {
55 56
56impl FileResolver for PathMap { 57impl FileResolver for PathMap {
57 fn file_stem(&self, file_id: FileId) -> String { 58 fn file_stem(&self, file_id: FileId) -> String {
58 self.get_path(file_id).file_stem().unwrap().to_str().unwrap().to_string() 59 self.get_path(file_id)
60 .file_stem()
61 .unwrap()
62 .to_str()
63 .unwrap()
64 .to_string()
59 } 65 }
60 66
61 fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option<FileId> { 67 fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option<FileId> {
@@ -101,10 +107,6 @@ mod test {
101 let mut m = PathMap::new(); 107 let mut m = PathMap::new();
102 let id1 = m.get_or_insert(PathBuf::from("/foo"), Root::Workspace); 108 let id1 = m.get_or_insert(PathBuf::from("/foo"), Root::Workspace);
103 let id2 = m.get_or_insert(PathBuf::from("/foo/bar.rs"), Root::Workspace); 109 let id2 = m.get_or_insert(PathBuf::from("/foo/bar.rs"), Root::Workspace);
104 assert_eq!( 110 assert_eq!(m.resolve(id1, &RelativePath::new("bar.rs")), Some(id2),)
105 m.resolve(id1, &RelativePath::new("bar.rs")),
106 Some(id2),
107 )
108 } 111 }
109} 112}
110