workspace: Fix inconsistent paths order serialization (#19232)

Release Notes:

- Fixed inconsistent serialization of workspace paths order
This commit is contained in:
Elliot Thomas 2024-10-17 16:38:28 +01:00 committed by GitHub
parent e9e4c770ca
commit 398d0396b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 107 additions and 33 deletions

View file

@ -1103,20 +1103,28 @@ impl Workspace {
let mut paths_to_open = abs_paths;
let paths_order = serialized_workspace
let workspace_location = serialized_workspace
.as_ref()
.map(|ws| &ws.location)
.and_then(|loc| match loc {
SerializedWorkspaceLocation::Local(_, order) => Some(order.order()),
SerializedWorkspaceLocation::Local(paths, order) => {
Some((paths.paths(), order.order()))
}
_ => None,
});
if let Some(paths_order) = paths_order {
paths_to_open = paths_order
if let Some((paths, order)) = workspace_location {
// todo: should probably move this logic to a method on the SerializedWorkspaceLocation
// it's only valid for Local and would be more clear there and be able to be tested
// and reused elsewhere
paths_to_open = order
.iter()
.filter_map(|i| paths_to_open.get(*i).cloned())
.collect::<Vec<_>>();
if paths_order.iter().enumerate().any(|(i, &j)| i != j) {
.zip(paths.iter())
.sorted_by_key(|(i, _)| *i)
.map(|(_, path)| path.clone())
.collect();
if order.iter().enumerate().any(|(i, &j)| i != j) {
project_handle
.update(&mut cx, |project, cx| {
project.set_worktrees_reordered(true, cx);