diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-16 14:44:24 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-16 14:44:24 +0100 |
commit | 1216878f7be20dd0e652fb8cdc395009fdcfae07 (patch) | |
tree | 6551967cc8c6e921b66071453ad7888a9121d326 /crates/ra_lsp_server/src/path_map.rs | |
parent | 39cb6c6d3f78b193f5873c3492e530bbd24d5dd2 (diff) | |
parent | 61f3a438d3a729a6be941bca1ff4c6a97a33f221 (diff) |
Merge #134
134: Cargo Format run r=kjeremy a=kjeremy
I'm not sure how appreciated this is but I figured I would run `cargo fmt` and see what came up.
I made sure that `cargo test` still passes.
Co-authored-by: Jeremy A. Kolb <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/src/path_map.rs')
-rw-r--r-- | crates/ra_lsp_server/src/path_map.rs | 28 |
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 @@ | |||
1 | use std::path::{PathBuf, Path, Component}; | ||
2 | use im; | 1 | use im; |
3 | use relative_path::RelativePath; | ||
4 | use ra_analysis::{FileId, FileResolver}; | 2 | use ra_analysis::{FileId, FileResolver}; |
3 | use relative_path::RelativePath; | ||
4 | |||
5 | use std::path::{Component, Path, PathBuf}; | ||
5 | 6 | ||
6 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 7 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
7 | pub enum Root { | 8 | pub 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 | ||
56 | impl FileResolver for PathMap { | 57 | impl 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 | |||