aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_vfs/src/lib.rs72
1 files changed, 33 insertions, 39 deletions
diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs
index 106afa9e7..1e1344456 100644
--- a/crates/ra_vfs/src/lib.rs
+++ b/crates/ra_vfs/src/lib.rs
@@ -121,6 +121,39 @@ impl Vfs {
121 None 121 None
122 } 122 }
123 123
124 pub fn add_file_overlay(&mut self, path: &Path, text: String) -> Option<VfsFile> {
125 let (root, rel_path, file) = self.find_root(path)?;
126 if let Some(file) = file {
127 self.do_change_file(file, text, true);
128 Some(file)
129 } else {
130 self.do_add_file(root, rel_path, text, true)
131 }
132 }
133
134 pub fn change_file_overlay(&mut self, path: &Path, new_text: String) {
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");
137 self.do_change_file(file, new_text, true);
138 }
139 }
140
141 pub fn remove_file_overlay(&mut self, path: &Path) -> Option<VfsFile> {
142 let (root, rel_path, file) = self.find_root(path)?;
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));
145 if let Ok(text) = fs::read_to_string(&full_path) {
146 self.do_change_file(file, text, true);
147 } else {
148 self.do_remove_file(root, rel_path, file, true);
149 }
150 Some(file)
151 }
152
153 pub fn commit_changes(&mut self) -> Vec<VfsChange> {
154 mem::replace(&mut self.pending_changes, Vec::new())
155 }
156
124 pub fn task_receiver(&self) -> &Receiver<io::TaskResult> { 157 pub fn task_receiver(&self) -> &Receiver<io::TaskResult> {
125 self.worker.receiver() 158 self.worker.receiver()
126 } 159 }
@@ -202,45 +235,6 @@ impl Vfs {
202 self.pending_changes.push(VfsChange::RemoveFile { root, path, file }); 235 self.pending_changes.push(VfsChange::RemoveFile { root, path, file });
203 } 236 }
204 237
205 pub fn add_file_overlay(&mut self, path: &Path, text: String) -> Option<VfsFile> {
206 if let Some((root, rel_path, file)) = self.find_root(path) {
207 if let Some(file) = file {
208 self.do_change_file(file, text, true);
209 Some(file)
210 } else {
211 self.do_add_file(root, rel_path, text, true)
212 }
213 } else {
214 None
215 }
216 }
217
218 pub fn change_file_overlay(&mut self, path: &Path, new_text: String) {
219 if let Some((_root, _path, file)) = self.find_root(path) {
220 let file = file.expect("can't change a file which wasn't added");
221 self.do_change_file(file, new_text, true);
222 }
223 }
224
225 pub fn remove_file_overlay(&mut self, path: &Path) -> Option<VfsFile> {
226 if let Some((root, path, file)) = self.find_root(path) {
227 let file = file.expect("can't remove a file which wasn't added");
228 let full_path = path.to_path(&self.roots.path(root));
229 if let Ok(text) = fs::read_to_string(&full_path) {
230 self.do_change_file(file, text, true);
231 } else {
232 self.do_remove_file(root, path, file, true);
233 }
234 Some(file)
235 } else {
236 None
237 }
238 }
239
240 pub fn commit_changes(&mut self) -> Vec<VfsChange> {
241 mem::replace(&mut self.pending_changes, Vec::new())
242 }
243
244 fn add_file( 238 fn add_file(
245 &mut self, 239 &mut self,
246 root: VfsRoot, 240 root: VfsRoot,