diff options
author | Aleksey Kladov <[email protected]> | 2018-12-19 12:40:42 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-12-20 09:15:38 +0000 |
commit | 7b6bafa631e6272946da568e9da7c3adc01ba625 (patch) | |
tree | f71e26828c40a79e50a21ab284c4123b741735f9 /crates/ra_vfs/src | |
parent | a5ef8ad05b7c1f7148c59814b55d641fd75aff75 (diff) |
fix syc
Diffstat (limited to 'crates/ra_vfs/src')
-rw-r--r-- | crates/ra_vfs/src/lib.rs | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs index dc980c3d2..3a68039f0 100644 --- a/crates/ra_vfs/src/lib.rs +++ b/crates/ra_vfs/src/lib.rs | |||
@@ -132,6 +132,7 @@ impl Vfs { | |||
132 | roots.sort_by_key(|it| Reverse(it.as_os_str().len())); | 132 | roots.sort_by_key(|it| Reverse(it.as_os_str().len())); |
133 | for (i, path) in roots.iter().enumerate() { | 133 | for (i, path) in roots.iter().enumerate() { |
134 | let root = res.roots.alloc(RootFilter::new(path.clone())); | 134 | let root = res.roots.alloc(RootFilter::new(path.clone())); |
135 | res.root2files.insert(root, Default::default()); | ||
135 | let nested = roots[..i] | 136 | let nested = roots[..i] |
136 | .iter() | 137 | .iter() |
137 | .filter(|it| it.starts_with(path)) | 138 | .filter(|it| it.starts_with(path)) |
@@ -155,6 +156,10 @@ impl Vfs { | |||
155 | (res, roots) | 156 | (res, roots) |
156 | } | 157 | } |
157 | 158 | ||
159 | pub fn root2path(&self, root: VfsRoot) -> PathBuf { | ||
160 | self.roots[root].root.clone() | ||
161 | } | ||
162 | |||
158 | pub fn path2file(&self, path: &Path) -> Option<VfsFile> { | 163 | pub fn path2file(&self, path: &Path) -> Option<VfsFile> { |
159 | if let Some((_root, _path, Some(file))) = self.find_root(path) { | 164 | if let Some((_root, _path, Some(file))) = self.find_root(path) { |
160 | return Some(file); | 165 | return Some(file); |
@@ -176,6 +181,23 @@ impl Vfs { | |||
176 | } | 181 | } |
177 | 182 | ||
178 | pub fn load(&mut self, path: &Path) -> Option<VfsFile> { | 183 | pub fn load(&mut self, path: &Path) -> Option<VfsFile> { |
184 | if let Some((root, rel_path, file)) = self.find_root(path) { | ||
185 | return if let Some(file) = file { | ||
186 | Some(file) | ||
187 | } else { | ||
188 | let text = fs::read_to_string(path).unwrap_or_default(); | ||
189 | let text = Arc::new(text); | ||
190 | let file = self.add_file(root, rel_path.clone(), Arc::clone(&text)); | ||
191 | let change = VfsChange::AddFile { | ||
192 | file, | ||
193 | text, | ||
194 | root, | ||
195 | path: rel_path, | ||
196 | }; | ||
197 | self.pending_changes.push(change); | ||
198 | Some(file) | ||
199 | }; | ||
200 | } | ||
179 | None | 201 | None |
180 | } | 202 | } |
181 | 203 | ||
@@ -262,10 +284,7 @@ impl Vfs { | |||
262 | fn add_file(&mut self, root: VfsRoot, path: RelativePathBuf, text: Arc<String>) -> VfsFile { | 284 | fn add_file(&mut self, root: VfsRoot, path: RelativePathBuf, text: Arc<String>) -> VfsFile { |
263 | let data = VfsFileData { root, path, text }; | 285 | let data = VfsFileData { root, path, text }; |
264 | let file = self.files.alloc(data); | 286 | let file = self.files.alloc(data); |
265 | self.root2files | 287 | self.root2files.get_mut(&root).unwrap().insert(file); |
266 | .entry(root) | ||
267 | .or_insert_with(FxHashSet::default) | ||
268 | .insert(file); | ||
269 | file | 288 | file |
270 | } | 289 | } |
271 | 290 | ||