aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-10 21:29:40 +0100
committerAleksey Kladov <[email protected]>2020-07-10 21:30:24 +0100
commita1ef6cc553bbd141d94144ccb8e1599fa3f76526 (patch)
tree6177263fca1ddd26e001626313922ff6fbda6753
parent676d2e040dfe619d666d5b3068db47346655f23b (diff)
Optimize VFS processing
-rw-r--r--crates/rust-analyzer/src/main_loop.rs68
-rw-r--r--crates/vfs/src/lib.rs2
2 files changed, 40 insertions, 30 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index cea03fb6b..702f25a19 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -198,39 +198,49 @@ impl GlobalState {
198 } 198 }
199 self.analysis_host.maybe_collect_garbage(); 199 self.analysis_host.maybe_collect_garbage();
200 } 200 }
201 Event::Vfs(task) => match task { 201 Event::Vfs(mut task) => {
202 vfs::loader::Message::Loaded { files } => { 202 let _p = profile("GlobalState::handle_event/vfs");
203 let vfs = &mut self.vfs.write().0; 203 loop {
204 for (path, contents) in files { 204 match task {
205 let path = VfsPath::from(path); 205 vfs::loader::Message::Loaded { files } => {
206 if !self.mem_docs.contains(&path) { 206 let vfs = &mut self.vfs.write().0;
207 vfs.set_file_contents(path, contents) 207 for (path, contents) in files {
208 let path = VfsPath::from(path);
209 if !self.mem_docs.contains(&path) {
210 vfs.set_file_contents(path, contents)
211 }
212 }
213 }
214 vfs::loader::Message::Progress { n_total, n_done } => {
215 if n_total == 0 {
216 self.transition(Status::Invalid);
217 } else {
218 let state = if n_done == 0 {
219 self.transition(Status::Loading);
220 Progress::Begin
221 } else if n_done < n_total {
222 Progress::Report
223 } else {
224 assert_eq!(n_done, n_total);
225 self.transition(Status::Ready);
226 Progress::End
227 };
228 self.report_progress(
229 "roots scanned",
230 state,
231 Some(format!("{}/{}", n_done, n_total)),
232 Some(Progress::percentage(n_done, n_total)),
233 )
234 }
208 } 235 }
209 } 236 }
210 } 237 // Coalesce many VFS event into a single loop turn
211 vfs::loader::Message::Progress { n_total, n_done } => { 238 task = match self.loader.receiver.try_recv() {
212 if n_total == 0 { 239 Ok(task) => task,
213 self.transition(Status::Invalid); 240 Err(_) => break,
214 } else {
215 let state = if n_done == 0 {
216 self.transition(Status::Loading);
217 Progress::Begin
218 } else if n_done < n_total {
219 Progress::Report
220 } else {
221 assert_eq!(n_done, n_total);
222 self.transition(Status::Ready);
223 Progress::End
224 };
225 self.report_progress(
226 "roots scanned",
227 state,
228 Some(format!("{}/{}", n_done, n_total)),
229 Some(Progress::percentage(n_done, n_total)),
230 )
231 } 241 }
232 } 242 }
233 }, 243 }
234 Event::Flycheck(task) => match task { 244 Event::Flycheck(task) => match task {
235 flycheck::Message::AddDiagnostic { workspace_root, diagnostic } => { 245 flycheck::Message::AddDiagnostic { workspace_root, diagnostic } => {
236 let diagnostics = crate::diagnostics::to_proto::map_rust_diagnostic_to_lsp( 246 let diagnostics = crate::diagnostics::to_proto::map_rust_diagnostic_to_lsp(
diff --git a/crates/vfs/src/lib.rs b/crates/vfs/src/lib.rs
index 569da8a1c..3bfecd08f 100644
--- a/crates/vfs/src/lib.rs
+++ b/crates/vfs/src/lib.rs
@@ -70,7 +70,7 @@ impl ChangedFile {
70 } 70 }
71} 71}
72 72
73#[derive(Eq, PartialEq, Copy, Clone)] 73#[derive(Eq, PartialEq, Copy, Clone, Debug)]
74pub enum ChangeKind { 74pub enum ChangeKind {
75 Create, 75 Create,
76 Modify, 76 Modify,