Use active worktree's task sources (#25784)

Follow-up of https://github.com/zed-industries/zed/pull/25605

Previous PR made global tasks with `ZED_WORKTREE_ROOT` available for
"nothing open" scenario, this PR also gets all related worktree task
templates, using the centralized `TextContexts`' active worktree
detection.

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov 2025-02-28 00:57:59 +02:00 committed by GitHub
parent 6f30d5da71
commit df7beb4217
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 125 additions and 124 deletions

View file

@ -1,6 +1,6 @@
use std::sync::Arc;
use crate::{active_item_selection_properties, TaskContexts};
use crate::TaskContexts;
use fuzzy::{StringMatch, StringMatchCandidate};
use gpui::{
rems, Action, AnyElement, App, AppContext as _, Context, DismissEvent, Entity, EventEmitter,
@ -209,13 +209,6 @@ impl PickerDelegate for TasksModalDelegate {
match &mut picker.delegate.candidates {
Some(candidates) => string_match_candidates(candidates.iter()),
None => {
let Ok((worktree, location)) =
picker.delegate.workspace.update(cx, |workspace, cx| {
active_item_selection_properties(workspace, cx)
})
else {
return Vec::new();
};
let Some(task_inventory) = picker
.delegate
.task_store
@ -228,8 +221,6 @@ impl PickerDelegate for TasksModalDelegate {
let (used, current) =
task_inventory.read(cx).used_and_current_resolved_tasks(
worktree,
location,
&picker.delegate.task_contexts,
cx,
);
@ -655,8 +646,8 @@ mod tests {
);
assert_eq!(
task_names(&tasks_picker, cx),
Vec::<String>::new(),
"With no global tasks and no open item, no tasks should be listed"
vec!["another one", "example task"],
"With no global tasks and no open item, a single worktree should be used and its tasks listed"
);
drop(tasks_picker);
@ -815,8 +806,8 @@ mod tests {
let tasks_picker = open_spawn_tasks(&workspace, cx);
assert_eq!(
task_names(&tasks_picker, cx),
Vec::<String>::new(),
"Should list no file or worktree context-dependent when no file is open"
vec![concat!("opened now: ", path!("/dir")).to_string()],
"When no file is open for a single worktree, should autodetect all worktree-related tasks"
);
tasks_picker.update(cx, |_, cx| {
cx.emit(DismissEvent);