diff options
author | Aleksey Kladov <[email protected]> | 2019-02-17 18:10:40 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-17 18:10:40 +0000 |
commit | aea986001fe42398589871b13e3a307d23f83461 (patch) | |
tree | 065fa8ae66ce3e5e438677e96d8b1227042a3bce | |
parent | bb393e2d11fde1307e92789669ca7230457d86cd (diff) |
marginally better names
-rw-r--r-- | crates/ra_vfs/src/lib.rs | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs index 7e45f0a73..7f555a3c0 100644 --- a/crates/ra_vfs/src/lib.rs +++ b/crates/ra_vfs/src/lib.rs | |||
@@ -112,7 +112,7 @@ impl Vfs { | |||
112 | } else { | 112 | } else { |
113 | let text = fs::read_to_string(path).unwrap_or_default(); | 113 | let text = fs::read_to_string(path).unwrap_or_default(); |
114 | let text = Arc::new(text); | 114 | let text = Arc::new(text); |
115 | let file = self.add_file(root, rel_path.clone(), Arc::clone(&text), false); | 115 | let file = self.raw_add_file(root, rel_path.clone(), Arc::clone(&text), false); |
116 | let change = VfsChange::AddFile { file, text, root, path: rel_path }; | 116 | let change = VfsChange::AddFile { file, text, root, path: rel_path }; |
117 | self.pending_changes.push(change); | 117 | self.pending_changes.push(change); |
118 | Some(file) | 118 | Some(file) |
@@ -124,17 +124,17 @@ impl Vfs { | |||
124 | pub fn add_file_overlay(&mut self, path: &Path, text: String) -> Option<VfsFile> { | 124 | pub fn add_file_overlay(&mut self, path: &Path, text: String) -> Option<VfsFile> { |
125 | let (root, rel_path, file) = self.find_root(path)?; | 125 | let (root, rel_path, file) = self.find_root(path)?; |
126 | if let Some(file) = file { | 126 | if let Some(file) = file { |
127 | self.do_change_file(file, text, true); | 127 | self.change_file_event(file, text, true); |
128 | Some(file) | 128 | Some(file) |
129 | } else { | 129 | } else { |
130 | self.do_add_file(root, rel_path, text, true) | 130 | self.add_file_event(root, rel_path, text, true) |
131 | } | 131 | } |
132 | } | 132 | } |
133 | 133 | ||
134 | pub fn change_file_overlay(&mut self, path: &Path, new_text: String) { | 134 | pub fn change_file_overlay(&mut self, path: &Path, new_text: String) { |
135 | if let Some((_root, _path, file)) = self.find_root(path) { | 135 | if let Some((_root, _path, file)) = self.find_root(path) { |
136 | let file = file.expect("can't change a file which wasn't added"); | 136 | let file = file.expect("can't change a file which wasn't added"); |
137 | self.do_change_file(file, new_text, true); | 137 | self.change_file_event(file, new_text, true); |
138 | } | 138 | } |
139 | } | 139 | } |
140 | 140 | ||
@@ -143,9 +143,9 @@ impl Vfs { | |||
143 | let file = file.expect("can't remove a file which wasn't added"); | 143 | let file = file.expect("can't remove a file which wasn't added"); |
144 | let full_path = rel_path.to_path(&self.roots.path(root)); | 144 | let full_path = rel_path.to_path(&self.roots.path(root)); |
145 | if let Ok(text) = fs::read_to_string(&full_path) { | 145 | if let Ok(text) = fs::read_to_string(&full_path) { |
146 | self.do_change_file(file, text, false); | 146 | self.change_file_event(file, text, false); |
147 | } else { | 147 | } else { |
148 | self.do_remove_file(root, rel_path, file); | 148 | self.remove_file_event(root, rel_path, file); |
149 | } | 149 | } |
150 | Some(file) | 150 | Some(file) |
151 | } | 151 | } |
@@ -175,7 +175,7 @@ impl Vfs { | |||
175 | continue; | 175 | continue; |
176 | } | 176 | } |
177 | let text = Arc::new(text); | 177 | let text = Arc::new(text); |
178 | let file = self.add_file(root, path.clone(), Arc::clone(&text), false); | 178 | let file = self.raw_add_file(root, path.clone(), Arc::clone(&text), false); |
179 | cur_files.push((file, path, text)); | 179 | cur_files.push((file, path, text)); |
180 | } | 180 | } |
181 | 181 | ||
@@ -189,13 +189,13 @@ impl Vfs { | |||
189 | } | 189 | } |
190 | match (existing_file, text) { | 190 | match (existing_file, text) { |
191 | (Some(file), None) => { | 191 | (Some(file), None) => { |
192 | self.do_remove_file(root, path, file); | 192 | self.remove_file_event(root, path, file); |
193 | } | 193 | } |
194 | (None, Some(text)) => { | 194 | (None, Some(text)) => { |
195 | self.do_add_file(root, path, text, false); | 195 | self.add_file_event(root, path, text, false); |
196 | } | 196 | } |
197 | (Some(file), Some(text)) => { | 197 | (Some(file), Some(text)) => { |
198 | self.do_change_file(file, text, false); | 198 | self.change_file_event(file, text, false); |
199 | } | 199 | } |
200 | (None, None) => (), | 200 | (None, None) => (), |
201 | } | 201 | } |
@@ -203,7 +203,10 @@ impl Vfs { | |||
203 | } | 203 | } |
204 | } | 204 | } |
205 | 205 | ||
206 | fn do_add_file( | 206 | // *_event calls change the state of VFS and push a change onto pending |
207 | // changes array. | ||
208 | |||
209 | fn add_file_event( | ||
207 | &mut self, | 210 | &mut self, |
208 | root: VfsRoot, | 211 | root: VfsRoot, |
209 | path: RelativePathBuf, | 212 | path: RelativePathBuf, |
@@ -211,23 +214,25 @@ impl Vfs { | |||
211 | is_overlay: bool, | 214 | is_overlay: bool, |
212 | ) -> Option<VfsFile> { | 215 | ) -> Option<VfsFile> { |
213 | let text = Arc::new(text); | 216 | let text = Arc::new(text); |
214 | let file = self.add_file(root, path.clone(), text.clone(), is_overlay); | 217 | let file = self.raw_add_file(root, path.clone(), text.clone(), is_overlay); |
215 | self.pending_changes.push(VfsChange::AddFile { file, root, path, text }); | 218 | self.pending_changes.push(VfsChange::AddFile { file, root, path, text }); |
216 | Some(file) | 219 | Some(file) |
217 | } | 220 | } |
218 | 221 | ||
219 | fn do_change_file(&mut self, file: VfsFile, text: String, is_overlay: bool) { | 222 | fn change_file_event(&mut self, file: VfsFile, text: String, is_overlay: bool) { |
220 | let text = Arc::new(text); | 223 | let text = Arc::new(text); |
221 | self.change_file(file, text.clone(), is_overlay); | 224 | self.raw_change_file(file, text.clone(), is_overlay); |
222 | self.pending_changes.push(VfsChange::ChangeFile { file, text }); | 225 | self.pending_changes.push(VfsChange::ChangeFile { file, text }); |
223 | } | 226 | } |
224 | 227 | ||
225 | fn do_remove_file(&mut self, root: VfsRoot, path: RelativePathBuf, file: VfsFile) { | 228 | fn remove_file_event(&mut self, root: VfsRoot, path: RelativePathBuf, file: VfsFile) { |
226 | self.remove_file(file); | 229 | self.raw_remove_file(file); |
227 | self.pending_changes.push(VfsChange::RemoveFile { root, path, file }); | 230 | self.pending_changes.push(VfsChange::RemoveFile { root, path, file }); |
228 | } | 231 | } |
229 | 232 | ||
230 | fn add_file( | 233 | // raw_* calls change the state of VFS, but **do not** emit events. |
234 | |||
235 | fn raw_add_file( | ||
231 | &mut self, | 236 | &mut self, |
232 | root: VfsRoot, | 237 | root: VfsRoot, |
233 | path: RelativePathBuf, | 238 | path: RelativePathBuf, |
@@ -240,13 +245,13 @@ impl Vfs { | |||
240 | file | 245 | file |
241 | } | 246 | } |
242 | 247 | ||
243 | fn change_file(&mut self, file: VfsFile, new_text: Arc<String>, is_overlayed: bool) { | 248 | fn raw_change_file(&mut self, file: VfsFile, new_text: Arc<String>, is_overlayed: bool) { |
244 | let mut file_data = &mut self.files[file]; | 249 | let mut file_data = &mut self.files[file]; |
245 | file_data.text = new_text; | 250 | file_data.text = new_text; |
246 | file_data.is_overlayed = is_overlayed; | 251 | file_data.is_overlayed = is_overlayed; |
247 | } | 252 | } |
248 | 253 | ||
249 | fn remove_file(&mut self, file: VfsFile) { | 254 | fn raw_remove_file(&mut self, file: VfsFile) { |
250 | // FIXME: use arena with removal | 255 | // FIXME: use arena with removal |
251 | self.files[file].text = Default::default(); | 256 | self.files[file].text = Default::default(); |
252 | self.files[file].path = Default::default(); | 257 | self.files[file].path = Default::default(); |