Improve Zed tasks' ZED_WORKTREE_ROOT
fallbacks (#25605)
Closes https://github.com/zed-industries/zed/issues/22912 Reworks the task context infrastructure so that it's possible to have multiple contexts at the same time, and stores all possible worktree context there. Task UI code is now falling back to the "active" worktree context, if active item's context did not produce a resolved task. Current code does not produce meaningful results for projects with multiple worktrees to avoid ambiguity and design changes: instead of resolving tasks per worktree context available, extra worktree context is only used when resolving tasks from the same worktree. Release Notes: - Improved Zed tasks' `ZED_WORKTREE_ROOT` fallbacks
This commit is contained in:
parent
d2b49de0e4
commit
b5a1ae6526
6 changed files with 390 additions and 164 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::active_item_selection_properties;
|
||||
use crate::{active_item_selection_properties, TaskContexts};
|
||||
use fuzzy::{StringMatch, StringMatchCandidate};
|
||||
use gpui::{
|
||||
rems, Action, AnyElement, App, AppContext as _, Context, DismissEvent, Entity, EventEmitter,
|
||||
|
@ -30,7 +30,7 @@ pub(crate) struct TasksModalDelegate {
|
|||
selected_index: usize,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
prompt: String,
|
||||
task_context: TaskContext,
|
||||
task_contexts: TaskContexts,
|
||||
placeholder_text: Arc<str>,
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ pub(crate) struct TaskOverrides {
|
|||
impl TasksModalDelegate {
|
||||
fn new(
|
||||
task_store: Entity<TaskStore>,
|
||||
task_context: TaskContext,
|
||||
task_contexts: TaskContexts,
|
||||
task_overrides: Option<TaskOverrides>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
) -> Self {
|
||||
|
@ -65,7 +65,7 @@ impl TasksModalDelegate {
|
|||
divider_index: None,
|
||||
selected_index: 0,
|
||||
prompt: String::default(),
|
||||
task_context,
|
||||
task_contexts,
|
||||
task_overrides,
|
||||
placeholder_text,
|
||||
}
|
||||
|
@ -76,6 +76,11 @@ impl TasksModalDelegate {
|
|||
return None;
|
||||
}
|
||||
|
||||
let default_context = TaskContext::default();
|
||||
let active_context = self
|
||||
.task_contexts
|
||||
.active_context()
|
||||
.unwrap_or(&default_context);
|
||||
let source_kind = TaskSourceKind::UserInput;
|
||||
let id_base = source_kind.to_id_base();
|
||||
let mut new_oneshot = TaskTemplate {
|
||||
|
@ -91,7 +96,7 @@ impl TasksModalDelegate {
|
|||
}
|
||||
Some((
|
||||
source_kind,
|
||||
new_oneshot.resolve_task(&id_base, &self.task_context)?,
|
||||
new_oneshot.resolve_task(&id_base, active_context)?,
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -122,7 +127,7 @@ pub(crate) struct TasksModal {
|
|||
impl TasksModal {
|
||||
pub(crate) fn new(
|
||||
task_store: Entity<TaskStore>,
|
||||
task_context: TaskContext,
|
||||
task_contexts: TaskContexts,
|
||||
task_overrides: Option<TaskOverrides>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
window: &mut Window,
|
||||
|
@ -130,7 +135,7 @@ impl TasksModal {
|
|||
) -> Self {
|
||||
let picker = cx.new(|cx| {
|
||||
Picker::uniform_list(
|
||||
TasksModalDelegate::new(task_store, task_context, task_overrides, workspace),
|
||||
TasksModalDelegate::new(task_store, task_contexts, task_overrides, workspace),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
|
@ -225,7 +230,7 @@ impl PickerDelegate for TasksModalDelegate {
|
|||
task_inventory.read(cx).used_and_current_resolved_tasks(
|
||||
worktree,
|
||||
location,
|
||||
&picker.delegate.task_context,
|
||||
&picker.delegate.task_contexts,
|
||||
cx,
|
||||
);
|
||||
picker.delegate.last_used_candidate_index = if used.is_empty() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue