Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
acp: Fix handling of single-file worktrees (#37412)
Cole Millerae840c6ef390
diff --git a/crates/agent_ui/src/acp/thread_view.rs b/crates/agent_ui/src/acp/thread_view.rsindex 60b3166a57a..bf981d10f76 100644--- a/crates/agent_ui/src/acp/thread_view.rs+++ b/crates/agent_ui/src/acp/thread_view.rs@@ -427,11 +427,24 @@ impl AcpThreadView {"External agents are not yet supported for remote projects.".into(),));}- let root_dir = project- .read(cx)- .visible_worktrees(cx)+ let mut worktrees = project.read(cx).visible_worktrees(cx).collect::<Vec<_>>();+ // Pick the first non-single-file worktree for the root directory if there are any,+ // and otherwise the parent of a single-file worktree, falling back to $HOME if there are no visible worktrees.+ worktrees.sort_by(|l, r| {+ l.read(cx)+ .is_single_file()+ .cmp(&r.read(cx).is_single_file())+ });+ let root_dir = worktrees+ .into_iter()+ .filter_map(|worktree| {+ if worktree.read(cx).is_single_file() {+ Some(worktree.read(cx).abs_path().parent()?.into())+ } else {+ Some(worktree.read(cx).abs_path())+ }+ }).next()- .map(|worktree| worktree.read(cx).abs_path()).unwrap_or_else(|| paths::home_dir().as_path().into());let (tx, mut rx) = watch::channel("Loading…".into());let delegate = AgentServerDelegate::new(project.clone(), Some(tx));