project_panel: Fix worktree root rename (#24487)
Closes #7923 This PR fixes root worktree renaming by: 1. Handling the case where `new_path` is the new root name instead of a relative path from the root. 2. [#20313](https://github.com/zed-industries/zed/pull/20313) added functionality to watch for root worktree renames made externally, e.g., via Finder. This PR avoids relying on that watcher because, when renaming explicitly from Zed, we can eagerly perform the necessary work (of course after fs rename) instead of waiting for the watcher to detect the rename. This prevents UI glitches during renaming root. Todo: - [x] Fix wrong abs paths when root is renamed - [x] Fix explicit scan entry func to handle renamed root dir - [x] Tests - [x] Test on Linux - [x] Tested with single and multipe worktrees - [x] Tested when single file is root file Release Notes: - Fixed an issue where worktree root name couldn't be renamed in project panel.
This commit is contained in:
parent
4207b194e3
commit
f1693e6129
3 changed files with 143 additions and 17 deletions
|
@ -1535,6 +1535,10 @@ impl Project {
|
|||
})
|
||||
}
|
||||
|
||||
/// Renames the project entry with given `entry_id`.
|
||||
///
|
||||
/// `new_path` is a relative path to worktree root.
|
||||
/// If root entry is renamed then its new root name is used instead.
|
||||
pub fn rename_entry(
|
||||
&mut self,
|
||||
entry_id: ProjectEntryId,
|
||||
|
@ -1551,12 +1555,18 @@ impl Project {
|
|||
};
|
||||
|
||||
let worktree_id = worktree.read(cx).id();
|
||||
let is_root_entry = self.entry_is_worktree_root(entry_id, cx);
|
||||
|
||||
let lsp_store = self.lsp_store().downgrade();
|
||||
cx.spawn(|_, mut cx| async move {
|
||||
let (old_abs_path, new_abs_path) = {
|
||||
let root_path = worktree.update(&mut cx, |this, _| this.abs_path())?;
|
||||
(root_path.join(&old_path), root_path.join(&new_path))
|
||||
let new_abs_path = if is_root_entry {
|
||||
root_path.parent().unwrap().join(&new_path)
|
||||
} else {
|
||||
root_path.join(&new_path)
|
||||
};
|
||||
(root_path.join(&old_path), new_abs_path)
|
||||
};
|
||||
LspStore::will_rename_entry(
|
||||
lsp_store.clone(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue