project: Clear worktree settings when worktrees get removed (#44913)

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Lukas Wirth authored and GitHub committed 2025-12-15 22:13:25 +01:00
1 parent 9e11aaec51
commit ee6469d60e
2 files changed
+25 -7

No files matched your search

+14 -7
View File
@@ -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();
});
}
_ => {}
}
}
+11
View File
@@ -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)]