
New list (used tasks are above the separator line, sorted by the usage recency), then all language tasks, then project-local and global tasks are listed. Note that there are two test tasks (for `test_name_1` and `test_name_2` functions) that are created from the same task template: <img width="563" alt="Screenshot 2024-04-10 at 01 00 46" src="https://github.com/zed-industries/zed/assets/2690773/7455a82f-2af2-47bf-99bd-d9c5a36e64ab"> Tasks are deduplicated by labels, with the used tasks left in case of the conflict with the new tasks from the template: <img width="555" alt="Screenshot 2024-04-10 at 01 01 06" src="https://github.com/zed-industries/zed/assets/2690773/8f5a249e-abec-46ef-a991-08c6d0348648"> Regular recent tasks can be now removed too: <img width="565" alt="Screenshot 2024-04-10 at 01 00 55" src="https://github.com/zed-industries/zed/assets/2690773/0976b8fe-b5d7-4d2a-953d-1d8b1f216192"> When the caret is in the place where no function symbol could be retrieved, no cargo tests for function are listed in tasks: <img width="556" alt="image" src="https://github.com/zed-industries/zed/assets/2690773/df30feba-fe27-4645-8be9-02afc70f02da"> Part of https://github.com/zed-industries/zed/issues/10132 Reworks the task code to simplify it and enable proper task labels. * removes `trait Task`, renames `Definition` into `TaskTemplate` and use that instead of `Arc<dyn Task>` everywhere * implement more generic `TaskId` generation that depends on the `TaskContext` and `TaskTemplate` * remove `TaskId` out of the template and only create it after "resolving" the template into the `ResolvedTask`: this way, task templates, task state (`TaskContext`) and task "result" (resolved state) are clearly separated and are not mixed * implement the logic for filtering out non-related language tasks and tasks that have non-resolved Zed task variables * rework Zed template-vs-resolved-task display in modal: now all reruns and recently used tasks are resolved tasks with "fixed" context (unless configured otherwise in the task json) that are always shown, and Zed can add on top tasks with different context that are derived from the same template as the used, resolved tasks * sort the tasks list better, showing more specific and least recently used tasks higher * shows a separator between used and unused tasks, allow removing the used tasks same as the oneshot ones * remote the Oneshot task source as redundant: all oneshot tasks are now stored in the inventory's history * when reusing the tasks as query in the modal, paste the expanded task label now, show trimmed resolved label in the modal * adjusts Rust and Elixir task labels to be more descriptive and closer to bash scripts Release Notes: - Improved task modal ordering, run and deletion capabilities
134 lines
4.8 KiB
Rust
134 lines
4.8 KiB
Rust
//! A source of tasks, based on a static configuration, deserialized from the tasks config file, and related infrastructure for tracking changes to the file.
|
|
|
|
use futures::StreamExt;
|
|
use gpui::{AppContext, Context, Model, ModelContext, Subscription};
|
|
use serde::Deserialize;
|
|
use util::ResultExt;
|
|
|
|
use crate::{TaskSource, TaskTemplates};
|
|
use futures::channel::mpsc::UnboundedReceiver;
|
|
|
|
/// The source of tasks defined in a tasks config file.
|
|
pub struct StaticSource {
|
|
tasks: TaskTemplates,
|
|
_templates: Model<TrackedFile<TaskTemplates>>,
|
|
_subscription: Subscription,
|
|
}
|
|
|
|
/// A Wrapper around deserializable T that keeps track of its contents
|
|
/// via a provided channel. Once T value changes, the observers of [`TrackedFile`] are
|
|
/// notified.
|
|
pub struct TrackedFile<T> {
|
|
parsed_contents: T,
|
|
}
|
|
|
|
impl<T: PartialEq + 'static> TrackedFile<T> {
|
|
/// Initializes new [`TrackedFile`] with a type that's deserializable.
|
|
pub fn new(mut tracker: UnboundedReceiver<String>, cx: &mut AppContext) -> Model<Self>
|
|
where
|
|
T: for<'a> Deserialize<'a> + Default,
|
|
{
|
|
cx.new_model(move |cx| {
|
|
cx.spawn(|tracked_file, mut cx| async move {
|
|
while let Some(new_contents) = tracker.next().await {
|
|
if !new_contents.trim().is_empty() {
|
|
// String -> T (ZedTaskFormat)
|
|
// String -> U (VsCodeFormat) -> Into::into T
|
|
let Some(new_contents) =
|
|
serde_json_lenient::from_str(&new_contents).log_err()
|
|
else {
|
|
continue;
|
|
};
|
|
tracked_file.update(&mut cx, |tracked_file: &mut TrackedFile<T>, cx| {
|
|
if tracked_file.parsed_contents != new_contents {
|
|
tracked_file.parsed_contents = new_contents;
|
|
cx.notify();
|
|
};
|
|
})?;
|
|
}
|
|
}
|
|
anyhow::Ok(())
|
|
})
|
|
.detach_and_log_err(cx);
|
|
Self {
|
|
parsed_contents: Default::default(),
|
|
}
|
|
})
|
|
}
|
|
|
|
/// Initializes new [`TrackedFile`] with a type that's convertible from another deserializable type.
|
|
pub fn new_convertible<U: for<'a> Deserialize<'a> + TryInto<T, Error = anyhow::Error>>(
|
|
mut tracker: UnboundedReceiver<String>,
|
|
cx: &mut AppContext,
|
|
) -> Model<Self>
|
|
where
|
|
T: Default,
|
|
{
|
|
cx.new_model(move |cx| {
|
|
cx.spawn(|tracked_file, mut cx| async move {
|
|
while let Some(new_contents) = tracker.next().await {
|
|
if !new_contents.trim().is_empty() {
|
|
let Some(new_contents) =
|
|
serde_json_lenient::from_str::<U>(&new_contents).log_err()
|
|
else {
|
|
continue;
|
|
};
|
|
let Some(new_contents) = new_contents.try_into().log_err() else {
|
|
continue;
|
|
};
|
|
tracked_file.update(&mut cx, |tracked_file: &mut TrackedFile<T>, cx| {
|
|
if tracked_file.parsed_contents != new_contents {
|
|
tracked_file.parsed_contents = new_contents;
|
|
cx.notify();
|
|
};
|
|
})?;
|
|
}
|
|
}
|
|
anyhow::Ok(())
|
|
})
|
|
.detach_and_log_err(cx);
|
|
Self {
|
|
parsed_contents: Default::default(),
|
|
}
|
|
})
|
|
}
|
|
|
|
fn get(&self) -> &T {
|
|
&self.parsed_contents
|
|
}
|
|
}
|
|
|
|
impl StaticSource {
|
|
/// Initializes the static source, reacting on tasks config changes.
|
|
pub fn new(
|
|
templates: Model<TrackedFile<TaskTemplates>>,
|
|
cx: &mut AppContext,
|
|
) -> Model<Box<dyn TaskSource>> {
|
|
cx.new_model(|cx| {
|
|
let _subscription = cx.observe(
|
|
&templates,
|
|
move |source: &mut Box<(dyn TaskSource + 'static)>, new_templates, cx| {
|
|
if let Some(static_source) = source.as_any().downcast_mut::<Self>() {
|
|
static_source.tasks = new_templates.read(cx).get().clone();
|
|
cx.notify();
|
|
}
|
|
},
|
|
);
|
|
Box::new(Self {
|
|
tasks: TaskTemplates::default(),
|
|
_templates: templates,
|
|
_subscription,
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
impl TaskSource for StaticSource {
|
|
fn tasks_to_schedule(&mut self, _: &mut ModelContext<Box<dyn TaskSource>>) -> TaskTemplates {
|
|
self.tasks.clone()
|
|
}
|
|
|
|
fn as_any(&mut self) -> &mut dyn std::any::Any {
|
|
self
|
|
}
|
|
}
|