diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-25 16:04:48 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-25 16:04:48 +0100 |
commit | 5932bd0bb5fcd066a9d16abcd1597b7097978085 (patch) | |
tree | 7b6ea86855fe34c3d45d14262c8cf94e315566e8 /crates/ra_lsp_server/src/path_map.rs | |
parent | 2cb2074c4b7219b32993abdcc7084637c0123d49 (diff) | |
parent | 363adf07b7763cfe7e13fac0ee148361d51834e4 (diff) |
Merge #162
162: Db everywhere r=matklad a=matklad
This PR continues our switch to salsa.
Now *all* state is handled by a single salsa database.
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/src/path_map.rs')
-rw-r--r-- | crates/ra_lsp_server/src/path_map.rs | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/crates/ra_lsp_server/src/path_map.rs b/crates/ra_lsp_server/src/path_map.rs index d32829382..d5957d673 100644 --- a/crates/ra_lsp_server/src/path_map.rs +++ b/crates/ra_lsp_server/src/path_map.rs | |||
@@ -1,4 +1,7 @@ | |||
1 | use std::path::{Component, Path, PathBuf}; | 1 | use std::{ |
2 | fmt, | ||
3 | path::{Component, Path, PathBuf}, | ||
4 | }; | ||
2 | 5 | ||
3 | use im; | 6 | use im; |
4 | use ra_analysis::{FileId, FileResolver}; | 7 | use ra_analysis::{FileId, FileResolver}; |
@@ -10,7 +13,7 @@ pub enum Root { | |||
10 | Lib, | 13 | Lib, |
11 | } | 14 | } |
12 | 15 | ||
13 | #[derive(Debug, Default, Clone)] | 16 | #[derive(Default, Clone)] |
14 | pub struct PathMap { | 17 | pub struct PathMap { |
15 | next_id: u32, | 18 | next_id: u32, |
16 | path2id: im::HashMap<PathBuf, FileId>, | 19 | path2id: im::HashMap<PathBuf, FileId>, |
@@ -18,19 +21,28 @@ pub struct PathMap { | |||
18 | id2root: im::HashMap<FileId, Root>, | 21 | id2root: im::HashMap<FileId, Root>, |
19 | } | 22 | } |
20 | 23 | ||
24 | impl fmt::Debug for PathMap { | ||
25 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
26 | f.write_str("PathMap { ... }") | ||
27 | } | ||
28 | } | ||
29 | |||
21 | impl PathMap { | 30 | impl PathMap { |
22 | pub fn new() -> PathMap { | 31 | pub fn new() -> PathMap { |
23 | Default::default() | 32 | Default::default() |
24 | } | 33 | } |
25 | pub fn get_or_insert(&mut self, path: PathBuf, root: Root) -> FileId { | 34 | pub fn get_or_insert(&mut self, path: PathBuf, root: Root) -> (bool, FileId) { |
26 | self.path2id | 35 | let mut inserted = false; |
36 | let file_id = self.path2id | ||
27 | .get(path.as_path()) | 37 | .get(path.as_path()) |
28 | .map(|&id| id) | 38 | .map(|&id| id) |
29 | .unwrap_or_else(|| { | 39 | .unwrap_or_else(|| { |
40 | inserted = true; | ||
30 | let id = self.new_file_id(); | 41 | let id = self.new_file_id(); |
31 | self.insert(path, id, root); | 42 | self.insert(path, id, root); |
32 | id | 43 | id |
33 | }) | 44 | }); |
45 | (inserted, file_id) | ||
34 | } | 46 | } |
35 | pub fn get_id(&self, path: &Path) -> Option<FileId> { | 47 | pub fn get_id(&self, path: &Path) -> Option<FileId> { |
36 | self.path2id.get(path).map(|&id| id) | 48 | self.path2id.get(path).map(|&id| id) |
@@ -105,8 +117,8 @@ mod test { | |||
105 | #[test] | 117 | #[test] |
106 | fn test_resolve() { | 118 | fn test_resolve() { |
107 | let mut m = PathMap::new(); | 119 | let mut m = PathMap::new(); |
108 | let id1 = m.get_or_insert(PathBuf::from("/foo"), Root::Workspace); | 120 | let (_, id1) = m.get_or_insert(PathBuf::from("/foo"), Root::Workspace); |
109 | let id2 = m.get_or_insert(PathBuf::from("/foo/bar.rs"), Root::Workspace); | 121 | let (_, id2) = m.get_or_insert(PathBuf::from("/foo/bar.rs"), Root::Workspace); |
110 | assert_eq!(m.resolve(id1, &RelativePath::new("bar.rs")), Some(id2),) | 122 | assert_eq!(m.resolve(id1, &RelativePath::new("bar.rs")), Some(id2),) |
111 | } | 123 | } |
112 | } | 124 | } |