Add task docs and default keybindings (#8123)

Also group task source modules together

Release Notes:

- N/A

---------

Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
This commit is contained in:
Kirill Bulatov 2024-02-21 16:43:56 +02:00 committed by GitHub
parent b9151b9506
commit 0c939e5dfc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 84 additions and 64 deletions

View file

@ -2,13 +2,11 @@ use std::path::PathBuf;
use gpui::{AppContext, ViewContext, WindowContext};
use modal::TasksModal;
pub use oneshot_source::OneshotSource;
use task::Task;
use util::ResultExt;
use workspace::Workspace;
mod modal;
mod oneshot_source;
pub fn init(cx: &mut AppContext) {
cx.observe_new_views(

View file

@ -8,12 +8,12 @@ use gpui::{
};
use picker::{Picker, PickerDelegate};
use project::Inventory;
use task::Task;
use task::{oneshot_source::OneshotSource, Task};
use ui::{v_flex, HighlightedLabel, ListItem, ListItemSpacing, Selectable};
use util::ResultExt;
use workspace::{ModalView, Workspace};
use crate::{schedule_task, OneshotSource};
use crate::schedule_task;
actions!(task, [Spawn, Rerun]);

View file

@ -1,77 +0,0 @@
use std::sync::Arc;
use gpui::{AppContext, Model};
use task::{Source, SpawnInTerminal, Task, TaskId};
use ui::Context;
pub struct OneshotSource {
tasks: Vec<Arc<dyn Task>>,
}
#[derive(Clone)]
struct OneshotTask {
id: TaskId,
}
impl OneshotTask {
fn new(prompt: String) -> Self {
Self { id: TaskId(prompt) }
}
}
impl Task for OneshotTask {
fn id(&self) -> &TaskId {
&self.id
}
fn name(&self) -> &str {
&self.id.0
}
fn cwd(&self) -> Option<&std::path::Path> {
None
}
fn exec(&self, cwd: Option<std::path::PathBuf>) -> Option<SpawnInTerminal> {
if self.id().0.is_empty() {
return None;
}
Some(SpawnInTerminal {
id: self.id().clone(),
label: self.name().to_owned(),
command: self.id().0.clone(),
args: vec![],
cwd,
env: Default::default(),
use_new_terminal: Default::default(),
allow_concurrent_runs: Default::default(),
separate_shell: true,
})
}
}
impl OneshotSource {
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 spawn(&mut self, prompt: String) -> Arc<dyn Task> {
let ret = Arc::new(OneshotTask::new(prompt));
self.tasks.push(ret.clone());
ret
}
}
impl Source for OneshotSource {
fn as_any(&mut self) -> &mut dyn std::any::Any {
self
}
fn tasks_for_path(
&mut self,
_path: Option<&std::path::Path>,
_cx: &mut gpui::ModelContext<Box<dyn Source>>,
) -> Vec<Arc<dyn Task>> {
self.tasks.clone()
}
}