Make ZED_WORKTREE_ROOT always point to a directory or is not set (#23150)

When the out-of-tree file like `tasks.json` is-focus, tasks spawn with `ZED_WORKTREE_ROOT` unset.
This commit is contained in:
Andrew Borg (Kashin) 2025-01-27 15:10:39 +00:00 committed by GitHub
parent 33921362cf
commit 9f3dbd6fa3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -489,7 +489,7 @@ impl ContextProvider for BasicContextProvider {
if !selected_text.trim().is_empty() {
task_variables.insert(VariableName::SelectedText, selected_text);
}
let worktree_abs_path =
let worktree_root_dir =
buffer
.file()
.map(|file| file.worktree_id(cx))
@ -497,9 +497,9 @@ impl ContextProvider for BasicContextProvider {
self.worktree_store
.read(cx)
.worktree_for_id(worktree_id, cx)
.map(|worktree| worktree.read(cx).abs_path())
.map(|worktree| worktree.read(cx).root_dir())
});
if let Some(worktree_path) = worktree_abs_path {
if let Some(Some(worktree_path)) = worktree_root_dir {
task_variables.insert(
VariableName::WorktreeRoot,
worktree_path.to_string_lossy().to_string(),