Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Always preserve worktree order rather than sorting lexicographically (#54716)

Max Brunsfeld41cf3a8950f6
diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs
index ab66da494de..ea400e28e86 100644
--- a/crates/project/src/project.rs
+++ b/crates/project/src/project.rs
@@ -2361,13 +2361,6 @@ impl Project {
self.collaborators.values().find(|c| c.is_host)
}
- #[inline]
- pub fn set_worktrees_reordered(&mut self, worktrees_reordered: bool, cx: &mut App) {
- self.worktree_store.update(cx, |store, _| {
- store.set_worktrees_reordered(worktrees_reordered);
- });
- }
-
/// Collect all worktrees, including ones that don't appear in the project panel
#[inline]
pub fn worktrees<'a>(
diff --git a/crates/project/src/worktree_store.rs b/crates/project/src/worktree_store.rs
index 768ab9afb91..8eaf3f40c0a 100644
--- a/crates/project/src/worktree_store.rs
+++ b/crates/project/src/worktree_store.rs
@@ -188,7 +188,6 @@ pub struct WorktreeStore {
downstream_client: Option<(AnyProtoClient, u64)>,
retain_worktrees: bool,
worktrees: Vec<WorktreeHandle>,
- worktrees_reordered: bool,
scanning_enabled: bool,
#[allow(clippy::type_complexity)]
loading_worktrees:
@@ -236,7 +235,6 @@ impl WorktreeStore {
loading_worktrees: Default::default(),
downstream_client: None,
worktrees: Vec::new(),
- worktrees_reordered: false,
scanning_enabled: true,
retain_worktrees,
initial_scan_complete: watch::channel_with(true),
@@ -257,7 +255,6 @@ impl WorktreeStore {
loading_worktrees: Default::default(),
downstream_client: None,
worktrees: Vec::new(),
- worktrees_reordered: false,
scanning_enabled: true,
retain_worktrees,
initial_scan_complete: watch::channel_with(true),
@@ -891,18 +888,7 @@ impl WorktreeStore {
} else {
WorktreeHandle::Weak(worktree.downgrade())
};
- if self.worktrees_reordered {
- self.worktrees.push(handle);
- } else {
- let i = match self
- .worktrees
- .binary_search_by_key(&Some(worktree.read(cx).abs_path()), |other| {
- other.upgrade().map(|worktree| worktree.read(cx).abs_path())
- }) {
- Ok(i) | Err(i) => i,
- };
- self.worktrees.insert(i, handle);
- }
+ self.worktrees.push(handle);
cx.emit(WorktreeStoreEvent::WorktreeAdded(worktree.clone()));
self.send_project_updates(cx);
@@ -987,10 +973,6 @@ impl WorktreeStore {
})
}
- pub fn set_worktrees_reordered(&mut self, worktrees_reordered: bool) {
- self.worktrees_reordered = worktrees_reordered;
- }
-
fn upstream_client(&self) -> Option<(AnyProtoClient, u64)> {
match &self.state {
WorktreeStoreState::Remote {
@@ -1090,7 +1072,6 @@ impl WorktreeStore {
let worktree_to_move = self.worktrees.remove(source_index);
self.worktrees.insert(destination_index, worktree_to_move);
- self.worktrees_reordered = true;
cx.emit(WorktreeStoreEvent::WorktreeOrderChanged);
cx.notify();
Ok(())
diff --git a/crates/project/tests/integration/project_tests.rs b/crates/project/tests/integration/project_tests.rs
index 05e29d00177..65fa5d72d80 100644
--- a/crates/project/tests/integration/project_tests.rs
+++ b/crates/project/tests/integration/project_tests.rs
@@ -4572,8 +4572,8 @@ async fn test_definition(cx: &mut gpui::TestAppContext) {
assert_eq!(
list_worktrees(&project, cx),
[
+ (path!("/dir/b.rs").as_ref(), true),
(path!("/dir/a.rs").as_ref(), false),
- (path!("/dir/b.rs").as_ref(), true)
],
);
diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs
index 22a86cab0b3..c88aec84e23 100644
--- a/crates/workspace/src/workspace.rs
+++ b/crates/workspace/src/workspace.rs
@@ -1870,11 +1870,6 @@ impl Workspace {
if let Some(paths) = serialized_workspace.as_ref().map(|ws| &ws.paths) {
paths_to_open = paths.ordered_paths().cloned().collect();
- if !paths.is_lexicographically_ordered() {
- project_handle.update(cx, |project, cx| {
- project.set_worktrees_reordered(true, cx);
- });
- }
}
// Get project paths for all of the abs_paths