From 9bbe67f0ea643a3ef019f8eb86791faf6b287cd7 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 6 Jan 2022 15:04:06 -0800 Subject: [PATCH] Don't clobber diagnostics when getting new snapshot from background scanner Co-Authored-By: Nathan Sobo --- crates/project/src/worktree.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index c3bd5886842df7caea6fccb3db4f1d02432db450..6108e9eb108a0f170e5056702b00db78a1f0c166 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -34,6 +34,7 @@ use std::{ ffi::{OsStr, OsString}, fmt, future::Future, + mem, ops::{Deref, Range}, path::{Path, PathBuf}, sync::{ @@ -583,7 +584,9 @@ impl Worktree { match self { Self::Local(worktree) => { let is_fake_fs = worktree.fs.is_fake(); - worktree.snapshot = worktree.background_snapshot.lock().clone(); + worktree + .snapshot + .assign(worktree.background_snapshot.lock().clone()); if worktree.is_scanning() { if worktree.poll_task.is_none() { worktree.poll_task = Some(cx.spawn(|this, mut cx| async move { @@ -1842,6 +1845,14 @@ impl Snapshot { Ok(()) } + fn assign(&mut self, mut other: Self) { + mem::swap( + &mut self.diagnostic_summaries, + &mut other.diagnostic_summaries, + ); + *self = other; + } + pub fn file_count(&self) -> usize { self.entries_by_path.summary().file_count }