debugger: Ensure both debug and regular global tasks are correctly merged (#27184)

Follow-up of https://github.com/zed-industries/zed/pull/13433
Closes https://github.com/zed-industries/zed/issues/27124
Closes https://github.com/zed-industries/zed/issues/27066

After this change, both old global task source, `tasks.json` and new,
`debug.json` started to call for the same task update method:


14920ab910/crates/project/src/task_inventory.rs (L414)

erasing previous declarations.

The PR puts this data under different paths instead and adjusts the code
around it.

Release Notes:

- Fixed custom tasks not shown
This commit is contained in:
Kirill Bulatov 2025-03-20 14:51:26 +02:00 committed by GitHub
parent 5bef32f3ed
commit de99febd9b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 57 additions and 35 deletions

View file

@ -13,7 +13,7 @@ use collections::{HashMap, HashSet, VecDeque};
use gpui::{App, AppContext as _, Entity, SharedString, Task};
use itertools::Itertools;
use language::{ContextProvider, File, Language, LanguageToolchainStore, Location};
use settings::{parse_json_with_comments, SettingsLocation, TaskKind};
use settings::{parse_json_with_comments, TaskKind};
use task::{
DebugTaskDefinition, ResolvedTask, TaskContext, TaskId, TaskTemplate, TaskTemplates,
TaskVariables, VariableName,
@ -22,7 +22,7 @@ use text::{Point, ToPoint};
use util::{paths::PathExt as _, post_inc, NumericPrefixWithSuffix, ResultExt as _};
use worktree::WorktreeId;
use crate::worktree_store::WorktreeStore;
use crate::{task_store::TaskSettingsLocation, worktree_store::WorktreeStore};
/// Inventory tracks available tasks for a given project.
#[derive(Debug, Default)]
@ -33,7 +33,7 @@ pub struct Inventory {
#[derive(Debug, Default)]
struct ParsedTemplates {
global: Vec<TaskTemplate>,
global: HashMap<PathBuf, Vec<TaskTemplate>>,
worktree: HashMap<WorktreeId, HashMap<(Arc<Path>, TaskKind), Vec<TaskTemplate>>>,
}
@ -324,22 +324,20 @@ impl Inventory {
) -> impl '_ + Iterator<Item = (TaskSourceKind, TaskTemplate)> {
self.templates_from_settings
.global
.clone()
.into_iter()
.map(|template| {
(
TaskSourceKind::AbsPath {
id_base: match template.task_type {
task::TaskType::Script => Cow::Borrowed("global tasks.json"),
task::TaskType::Debug(_) => Cow::Borrowed("global debug.json"),
.iter()
.flat_map(|(file_path, templates)| {
templates.into_iter().map(|template| {
(
TaskSourceKind::AbsPath {
id_base: match template.task_type {
task::TaskType::Script => Cow::Borrowed("global tasks.json"),
task::TaskType::Debug(_) => Cow::Borrowed("global debug.json"),
},
abs_path: file_path.clone(),
},
abs_path: match template.task_type {
task::TaskType::Script => paths::tasks_file().clone(),
task::TaskType::Debug(_) => paths::debug_tasks_file().clone(),
},
},
template,
)
template.clone(),
)
})
})
}
@ -377,7 +375,7 @@ impl Inventory {
/// Global tasks are updated for no worktree provided, otherwise the worktree metadata for a given path will be updated.
pub(crate) fn update_file_based_tasks(
&mut self,
location: Option<SettingsLocation<'_>>,
location: TaskSettingsLocation<'_>,
raw_tasks_json: Option<&str>,
task_kind: TaskKind,
) -> anyhow::Result<()> {
@ -395,7 +393,13 @@ impl Inventory {
let parsed_templates = &mut self.templates_from_settings;
match location {
Some(location) => {
TaskSettingsLocation::Global(path) => {
parsed_templates
.global
.entry(path.to_owned())
.insert_entry(new_templates.collect());
}
TaskSettingsLocation::Worktree(location) => {
let new_templates = new_templates.collect::<Vec<_>>();
if new_templates.is_empty() {
if let Some(worktree_tasks) =
@ -411,8 +415,8 @@ impl Inventory {
.insert((Arc::from(location.path), task_kind), new_templates);
}
}
None => parsed_templates.global = new_templates.collect(),
}
Ok(())
}
}
@ -651,8 +655,10 @@ impl ContextProvider for ContextProviderWithTasks {
#[cfg(test)]
mod tests {
use gpui::TestAppContext;
use paths::tasks_file;
use pretty_assertions::assert_eq;
use serde_json::json;
use settings::SettingsLocation;
use crate::task_store::TaskStore;
@ -684,7 +690,7 @@ mod tests {
inventory.update(cx, |inventory, _| {
inventory
.update_file_based_tasks(
None,
TaskSettingsLocation::Global(tasks_file()),
Some(&mock_tasks_from_names(
expected_initial_state.iter().map(|name| name.as_str()),
)),
@ -738,7 +744,7 @@ mod tests {
inventory.update(cx, |inventory, _| {
inventory
.update_file_based_tasks(
None,
TaskSettingsLocation::Global(tasks_file()),
Some(&mock_tasks_from_names(
["10_hello", "11_hello"]
.into_iter()
@ -863,7 +869,7 @@ mod tests {
inventory.update(cx, |inventory, _| {
inventory
.update_file_based_tasks(
None,
TaskSettingsLocation::Global(tasks_file()),
Some(&mock_tasks_from_names(
worktree_independent_tasks
.iter()
@ -874,7 +880,7 @@ mod tests {
.unwrap();
inventory
.update_file_based_tasks(
Some(SettingsLocation {
TaskSettingsLocation::Worktree(SettingsLocation {
worktree_id: worktree_1,
path: Path::new(".zed"),
}),
@ -886,7 +892,7 @@ mod tests {
.unwrap();
inventory
.update_file_based_tasks(
Some(SettingsLocation {
TaskSettingsLocation::Worktree(SettingsLocation {
worktree_id: worktree_2,
path: Path::new(".zed"),
}),