Add tests on inventory task sorting
This commit is contained in:
parent
ca092fb694
commit
2e516261fe
6 changed files with 267 additions and 32 deletions
|
@ -56,13 +56,13 @@ pub trait Task {
|
|||
///
|
||||
/// Implementations of this trait could be e.g. [`StaticSource`] that parses tasks from a .json files and provides process templates to be spawned;
|
||||
/// another one could be a language server providing lenses with tests or build server listing all targets for a given project.
|
||||
pub trait Source: Any {
|
||||
pub trait TaskSource: Any {
|
||||
/// A way to erase the type of the source, processing and storing them generically.
|
||||
fn as_any(&mut self) -> &mut dyn Any;
|
||||
/// Collects all tasks available for scheduling, for the path given.
|
||||
fn tasks_for_path(
|
||||
&mut self,
|
||||
path: Option<&Path>,
|
||||
cx: &mut ModelContext<Box<dyn Source>>,
|
||||
cx: &mut ModelContext<Box<dyn TaskSource>>,
|
||||
) -> Vec<Arc<dyn Task>>;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{Source, SpawnInTerminal, Task, TaskId};
|
||||
use crate::{SpawnInTerminal, Task, TaskId, TaskSource};
|
||||
use gpui::{AppContext, Context, Model};
|
||||
|
||||
/// A storage and source of tasks generated out of user command prompt inputs.
|
||||
|
@ -54,8 +54,8 @@ impl Task for OneshotTask {
|
|||
|
||||
impl OneshotSource {
|
||||
/// Initializes the oneshot source, preparing to store user prompts.
|
||||
pub fn new(cx: &mut AppContext) -> Model<Box<dyn Source>> {
|
||||
cx.new_model(|_| Box::new(Self { tasks: Vec::new() }) as Box<dyn Source>)
|
||||
pub fn new(cx: &mut AppContext) -> Model<Box<dyn TaskSource>> {
|
||||
cx.new_model(|_| Box::new(Self { tasks: Vec::new() }) as Box<dyn TaskSource>)
|
||||
}
|
||||
|
||||
/// Spawns a certain task based on the user prompt.
|
||||
|
@ -66,7 +66,7 @@ impl OneshotSource {
|
|||
}
|
||||
}
|
||||
|
||||
impl Source for OneshotSource {
|
||||
impl TaskSource for OneshotSource {
|
||||
fn as_any(&mut self) -> &mut dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ impl Source for OneshotSource {
|
|||
fn tasks_for_path(
|
||||
&mut self,
|
||||
_path: Option<&std::path::Path>,
|
||||
_cx: &mut gpui::ModelContext<Box<dyn Source>>,
|
||||
_cx: &mut gpui::ModelContext<Box<dyn TaskSource>>,
|
||||
) -> Vec<Arc<dyn Task>> {
|
||||
self.tasks.clone()
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use schemars::{gen::SchemaSettings, JsonSchema};
|
|||
use serde::{Deserialize, Serialize};
|
||||
use util::ResultExt;
|
||||
|
||||
use crate::{Source, SpawnInTerminal, Task, TaskId};
|
||||
use crate::{SpawnInTerminal, Task, TaskId, TaskSource};
|
||||
use futures::channel::mpsc::UnboundedReceiver;
|
||||
|
||||
/// A single config file entry with the deserialized task definition.
|
||||
|
@ -152,12 +152,12 @@ impl StaticSource {
|
|||
pub fn new(
|
||||
tasks_file_tracker: UnboundedReceiver<String>,
|
||||
cx: &mut AppContext,
|
||||
) -> Model<Box<dyn Source>> {
|
||||
) -> Model<Box<dyn TaskSource>> {
|
||||
let definitions = TrackedFile::new(DefinitionProvider::default(), tasks_file_tracker, cx);
|
||||
cx.new_model(|cx| {
|
||||
let _subscription = cx.observe(
|
||||
&definitions,
|
||||
|source: &mut Box<(dyn Source + 'static)>, new_definitions, cx| {
|
||||
|source: &mut Box<(dyn TaskSource + 'static)>, new_definitions, cx| {
|
||||
if let Some(static_source) = source.as_any().downcast_mut::<Self>() {
|
||||
static_source.tasks = new_definitions
|
||||
.read(cx)
|
||||
|
@ -181,11 +181,11 @@ impl StaticSource {
|
|||
}
|
||||
}
|
||||
|
||||
impl Source for StaticSource {
|
||||
impl TaskSource for StaticSource {
|
||||
fn tasks_for_path(
|
||||
&mut self,
|
||||
_: Option<&Path>,
|
||||
_: &mut ModelContext<Box<dyn Source>>,
|
||||
_: &mut ModelContext<Box<dyn TaskSource>>,
|
||||
) -> Vec<Arc<dyn Task>> {
|
||||
self.tasks
|
||||
.clone()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue