Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
project: Clear worktree settings when worktrees get removed (#44913)
Lukas Wirthee6469d60e4a
diff --git a/crates/project/src/project_settings.rs b/crates/project/src/project_settings.rsindex b7dadc52f74..8494eac5b33 100644--- a/crates/project/src/project_settings.rs+++ b/crates/project/src/project_settings.rs@@ -792,13 +792,20 @@ impl SettingsObserver {event: &WorktreeStoreEvent,cx: &mut Context<Self>,) {- if let WorktreeStoreEvent::WorktreeAdded(worktree) = event {- cx.subscribe(worktree, |this, worktree, event, cx| {- if let worktree::Event::UpdatedEntries(changes) = event {- this.update_local_worktree_settings(&worktree, changes, cx)- }- })- .detach()+ match event {+ WorktreeStoreEvent::WorktreeAdded(worktree) => cx+ .subscribe(worktree, |this, worktree, event, cx| {+ if let worktree::Event::UpdatedEntries(changes) = event {+ this.update_local_worktree_settings(&worktree, changes, cx)+ }+ })+ .detach(),+ WorktreeStoreEvent::WorktreeRemoved(_, worktree_id) => {+ cx.update_global::<SettingsStore, _>(|store, cx| {+ store.clear_local_settings(*worktree_id, cx).log_err();+ });+ }+ _ => {}}}diff --git a/crates/settings/src/settings_store.rs b/crates/settings/src/settings_store.rsindex 72e2d3ef099..abd45a14164 100644--- a/crates/settings/src/settings_store.rs+++ b/crates/settings/src/settings_store.rs@@ -247,6 +247,7 @@ pub trait AnySettingValue: 'static + Send + Sync {fn all_local_values(&self) -> Vec<(WorktreeId, Arc<RelPath>, &dyn Any)>;fn set_global_value(&mut self, value: Box<dyn Any>);fn set_local_value(&mut self, root_id: WorktreeId, path: Arc<RelPath>, value: Box<dyn Any>);+ fn clear_local_values(&mut self, root_id: WorktreeId);}/// Parameters that are used when generating some JSON schemas at runtime.@@ -971,6 +972,11 @@ impl SettingsStore {pub fn clear_local_settings(&mut self, root_id: WorktreeId, cx: &mut App) -> Result<()> {self.local_settings.retain(|(worktree_id, _), _| worktree_id != &root_id);+ self.raw_editorconfig_settings+ .retain(|(worktree_id, _), _| worktree_id != &root_id);+ for setting_value in self.setting_values.values_mut() {+ setting_value.clear_local_values(root_id);+ }self.recompute_values(Some((root_id, RelPath::empty())), cx);Ok(())}@@ -1338,6 +1344,11 @@ impl<T: Settings> AnySettingValue for SettingValue<T> {Err(ix) => self.local_values.insert(ix, (root_id, path, value)),}}++ fn clear_local_values(&mut self, root_id: WorktreeId) {+ self.local_values+ .retain(|(worktree_id, _, _)| *worktree_id != root_id);+ }}#[cfg(test)]