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.

Respect workspace order in recent projects (#12844)

Elliot Thomasf5f73efa8a60
diff --git a/crates/recent_projects/src/recent_projects.rs b/crates/recent_projects/src/recent_projects.rs
index da25b83f4d9..9655c713048 100644
--- a/crates/recent_projects/src/recent_projects.rs
+++ b/crates/recent_projects/src/recent_projects.rs
@@ -224,9 +224,10 @@ impl PickerDelegate for RecentProjectsDelegate {
.filter(|(_, (id, _))| !self.is_current_workspace(*id, cx))
.map(|(id, (_, location))| {
let combined_string = match location {
- SerializedWorkspaceLocation::Local(paths, _) => paths
- .paths()
+ SerializedWorkspaceLocation::Local(paths, order) => order
+ .order()
.iter()
+ .filter_map(|i| paths.paths().get(*i))
.map(|path| path.compact().to_string_lossy().into_owned())
.collect::<Vec<_>>()
.join(""),
@@ -285,7 +286,7 @@ impl PickerDelegate for RecentProjectsDelegate {
} else {
match candidate_workspace_location {
SerializedWorkspaceLocation::Local(paths, _) => {
- let paths = paths.paths().as_ref().clone();
+ let paths = paths.paths().to_vec();
if replace_current_window {
cx.spawn(move |workspace, mut cx| async move {
let continue_replacing = workspace
@@ -389,7 +390,13 @@ impl PickerDelegate for RecentProjectsDelegate {
let mut path_start_offset = 0;
let paths = match location {
- SerializedWorkspaceLocation::Local(paths, _) => paths.paths(),
+ SerializedWorkspaceLocation::Local(paths, order) => Arc::new(
+ order
+ .order()
+ .iter()
+ .filter_map(|i| paths.paths().get(*i).cloned())
+ .collect(),
+ ),
SerializedWorkspaceLocation::DevServer(dev_server_project) => {
Arc::new(vec![PathBuf::from(format!(
"{}:{}",
diff --git a/crates/workspace/src/persistence.rs b/crates/workspace/src/persistence.rs
index f533233ecaf..8fcadcf4f5f 100644
--- a/crates/workspace/src/persistence.rs
+++ b/crates/workspace/src/persistence.rs
@@ -667,8 +667,8 @@ impl WorkspaceDb {
}
query! {
- fn recent_workspaces() -> Result<Vec<(WorkspaceId, LocalPaths, Option<u64>)>> {
- SELECT workspace_id, local_paths, dev_server_project_id
+ fn recent_workspaces() -> Result<Vec<(WorkspaceId, LocalPaths, LocalPathsOrder, Option<u64>)>> {
+ SELECT workspace_id, local_paths, local_paths_order, dev_server_project_id
FROM workspaces
WHERE local_paths IS NOT NULL OR dev_server_project_id IS NOT NULL
ORDER BY timestamp DESC
@@ -732,7 +732,7 @@ impl WorkspaceDb {
let mut delete_tasks = Vec::new();
let dev_server_projects = self.dev_server_projects()?;
- for (id, location, dev_server_project_id) in self.recent_workspaces()? {
+ for (id, location, order, dev_server_project_id) in self.recent_workspaces()? {
if let Some(dev_server_project_id) = dev_server_project_id.map(DevServerProjectId) {
if let Some(dev_server_project) = dev_server_projects
.iter()
@@ -748,7 +748,7 @@ impl WorkspaceDb {
if location.paths().iter().all(|path| path.exists())
&& location.paths().iter().any(|path| path.is_dir())
{
- result.push((id, location.into()));
+ result.push((id, SerializedWorkspaceLocation::Local(location, order)));
} else {
delete_tasks.push(self.delete_workspace_by_id(id));
}
diff --git a/crates/workspace/src/persistence/model.rs b/crates/workspace/src/persistence/model.rs
index 2eadda6a778..339d3b3b8ec 100644
--- a/crates/workspace/src/persistence/model.rs
+++ b/crates/workspace/src/persistence/model.rs
@@ -39,8 +39,8 @@ impl LocalPaths {
Self(Arc::new(paths))
}
- pub fn paths(&self) -> Arc<Vec<PathBuf>> {
- self.0.clone()
+ pub fn paths(&self) -> &Arc<Vec<PathBuf>> {
+ &self.0
}
}