@@ -380,6 +380,8 @@ impl WorkspaceDb {
380
380
& self ,
381
381
worktree_roots : & [ P ] ,
382
382
) -> Option < SerializedWorkspace > {
383
+ // paths are sorted before db interactions to ensure that the order of the paths
384
+ // doesn't affect the workspace selection for existing workspaces
383
385
let local_paths = LocalPaths :: new ( worktree_roots) ;
384
386
385
387
// Note that we re-assign the workspace_id here in case it's empty
@@ -833,8 +835,8 @@ impl WorkspaceDb {
833
835
}
834
836
835
837
query ! {
836
- fn session_workspaces( session_id: String ) -> Result <Vec <( LocalPaths , Option <u64 >, Option <u64 >) >> {
837
- SELECT local_paths, window_id, ssh_project_id
838
+ fn session_workspaces( session_id: String ) -> Result <Vec <( LocalPaths , LocalPathsOrder , Option <u64 >, Option <u64 >) >> {
839
+ SELECT local_paths, local_paths_order , window_id, ssh_project_id
838
840
FROM workspaces
839
841
WHERE session_id = ?1 AND dev_server_project_id IS NULL
840
842
ORDER BY timestamp DESC
@@ -971,7 +973,7 @@ impl WorkspaceDb {
971
973
) -> Result < Vec < SerializedWorkspaceLocation > > {
972
974
let mut workspaces = Vec :: new ( ) ;
973
975
974
- for ( location, window_id, ssh_project_id) in
976
+ for ( location, order , window_id, ssh_project_id) in
975
977
self . session_workspaces ( last_session_id. to_owned ( ) ) ?
976
978
{
977
979
if let Some ( ssh_project_id) = ssh_project_id {
@@ -980,8 +982,7 @@ impl WorkspaceDb {
980
982
} else if location. paths ( ) . iter ( ) . all ( |path| path. exists ( ) )
981
983
&& location. paths ( ) . iter ( ) . any ( |path| path. is_dir ( ) )
982
984
{
983
- let location =
984
- SerializedWorkspaceLocation :: from_local_paths ( location. paths ( ) . iter ( ) ) ;
985
+ let location = SerializedWorkspaceLocation :: Local ( location, order) ;
985
986
workspaces. push ( ( location, window_id. map ( WindowId :: from) ) ) ;
986
987
}
987
988
}
@@ -1603,27 +1604,56 @@ mod tests {
1603
1604
window_id : Some ( 50 ) ,
1604
1605
} ;
1605
1606
1607
+ let workspace_6 = SerializedWorkspace {
1608
+ id : WorkspaceId ( 6 ) ,
1609
+ location : SerializedWorkspaceLocation :: Local (
1610
+ LocalPaths :: new ( [ "/tmp6a" , "/tmp6b" , "/tmp6c" ] ) ,
1611
+ LocalPathsOrder :: new ( [ 2 , 1 , 0 ] ) ,
1612
+ ) ,
1613
+ center_group : Default :: default ( ) ,
1614
+ window_bounds : Default :: default ( ) ,
1615
+ display : Default :: default ( ) ,
1616
+ docks : Default :: default ( ) ,
1617
+ centered_layout : false ,
1618
+ session_id : Some ( "session-id-3" . to_owned ( ) ) ,
1619
+ window_id : Some ( 60 ) ,
1620
+ } ;
1621
+
1606
1622
db. save_workspace ( workspace_1. clone ( ) ) . await ;
1607
1623
db. save_workspace ( workspace_2. clone ( ) ) . await ;
1608
1624
db. save_workspace ( workspace_3. clone ( ) ) . await ;
1609
1625
db. save_workspace ( workspace_4. clone ( ) ) . await ;
1610
1626
db. save_workspace ( workspace_5. clone ( ) ) . await ;
1627
+ db. save_workspace ( workspace_6. clone ( ) ) . await ;
1611
1628
1612
1629
let locations = db. session_workspaces ( "session-id-1" . to_owned ( ) ) . unwrap ( ) ;
1613
1630
assert_eq ! ( locations. len( ) , 2 ) ;
1614
1631
assert_eq ! ( locations[ 0 ] . 0 , LocalPaths :: new( [ "/tmp1" ] ) ) ;
1615
- assert_eq ! ( locations[ 0 ] . 1 , Some ( 10 ) ) ;
1632
+ assert_eq ! ( locations[ 0 ] . 1 , LocalPathsOrder :: new( [ 0 ] ) ) ;
1633
+ assert_eq ! ( locations[ 0 ] . 2 , Some ( 10 ) ) ;
1616
1634
assert_eq ! ( locations[ 1 ] . 0 , LocalPaths :: new( [ "/tmp2" ] ) ) ;
1617
- assert_eq ! ( locations[ 1 ] . 1 , Some ( 20 ) ) ;
1635
+ assert_eq ! ( locations[ 1 ] . 1 , LocalPathsOrder :: new( [ 0 ] ) ) ;
1636
+ assert_eq ! ( locations[ 1 ] . 2 , Some ( 20 ) ) ;
1618
1637
1619
1638
let locations = db. session_workspaces ( "session-id-2" . to_owned ( ) ) . unwrap ( ) ;
1620
1639
assert_eq ! ( locations. len( ) , 2 ) ;
1621
1640
assert_eq ! ( locations[ 0 ] . 0 , LocalPaths :: new( [ "/tmp3" ] ) ) ;
1622
- assert_eq ! ( locations[ 0 ] . 1 , Some ( 30 ) ) ;
1641
+ assert_eq ! ( locations[ 0 ] . 1 , LocalPathsOrder :: new( [ 0 ] ) ) ;
1642
+ assert_eq ! ( locations[ 0 ] . 2 , Some ( 30 ) ) ;
1623
1643
let empty_paths: Vec < & str > = Vec :: new ( ) ;
1624
1644
assert_eq ! ( locations[ 1 ] . 0 , LocalPaths :: new( empty_paths. iter( ) ) ) ;
1625
- assert_eq ! ( locations[ 1 ] . 1 , Some ( 50 ) ) ;
1626
- assert_eq ! ( locations[ 1 ] . 2 , Some ( ssh_project. id. 0 ) ) ;
1645
+ assert_eq ! ( locations[ 1 ] . 1 , LocalPathsOrder :: new( [ ] ) ) ;
1646
+ assert_eq ! ( locations[ 1 ] . 2 , Some ( 50 ) ) ;
1647
+ assert_eq ! ( locations[ 1 ] . 3 , Some ( ssh_project. id. 0 ) ) ;
1648
+
1649
+ let locations = db. session_workspaces ( "session-id-3" . to_owned ( ) ) . unwrap ( ) ;
1650
+ assert_eq ! ( locations. len( ) , 1 ) ;
1651
+ assert_eq ! (
1652
+ locations[ 0 ] . 0 ,
1653
+ LocalPaths :: new( [ "/tmp6a" , "/tmp6b" , "/tmp6c" ] ) ,
1654
+ ) ;
1655
+ assert_eq ! ( locations[ 0 ] . 1 , LocalPathsOrder :: new( [ 2 , 1 , 0 ] ) ) ;
1656
+ assert_eq ! ( locations[ 0 ] . 2 , Some ( 60 ) ) ;
1627
1657
}
1628
1658
1629
1659
fn default_workspace < P : AsRef < Path > > (
@@ -1654,15 +1684,30 @@ mod tests {
1654
1684
WorkspaceDb ( open_test_db ( "test_serializing_workspaces_last_session_workspaces" ) . await ) ;
1655
1685
1656
1686
let workspaces = [
1657
- ( 1 , dir1. path ( ) . to_str ( ) . unwrap ( ) , 9 ) ,
1658
- ( 2 , dir2. path ( ) . to_str ( ) . unwrap ( ) , 5 ) ,
1659
- ( 3 , dir3. path ( ) . to_str ( ) . unwrap ( ) , 8 ) ,
1660
- ( 4 , dir4. path ( ) . to_str ( ) . unwrap ( ) , 2 ) ,
1687
+ ( 1 , vec ! [ dir1. path( ) ] , vec ! [ 0 ] , 9 ) ,
1688
+ ( 2 , vec ! [ dir2. path( ) ] , vec ! [ 0 ] , 5 ) ,
1689
+ ( 3 , vec ! [ dir3. path( ) ] , vec ! [ 0 ] , 8 ) ,
1690
+ ( 4 , vec ! [ dir4. path( ) ] , vec ! [ 0 ] , 2 ) ,
1691
+ (
1692
+ 5 ,
1693
+ vec ! [ dir1. path( ) , dir2. path( ) , dir3. path( ) ] ,
1694
+ vec ! [ 0 , 1 , 2 ] ,
1695
+ 3 ,
1696
+ ) ,
1697
+ (
1698
+ 6 ,
1699
+ vec ! [ dir2. path( ) , dir3. path( ) , dir4. path( ) ] ,
1700
+ vec ! [ 2 , 1 , 0 ] ,
1701
+ 4 ,
1702
+ ) ,
1661
1703
]
1662
1704
. into_iter ( )
1663
- . map ( |( id, location , window_id) | SerializedWorkspace {
1705
+ . map ( |( id, locations , order , window_id) | SerializedWorkspace {
1664
1706
id : WorkspaceId ( id) ,
1665
- location : SerializedWorkspaceLocation :: from_local_paths ( [ location] ) ,
1707
+ location : SerializedWorkspaceLocation :: Local (
1708
+ LocalPaths :: new ( locations) ,
1709
+ LocalPathsOrder :: new ( order) ,
1710
+ ) ,
1666
1711
center_group : Default :: default ( ) ,
1667
1712
window_bounds : Default :: default ( ) ,
1668
1713
display : Default :: default ( ) ,
@@ -1681,28 +1726,44 @@ mod tests {
1681
1726
WindowId :: from ( 2 ) , // Top
1682
1727
WindowId :: from ( 8 ) ,
1683
1728
WindowId :: from ( 5 ) ,
1684
- WindowId :: from ( 9 ) , // Bottom
1729
+ WindowId :: from ( 9 ) ,
1730
+ WindowId :: from ( 3 ) ,
1731
+ WindowId :: from ( 4 ) , // Bottom
1685
1732
] ) ) ;
1686
1733
1687
1734
let have = db
1688
1735
. last_session_workspace_locations ( "one-session" , stack)
1689
1736
. unwrap ( ) ;
1690
- assert_eq ! ( have. len( ) , 4 ) ;
1737
+ assert_eq ! ( have. len( ) , 6 ) ;
1691
1738
assert_eq ! (
1692
1739
have[ 0 ] ,
1693
- SerializedWorkspaceLocation :: from_local_paths( & [ dir4. path( ) . to_str ( ) . unwrap ( ) ] )
1740
+ SerializedWorkspaceLocation :: from_local_paths( & [ dir4. path( ) ] )
1694
1741
) ;
1695
1742
assert_eq ! (
1696
1743
have[ 1 ] ,
1697
- SerializedWorkspaceLocation :: from_local_paths( [ dir3. path( ) . to_str ( ) . unwrap ( ) ] )
1744
+ SerializedWorkspaceLocation :: from_local_paths( [ dir3. path( ) ] )
1698
1745
) ;
1699
1746
assert_eq ! (
1700
1747
have[ 2 ] ,
1701
- SerializedWorkspaceLocation :: from_local_paths( [ dir2. path( ) . to_str ( ) . unwrap ( ) ] )
1748
+ SerializedWorkspaceLocation :: from_local_paths( [ dir2. path( ) ] )
1702
1749
) ;
1703
1750
assert_eq ! (
1704
1751
have[ 3 ] ,
1705
- SerializedWorkspaceLocation :: from_local_paths( [ dir1. path( ) . to_str( ) . unwrap( ) ] )
1752
+ SerializedWorkspaceLocation :: from_local_paths( [ dir1. path( ) ] )
1753
+ ) ;
1754
+ assert_eq ! (
1755
+ have[ 4 ] ,
1756
+ SerializedWorkspaceLocation :: Local (
1757
+ LocalPaths :: new( [ dir1. path( ) , dir2. path( ) , dir3. path( ) ] ) ,
1758
+ LocalPathsOrder :: new( [ 0 , 1 , 2 ] ) ,
1759
+ ) ,
1760
+ ) ;
1761
+ assert_eq ! (
1762
+ have[ 5 ] ,
1763
+ SerializedWorkspaceLocation :: Local (
1764
+ LocalPaths :: new( [ dir2. path( ) , dir3. path( ) , dir4. path( ) ] ) ,
1765
+ LocalPathsOrder :: new( [ 2 , 1 , 0 ] ) ,
1766
+ ) ,
1706
1767
) ;
1707
1768
}
1708
1769
0 commit comments