diff options
-rw-r--r-- | crates/ra_vfs/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_vfs/src/lib.rs | 40 |
2 files changed, 23 insertions, 18 deletions
diff --git a/crates/ra_vfs/Cargo.toml b/crates/ra_vfs/Cargo.toml index 2da5c499b..451daed1b 100644 --- a/crates/ra_vfs/Cargo.toml +++ b/crates/ra_vfs/Cargo.toml | |||
@@ -15,7 +15,6 @@ drop_bomb = "0.1.0" | |||
15 | parking_lot = "0.7.0" | 15 | parking_lot = "0.7.0" |
16 | 16 | ||
17 | thread_worker = { path = "../thread_worker" } | 17 | thread_worker = { path = "../thread_worker" } |
18 | ra_arena = { path = "../ra_arena" } | ||
19 | 18 | ||
20 | [dev-dependencies] | 19 | [dev-dependencies] |
21 | tempfile = "3" | 20 | tempfile = "3" |
diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs index 1c5402aed..d07bc5694 100644 --- a/crates/ra_vfs/src/lib.rs +++ b/crates/ra_vfs/src/lib.rs | |||
@@ -25,7 +25,6 @@ use std::{ | |||
25 | }; | 25 | }; |
26 | 26 | ||
27 | use crossbeam_channel::Receiver; | 27 | use crossbeam_channel::Receiver; |
28 | use ra_arena::{impl_arena_id, Arena, RawId}; | ||
29 | use relative_path::{RelativePath, RelativePathBuf}; | 28 | use relative_path::{RelativePath, RelativePathBuf}; |
30 | use rustc_hash::{FxHashMap, FxHashSet}; | 29 | use rustc_hash::{FxHashMap, FxHashSet}; |
31 | 30 | ||
@@ -40,8 +39,7 @@ pub use crate::{ | |||
40 | }; | 39 | }; |
41 | 40 | ||
42 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 41 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
43 | pub struct VfsFile(pub RawId); | 42 | pub struct VfsFile(pub u32); |
44 | impl_arena_id!(VfsFile); | ||
45 | 43 | ||
46 | struct VfsFileData { | 44 | struct VfsFileData { |
47 | root: VfsRoot, | 45 | root: VfsRoot, |
@@ -52,7 +50,7 @@ struct VfsFileData { | |||
52 | 50 | ||
53 | pub struct Vfs { | 51 | pub struct Vfs { |
54 | roots: Arc<Roots>, | 52 | roots: Arc<Roots>, |
55 | files: Arena<VfsFile, VfsFileData>, | 53 | files: Vec<VfsFileData>, |
56 | root2files: FxHashMap<VfsRoot, FxHashSet<VfsFile>>, | 54 | root2files: FxHashMap<VfsRoot, FxHashSet<VfsFile>>, |
57 | pending_changes: Vec<VfsChange>, | 55 | pending_changes: Vec<VfsChange>, |
58 | worker: Worker, | 56 | worker: Worker, |
@@ -78,8 +76,7 @@ impl Vfs { | |||
78 | root2files.insert(root, Default::default()); | 76 | root2files.insert(root, Default::default()); |
79 | worker.sender().send(io::Task::AddRoot { root }).unwrap(); | 77 | worker.sender().send(io::Task::AddRoot { root }).unwrap(); |
80 | } | 78 | } |
81 | let res = | 79 | let res = Vfs { roots, files: Vec::new(), root2files, worker, pending_changes: Vec::new() }; |
82 | Vfs { roots, files: Arena::default(), root2files, worker, pending_changes: Vec::new() }; | ||
83 | let vfs_roots = res.roots.iter().collect(); | 80 | let vfs_roots = res.roots.iter().collect(); |
84 | (res, vfs_roots) | 81 | (res, vfs_roots) |
85 | } | 82 | } |
@@ -96,8 +93,8 @@ impl Vfs { | |||
96 | } | 93 | } |
97 | 94 | ||
98 | pub fn file2path(&self, file: VfsFile) -> PathBuf { | 95 | pub fn file2path(&self, file: VfsFile) -> PathBuf { |
99 | let rel_path = &self.files[file].path; | 96 | let rel_path = &self.file(file).path; |
100 | let root_path = &self.roots.path(self.files[file].root); | 97 | let root_path = &self.roots.path(self.file(file).root); |
101 | rel_path.to_path(root_path) | 98 | rel_path.to_path(root_path) |
102 | } | 99 | } |
103 | 100 | ||
@@ -166,11 +163,11 @@ impl Vfs { | |||
166 | // been open in the editor, so we need to account for that. | 163 | // been open in the editor, so we need to account for that. |
167 | let existing = self.root2files[&root] | 164 | let existing = self.root2files[&root] |
168 | .iter() | 165 | .iter() |
169 | .map(|&file| (self.files[file].path.clone(), file)) | 166 | .map(|&file| (self.file(file).path.clone(), file)) |
170 | .collect::<FxHashMap<_, _>>(); | 167 | .collect::<FxHashMap<_, _>>(); |
171 | for (path, text) in files { | 168 | for (path, text) in files { |
172 | if let Some(&file) = existing.get(&path) { | 169 | if let Some(&file) = existing.get(&path) { |
173 | let text = Arc::clone(&self.files[file].text); | 170 | let text = Arc::clone(&self.file(file).text); |
174 | cur_files.push((file, path, text)); | 171 | cur_files.push((file, path, text)); |
175 | continue; | 172 | continue; |
176 | } | 173 | } |
@@ -184,7 +181,7 @@ impl Vfs { | |||
184 | } | 181 | } |
185 | TaskResult::SingleFile { root, path, text } => { | 182 | TaskResult::SingleFile { root, path, text } => { |
186 | let existing_file = self.find_file(root, &path); | 183 | let existing_file = self.find_file(root, &path); |
187 | if existing_file.map(|file| self.files[file].is_overlayed) == Some(true) { | 184 | if existing_file.map(|file| self.file(file).is_overlayed) == Some(true) { |
188 | return; | 185 | return; |
189 | } | 186 | } |
190 | match (existing_file, text) { | 187 | match (existing_file, text) { |
@@ -240,22 +237,23 @@ impl Vfs { | |||
240 | is_overlayed: bool, | 237 | is_overlayed: bool, |
241 | ) -> VfsFile { | 238 | ) -> VfsFile { |
242 | let data = VfsFileData { root, path, text, is_overlayed }; | 239 | let data = VfsFileData { root, path, text, is_overlayed }; |
243 | let file = self.files.alloc(data); | 240 | let file = VfsFile(self.files.len() as u32); |
241 | self.files.push(data); | ||
244 | self.root2files.get_mut(&root).unwrap().insert(file); | 242 | self.root2files.get_mut(&root).unwrap().insert(file); |
245 | file | 243 | file |
246 | } | 244 | } |
247 | 245 | ||
248 | fn raw_change_file(&mut self, file: VfsFile, new_text: Arc<String>, is_overlayed: bool) { | 246 | fn raw_change_file(&mut self, file: VfsFile, new_text: Arc<String>, is_overlayed: bool) { |
249 | let mut file_data = &mut self.files[file]; | 247 | let mut file_data = &mut self.file_mut(file); |
250 | file_data.text = new_text; | 248 | file_data.text = new_text; |
251 | file_data.is_overlayed = is_overlayed; | 249 | file_data.is_overlayed = is_overlayed; |
252 | } | 250 | } |
253 | 251 | ||
254 | fn raw_remove_file(&mut self, file: VfsFile) { | 252 | fn raw_remove_file(&mut self, file: VfsFile) { |
255 | // FIXME: use arena with removal | 253 | // FIXME: use arena with removal |
256 | self.files[file].text = Default::default(); | 254 | self.file_mut(file).text = Default::default(); |
257 | self.files[file].path = Default::default(); | 255 | self.file_mut(file).path = Default::default(); |
258 | let root = self.files[file].root; | 256 | let root = self.file(file).root; |
259 | let removed = self.root2files.get_mut(&root).unwrap().remove(&file); | 257 | let removed = self.root2files.get_mut(&root).unwrap().remove(&file); |
260 | assert!(removed); | 258 | assert!(removed); |
261 | } | 259 | } |
@@ -267,7 +265,15 @@ impl Vfs { | |||
267 | } | 265 | } |
268 | 266 | ||
269 | fn find_file(&self, root: VfsRoot, path: &RelativePath) -> Option<VfsFile> { | 267 | fn find_file(&self, root: VfsRoot, path: &RelativePath) -> Option<VfsFile> { |
270 | self.root2files[&root].iter().map(|&it| it).find(|&file| self.files[file].path == path) | 268 | self.root2files[&root].iter().map(|&it| it).find(|&file| self.file(file).path == path) |
269 | } | ||
270 | |||
271 | fn file(&self, file: VfsFile) -> &VfsFileData { | ||
272 | &self.files[file.0 as usize] | ||
273 | } | ||
274 | |||
275 | fn file_mut(&mut self, file: VfsFile) -> &mut VfsFileData { | ||
276 | &mut self.files[file.0 as usize] | ||
271 | } | 277 | } |
272 | } | 278 | } |
273 | 279 | ||