mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 06:59:22 +01:00
sidebar: Open closed linked worktree threads from the thread switcher
The thread switcher resolved a thread of a closed linked worktree to the workspace of its project group and loaded the thread there. Keep the thread's own workspace in the switcher entry and, when that workspace is closed, open it from the thread's folders first, as a click on the thread in the sidebar does.
This commit is contained in:
@@ -5901,17 +5901,15 @@ impl Sidebar {
|
||||
if thread.draft == Some(DraftKind::Empty) {
|
||||
return None;
|
||||
}
|
||||
let workspace = match &thread.workspace {
|
||||
ThreadEntryWorkspace::Open(workspace) => Some(workspace.clone()),
|
||||
ThreadEntryWorkspace::Closed { .. } => {
|
||||
current_header_key.as_ref().and_then(|key| {
|
||||
self.multi_workspace.upgrade().and_then(|mw| {
|
||||
mw.read(cx)
|
||||
.workspace_for_paths(key.path_list(), key.host(), cx)
|
||||
})
|
||||
})
|
||||
}
|
||||
}?;
|
||||
if let ThreadEntryWorkspace::Closed { .. } = &thread.workspace {
|
||||
let key = current_header_key.as_ref()?;
|
||||
let multi_workspace = self.multi_workspace.upgrade()?;
|
||||
multi_workspace
|
||||
.read(cx)
|
||||
.workspaces_for_project_group(key, cx)
|
||||
.next()?;
|
||||
}
|
||||
let workspace = thread.workspace.clone();
|
||||
let notified = self.contents.is_thread_notified(&thread.metadata.thread_id);
|
||||
let timestamp: SharedString =
|
||||
format_history_entry_timestamp(Self::thread_display_time(&thread.metadata))
|
||||
@@ -6000,18 +5998,20 @@ impl Sidebar {
|
||||
metadata,
|
||||
workspace,
|
||||
} => {
|
||||
if let Some(multi_workspace) = self.multi_workspace.upgrade() {
|
||||
multi_workspace.update(cx, |multi_workspace, cx| {
|
||||
multi_workspace.activate(workspace.clone(), None, window, cx);
|
||||
if let ThreadEntryWorkspace::Open(workspace) = workspace {
|
||||
if let Some(multi_workspace) = self.multi_workspace.upgrade() {
|
||||
multi_workspace.update(cx, |multi_workspace, cx| {
|
||||
multi_workspace.activate(workspace.clone(), None, window, cx);
|
||||
});
|
||||
}
|
||||
self.active_entry = Some(ActiveEntry::Thread {
|
||||
thread_id: metadata.thread_id,
|
||||
session_id: metadata.session_id.clone(),
|
||||
workspace: workspace.clone(),
|
||||
});
|
||||
self.update_entries(cx);
|
||||
Self::load_agent_thread_in_workspace(workspace, metadata, false, window, cx);
|
||||
}
|
||||
self.active_entry = Some(ActiveEntry::Thread {
|
||||
thread_id: metadata.thread_id,
|
||||
session_id: metadata.session_id.clone(),
|
||||
workspace: workspace.clone(),
|
||||
});
|
||||
self.update_entries(cx);
|
||||
Self::load_agent_thread_in_workspace(workspace, metadata, false, window, cx);
|
||||
}
|
||||
ThreadSwitcherSelection::Terminal {
|
||||
metadata,
|
||||
@@ -6043,7 +6043,7 @@ impl Sidebar {
|
||||
match selection {
|
||||
ThreadSwitcherSelection::Thread {
|
||||
metadata,
|
||||
workspace,
|
||||
workspace: ThreadEntryWorkspace::Open(workspace),
|
||||
} => {
|
||||
if let Some(multi_workspace) = self.multi_workspace.upgrade() {
|
||||
multi_workspace.update(cx, |multi_workspace, cx| {
|
||||
@@ -6061,6 +6061,24 @@ impl Sidebar {
|
||||
self.dismiss_thread_switcher(cx);
|
||||
Self::load_agent_thread_in_workspace(workspace, metadata, true, window, cx);
|
||||
}
|
||||
ThreadSwitcherSelection::Thread {
|
||||
metadata,
|
||||
workspace:
|
||||
ThreadEntryWorkspace::Closed {
|
||||
folder_paths,
|
||||
project_group_key,
|
||||
},
|
||||
} => {
|
||||
self.record_thread_access(&metadata.thread_id);
|
||||
self.dismiss_thread_switcher(cx);
|
||||
self.open_workspace_and_activate_thread(
|
||||
metadata.clone(),
|
||||
folder_paths.clone(),
|
||||
project_group_key,
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
ThreadSwitcherSelection::Terminal {
|
||||
metadata,
|
||||
workspace,
|
||||
|
||||
@@ -4176,6 +4176,134 @@ async fn test_thread_switcher_preserves_closed_terminal_linked_worktree_workspac
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_thread_switcher_opens_closed_linked_worktree_thread_in_its_worktree(
|
||||
cx: &mut TestAppContext,
|
||||
) {
|
||||
init_test(cx);
|
||||
|
||||
let fs = FakeFs::new(cx.executor());
|
||||
fs.insert_tree(
|
||||
"/project",
|
||||
serde_json::json!({
|
||||
".git": {
|
||||
"worktrees": {
|
||||
"feature-a": {
|
||||
"commondir": "../../",
|
||||
"HEAD": "ref: refs/heads/feature-a",
|
||||
},
|
||||
"feature-b": {
|
||||
"commondir": "../../",
|
||||
"HEAD": "ref: refs/heads/feature-b",
|
||||
},
|
||||
},
|
||||
},
|
||||
"src": {},
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
fs.insert_tree(
|
||||
"/worktrees/project/feature-a/project",
|
||||
serde_json::json!({
|
||||
".git": "gitdir: /project/.git/worktrees/feature-a",
|
||||
"src": {},
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
fs.insert_tree(
|
||||
"/worktrees/project/feature-b/project",
|
||||
serde_json::json!({
|
||||
".git": "gitdir: /project/.git/worktrees/feature-b",
|
||||
"src": {},
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
for name in ["feature-a", "feature-b"] {
|
||||
fs.add_linked_worktree_for_repo(
|
||||
Path::new("/project/.git"),
|
||||
false,
|
||||
git::repository::Worktree {
|
||||
path: PathBuf::from(format!("/worktrees/project/{name}/project")),
|
||||
ref_name: Some(format!("refs/heads/{name}").into()),
|
||||
sha: "aaa".into(),
|
||||
is_main: false,
|
||||
is_bare: false,
|
||||
},
|
||||
)
|
||||
.await;
|
||||
}
|
||||
cx.update(|cx| <dyn fs::Fs>::set_global(fs.clone(), cx));
|
||||
let main_paths = PathList::new(&[PathBuf::from("/project")]);
|
||||
let worktree_folder_paths =
|
||||
PathList::new(&[PathBuf::from("/worktrees/project/feature-a/project")]);
|
||||
save_thread_metadata_with_main_paths(
|
||||
"feature-thread",
|
||||
"Feature Thread",
|
||||
worktree_folder_paths.clone(),
|
||||
main_paths.clone(),
|
||||
chrono::TimeZone::with_ymd_and_hms(&Utc, 2024, 1, 2, 0, 0, 0).unwrap(),
|
||||
cx,
|
||||
);
|
||||
save_thread_metadata_with_main_paths(
|
||||
"main-thread",
|
||||
"Main Thread",
|
||||
main_paths.clone(),
|
||||
main_paths,
|
||||
chrono::TimeZone::with_ymd_and_hms(&Utc, 2024, 1, 1, 0, 0, 0).unwrap(),
|
||||
cx,
|
||||
);
|
||||
|
||||
let sibling_project = project::Project::test(
|
||||
fs.clone(),
|
||||
["/worktrees/project/feature-b/project".as_ref()],
|
||||
cx,
|
||||
)
|
||||
.await;
|
||||
sibling_project
|
||||
.update(cx, |project, cx| project.git_scans_complete(cx))
|
||||
.await;
|
||||
let (multi_workspace, cx) = cx.add_window_view(|window, cx| {
|
||||
MultiWorkspace::test_new(sibling_project.clone(), window, cx)
|
||||
});
|
||||
let sidebar = setup_sidebar(&multi_workspace, cx);
|
||||
sidebar.update(cx, |sidebar, cx| sidebar.update_entries(cx));
|
||||
cx.run_until_parked();
|
||||
|
||||
focus_sidebar(&sidebar, cx);
|
||||
sidebar.update_in(cx, |sidebar, window, cx| {
|
||||
sidebar.on_toggle_thread_switcher(&ToggleThreadSwitcher::default(), window, cx);
|
||||
});
|
||||
cx.run_until_parked();
|
||||
let feature_selection = sidebar.read_with(cx, |sidebar, cx| {
|
||||
sidebar
|
||||
.thread_switcher
|
||||
.as_ref()
|
||||
.expect("switcher should be open")
|
||||
.read(cx)
|
||||
.entries()
|
||||
.iter()
|
||||
.find_map(|entry| match entry {
|
||||
ThreadSwitcherEntry::Thread(thread)
|
||||
if thread.metadata.title.as_ref().map(|title| title.as_ref())
|
||||
== Some("Feature Thread") =>
|
||||
{
|
||||
Some(entry.selection())
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.expect("the closed worktree thread should be listed")
|
||||
});
|
||||
sidebar.update_in(cx, |sidebar, window, cx| {
|
||||
sidebar.confirm_switcher_selection(&feature_selection, window, cx);
|
||||
});
|
||||
cx.run_until_parked();
|
||||
|
||||
let active_root_paths = multi_workspace.read_with(cx, |multi_workspace, cx| {
|
||||
PathList::new(&multi_workspace.workspace().read(cx).root_paths(cx))
|
||||
});
|
||||
assert_eq!(active_root_paths, worktree_folder_paths);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_archive_selected_terminal_archives_closed_linked_worktree(cx: &mut TestAppContext) {
|
||||
init_test(cx);
|
||||
|
||||
@@ -5,11 +5,11 @@ use agent_ui::{
|
||||
terminal_thread_metadata_store::TerminalThreadMetadata, thread_metadata_store::ThreadMetadata,
|
||||
};
|
||||
use gpui::{
|
||||
Action as _, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, Modifiers,
|
||||
Action as _, DismissEvent, EventEmitter, FocusHandle, Focusable, Modifiers,
|
||||
ModifiersChangedEvent, Render, ScrollHandle, SharedString, prelude::*,
|
||||
};
|
||||
use ui::{AgentThreadStatus, ThreadItem, ThreadItemWorktreeInfo, WithScrollbar, prelude::*};
|
||||
use workspace::{ModalView, Workspace};
|
||||
use workspace::ModalView;
|
||||
use zed_actions::agents_sidebar::ToggleThreadSwitcher;
|
||||
|
||||
use super::ThreadEntryWorkspace;
|
||||
@@ -21,7 +21,7 @@ pub(crate) struct ThreadSwitcherThreadEntry {
|
||||
pub icon_from_external_svg: Option<SharedString>,
|
||||
pub status: AgentThreadStatus,
|
||||
pub metadata: ThreadMetadata,
|
||||
pub workspace: Entity<Workspace>,
|
||||
pub workspace: ThreadEntryWorkspace,
|
||||
pub project_name: Option<SharedString>,
|
||||
pub worktrees: Vec<ThreadItemWorktreeInfo>,
|
||||
pub diff_stats: DiffStats,
|
||||
@@ -51,7 +51,7 @@ pub(crate) enum ThreadSwitcherEntry {
|
||||
pub(super) enum ThreadSwitcherSelection {
|
||||
Thread {
|
||||
metadata: ThreadMetadata,
|
||||
workspace: Entity<Workspace>,
|
||||
workspace: ThreadEntryWorkspace,
|
||||
},
|
||||
Terminal {
|
||||
metadata: TerminalThreadMetadata,
|
||||
|
||||
Reference in New Issue
Block a user