mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-03 17:44:30 +00:00
Merge pull request #2017 from zed-industries/dont-save-single-file-workspaces
Don't save single file worktrees
This commit is contained in:
commit
a222821dfa
3 changed files with 26 additions and 19 deletions
|
@ -216,7 +216,9 @@ impl WorkspaceDb {
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
let mut delete_tasks = Vec::new();
|
let mut delete_tasks = Vec::new();
|
||||||
for (id, location) in self.recent_workspaces()? {
|
for (id, location) in self.recent_workspaces()? {
|
||||||
if location.paths().iter().all(|path| path.exists()) {
|
if location.paths().iter().all(|path| path.exists())
|
||||||
|
&& location.paths().iter().any(|path| path.is_dir())
|
||||||
|
{
|
||||||
result.push((id, location));
|
result.push((id, location));
|
||||||
} else {
|
} else {
|
||||||
delete_tasks.push(self.delete_stale_workspace(id));
|
delete_tasks.push(self.delete_stale_workspace(id));
|
||||||
|
@ -227,14 +229,13 @@ impl WorkspaceDb {
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
query! {
|
pub async fn last_workspace(&self) -> Result<Option<WorkspaceLocation>> {
|
||||||
pub fn last_workspace() -> Result<Option<WorkspaceLocation>> {
|
Ok(self
|
||||||
SELECT workspace_location
|
.recent_workspaces_on_disk()
|
||||||
FROM workspaces
|
.await?
|
||||||
WHERE workspace_location IS NOT NULL
|
.into_iter()
|
||||||
ORDER BY timestamp DESC
|
.next()
|
||||||
LIMIT 1
|
.map(|(_, location)| location))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_center_pane_group(&self, workspace_id: WorkspaceId) -> Result<SerializedPaneGroup> {
|
fn get_center_pane_group(&self, workspace_id: WorkspaceId) -> Result<SerializedPaneGroup> {
|
||||||
|
|
|
@ -2680,8 +2680,8 @@ pub fn activate_workspace_for_project(
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn last_opened_workspace_paths() -> Option<WorkspaceLocation> {
|
pub async fn last_opened_workspace_paths() -> Option<WorkspaceLocation> {
|
||||||
DB.last_workspace().log_err().flatten()
|
DB.last_workspace().await.log_err().flatten()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
|
|
|
@ -170,7 +170,8 @@ fn main() {
|
||||||
cx.platform().activate(true);
|
cx.platform().activate(true);
|
||||||
let paths = collect_path_args();
|
let paths = collect_path_args();
|
||||||
if paths.is_empty() {
|
if paths.is_empty() {
|
||||||
restore_or_create_workspace(cx);
|
cx.spawn(|cx| async move { restore_or_create_workspace(cx).await })
|
||||||
|
.detach()
|
||||||
} else {
|
} else {
|
||||||
cx.dispatch_global_action(OpenPaths { paths });
|
cx.dispatch_global_action(OpenPaths { paths });
|
||||||
}
|
}
|
||||||
|
@ -179,7 +180,8 @@ fn main() {
|
||||||
cx.spawn(|cx| handle_cli_connection(connection, app_state.clone(), cx))
|
cx.spawn(|cx| handle_cli_connection(connection, app_state.clone(), cx))
|
||||||
.detach();
|
.detach();
|
||||||
} else {
|
} else {
|
||||||
restore_or_create_workspace(cx);
|
cx.spawn(|cx| async move { restore_or_create_workspace(cx).await })
|
||||||
|
.detach()
|
||||||
}
|
}
|
||||||
cx.spawn(|cx| async move {
|
cx.spawn(|cx| async move {
|
||||||
while let Some(connection) = cli_connections_rx.next().await {
|
while let Some(connection) = cli_connections_rx.next().await {
|
||||||
|
@ -203,13 +205,17 @@ fn main() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn restore_or_create_workspace(cx: &mut gpui::MutableAppContext) {
|
async fn restore_or_create_workspace(mut cx: AsyncAppContext) {
|
||||||
if let Some(location) = workspace::last_opened_workspace_paths() {
|
if let Some(location) = workspace::last_opened_workspace_paths().await {
|
||||||
cx.dispatch_global_action(OpenPaths {
|
cx.update(|cx| {
|
||||||
paths: location.paths().as_ref().clone(),
|
cx.dispatch_global_action(OpenPaths {
|
||||||
})
|
paths: location.paths().as_ref().clone(),
|
||||||
|
})
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
cx.dispatch_global_action(NewFile);
|
cx.update(|cx| {
|
||||||
|
cx.dispatch_global_action(NewFile);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue