From ee6469d60e4ae1de2e84239db836c767d34958ef Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 15 Dec 2025 22:13:25 +0100 Subject: [PATCH] project: Clear worktree settings when worktrees get removed (#44913) Release Notes: - N/A *or* Added/Fixed/Improved ... --- crates/project/src/project_settings.rs | 21 ++++++++++++++------- crates/settings/src/settings_store.rs | 11 +++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/crates/project/src/project_settings.rs b/crates/project/src/project_settings.rs index b7dadc52f74f4800741f5cf537ac9f52c09643e3..8494eac5b33e7e1f231f9c62010c49aec345229f 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, ) { - 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::(|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.rs index 72e2d3ef099659c5ad27e7f1aaafaee24354d4a9..abd45a141647f6ba13708c549188a22988c78069 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, &dyn Any)>; fn set_global_value(&mut self, value: Box); fn set_local_value(&mut self, root_id: WorktreeId, path: Arc, value: Box); + 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 AnySettingValue for SettingValue { 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)]