From 1b946ef8a61fa520459435d4e1cd674e0c550771 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 19 Dec 2018 15:56:51 +0300 Subject: File can be opened before the root is scanned --- crates/ra_vfs/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'crates/ra_vfs/src/lib.rs') diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs index 3a68039f0..4de07b093 100644 --- a/crates/ra_vfs/src/lib.rs +++ b/crates/ra_vfs/src/lib.rs @@ -207,11 +207,23 @@ impl Vfs { pub fn handle_task(&mut self, task: io::TaskResult) { let mut files = Vec::new(); + // While we were scanning the root in the backgound, a file might have + // been open in the editor, so we need to account for that. + let exising = self.root2files[&task.root] + .iter() + .map(|&file| (self.files[file].path.clone(), file)) + .collect::>(); for (path, text) in task.files { + if let Some(&file) = exising.get(&path) { + let text = Arc::clone(&self.files[file].text); + files.push((file, path, text)); + continue; + } let text = Arc::new(text); let file = self.add_file(task.root, path.clone(), Arc::clone(&text)); files.push((file, path, text)); } + let change = VfsChange::AddRoot { root: task.root, files, -- cgit v1.2.3