diff options
author | Aleksey Kladov <[email protected]> | 2018-10-25 08:57:55 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-10-25 14:25:40 +0100 |
commit | ee4d904cfb1b604bc8627491e05980ac43cd59e3 (patch) | |
tree | 54d1b937de544b8f6a8f2821ad9599aa82192375 /crates/ra_lsp_server/src/path_map.rs | |
parent | 2cb2074c4b7219b32993abdcc7084637c0123d49 (diff) |
Store all the data in the Salsa Database
Diffstat (limited to 'crates/ra_lsp_server/src/path_map.rs')
-rw-r--r-- | crates/ra_lsp_server/src/path_map.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/crates/ra_lsp_server/src/path_map.rs b/crates/ra_lsp_server/src/path_map.rs index d32829382..b3d1dc3db 100644 --- a/crates/ra_lsp_server/src/path_map.rs +++ b/crates/ra_lsp_server/src/path_map.rs | |||
@@ -22,15 +22,18 @@ impl PathMap { | |||
22 | pub fn new() -> PathMap { | 22 | pub fn new() -> PathMap { |
23 | Default::default() | 23 | Default::default() |
24 | } | 24 | } |
25 | pub fn get_or_insert(&mut self, path: PathBuf, root: Root) -> FileId { | 25 | pub fn get_or_insert(&mut self, path: PathBuf, root: Root) -> (bool, FileId) { |
26 | self.path2id | 26 | let mut inserted = false; |
27 | let file_id = self.path2id | ||
27 | .get(path.as_path()) | 28 | .get(path.as_path()) |
28 | .map(|&id| id) | 29 | .map(|&id| id) |
29 | .unwrap_or_else(|| { | 30 | .unwrap_or_else(|| { |
31 | inserted = true; | ||
30 | let id = self.new_file_id(); | 32 | let id = self.new_file_id(); |
31 | self.insert(path, id, root); | 33 | self.insert(path, id, root); |
32 | id | 34 | id |
33 | }) | 35 | }); |
36 | (inserted, file_id) | ||
34 | } | 37 | } |
35 | pub fn get_id(&self, path: &Path) -> Option<FileId> { | 38 | pub fn get_id(&self, path: &Path) -> Option<FileId> { |
36 | self.path2id.get(path).map(|&id| id) | 39 | self.path2id.get(path).map(|&id| id) |
@@ -105,8 +108,8 @@ mod test { | |||
105 | #[test] | 108 | #[test] |
106 | fn test_resolve() { | 109 | fn test_resolve() { |
107 | let mut m = PathMap::new(); | 110 | let mut m = PathMap::new(); |
108 | let id1 = m.get_or_insert(PathBuf::from("/foo"), Root::Workspace); | 111 | 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); | 112 | 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),) | 113 | assert_eq!(m.resolve(id1, &RelativePath::new("bar.rs")), Some(id2),) |
111 | } | 114 | } |
112 | } | 115 | } |