From b09e5af03f6e26e1f89bdc917de99230f073ebd5 Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 28 Oct 2025 14:34:47 -0400 Subject: [PATCH] Allow users to associated tasks with specific languages This lets users filter tasks shown based on the active location they're currently in --- crates/project/src/debugger/locators/go.rs | 3 +++ .../project/src/debugger/locators/python.rs | 1 + crates/task/src/task_template.rs | 6 +++++ crates/tasks_ui/src/modal.rs | 23 ++++++++++++++++++- 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/crates/project/src/debugger/locators/go.rs b/crates/project/src/debugger/locators/go.rs index eec06084ec78548e1a627080663d2afccc8a0aca..fd2fad1f7bfd41661ea79978fbbae9a2c71fe596 100644 --- a/crates/project/src/debugger/locators/go.rs +++ b/crates/project/src/debugger/locators/go.rs @@ -264,6 +264,7 @@ mod tests { hide: HideStrategy::Never, shell: Shell::System, tags: vec![], + languages: vec![], show_summary: true, show_command: true, }; @@ -291,6 +292,7 @@ mod tests { hide: HideStrategy::Never, shell: Shell::System, tags: vec![], + languages: vec![], show_summary: true, show_command: true, }; @@ -429,6 +431,7 @@ mod tests { hide: HideStrategy::Never, shell: Shell::System, tags: vec![], + languages: vec![], show_summary: true, show_command: true, }; diff --git a/crates/project/src/debugger/locators/python.rs b/crates/project/src/debugger/locators/python.rs index c3754548d0676e76f08368828d554600ab700fc0..c845ddcda1881b2b215d452392721173e3f32ecc 100644 --- a/crates/project/src/debugger/locators/python.rs +++ b/crates/project/src/debugger/locators/python.rs @@ -116,6 +116,7 @@ mod test { reveal_target: task::RevealTarget::Dock, hide: task::HideStrategy::Never, tags: vec!["python-module-main-method".into()], + languages: vec![], shell: task::Shell::System, show_summary: false, show_command: false, diff --git a/crates/task/src/task_template.rs b/crates/task/src/task_template.rs index 33ff610b6e1ba509c75138ad4bf35478e69deaf1..3c5c01def26ffb967a1f5d046afdf836a529d47e 100644 --- a/crates/task/src/task_template.rs +++ b/crates/task/src/task_template.rs @@ -58,6 +58,12 @@ pub struct TaskTemplate { /// * `on_success` — hide the terminal tab on task success only, otherwise behaves similar to `always`. #[serde(default)] pub hide: HideStrategy, + /// Languages that this task template is associated with + /// When this list is empty, the task will be visible in all langauges. + /// Otherwise, the task will be visible only in the specified languages. + #[serde(default, deserialize_with = "non_empty_string_vec")] + #[schemars(length(min = 1))] + pub languages: Vec, /// Represents the tags which this template attaches to. /// Adding this removes this task from other UI and gives you ability to run it by tag. #[serde(default, deserialize_with = "non_empty_string_vec")] diff --git a/crates/tasks_ui/src/modal.rs b/crates/tasks_ui/src/modal.rs index f82321feeb245b4ee3b6d56627387c8594d5db8e..20f21c379420d560077da0bc67918e806713331e 100644 --- a/crates/tasks_ui/src/modal.rs +++ b/crates/tasks_ui/src/modal.rs @@ -200,9 +200,30 @@ impl TasksModal { } })); self.picker.update(cx, |picker, cx| { + let language = task_contexts + .location() + .and_then(|location| location.buffer.read(cx).language()) + .map(|lang| lang.config().name.clone()); + picker.delegate.task_contexts = task_contexts; + picker.delegate.last_used_candidate_index = last_used_candidate_index; - picker.delegate.candidates = Some(new_candidates); + picker.delegate.candidates = Some( + new_candidates + .into_iter() + .filter(|candidate| { + let task_languages = &candidate.1.original_task().languages; + + task_languages.is_empty() + || language.as_ref().is_none_or(|lang| { + task_languages.iter().any(|task_lang| { + task_lang.to_ascii_lowercase().as_str() + == lang.0.to_ascii_lowercase().as_str() + }) + }) + }) + .collect(), + ); picker.refresh(window, cx); cx.notify(); })