Rework remote task synchronization (#18746)

Reworks the way tasks are stored, accessed and synchronized in the
`project`.
Now both collab and ssh remote projects use the same TaskStorage kind to
get the task context from the remote host, and worktree task templates
are synchronized along with other worktree settings.

Release Notes:

- Adds ssh support to tasks, improves collab-remote projects' tasks sync
This commit is contained in:
Kirill Bulatov 2024-10-09 22:28:42 +03:00 committed by GitHub
parent f1053ff525
commit 49c75eb062
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 1262 additions and 1366 deletions

View file

@ -16,7 +16,7 @@ use serde_json::json;
use std::os;
use std::{mem, ops::Range, task::Poll};
use task::{ResolvedTask, TaskContext, TaskTemplate, TaskTemplates};
use task::{ResolvedTask, TaskContext};
use unindent::Unindent as _;
use util::{assert_set_eq, paths::PathMatcher, test::temp_tree, TryFutureExt as _};
@ -94,6 +94,7 @@ async fn test_symlinks(cx: &mut gpui::TestAppContext) {
#[gpui::test]
async fn test_managing_project_specific_settings(cx: &mut gpui::TestAppContext) {
init_test(cx);
TaskStore::init(None);
let fs = FakeFs::new(cx.executor());
fs.insert_tree(
@ -102,7 +103,7 @@ async fn test_managing_project_specific_settings(cx: &mut gpui::TestAppContext)
".zed": {
"settings.json": r#"{ "tab_size": 8 }"#,
"tasks.json": r#"[{
"label": "cargo check",
"label": "cargo check all",
"command": "cargo",
"args": ["check", "--all"]
},]"#,
@ -135,10 +136,10 @@ async fn test_managing_project_specific_settings(cx: &mut gpui::TestAppContext)
project.worktrees(cx).next().unwrap().read(cx).id()
})
});
let global_task_source_kind = TaskSourceKind::Worktree {
let topmost_local_task_source_kind = TaskSourceKind::Worktree {
id: worktree_id,
abs_path: PathBuf::from("/the-root/.zed/tasks.json"),
id_base: "local_tasks_for_worktree".into(),
directory_in_worktree: PathBuf::from(".zed"),
id_base: "local worktree tasks from directory \".zed\"".into(),
};
let all_tasks = cx
@ -171,7 +172,6 @@ async fn test_managing_project_specific_settings(cx: &mut gpui::TestAppContext)
get_all_tasks(&project, Some(worktree_id), &task_context, cx)
})
.await
.into_iter()
.map(|(source_kind, task)| {
let resolved = task.resolved.unwrap();
@ -186,71 +186,65 @@ async fn test_managing_project_specific_settings(cx: &mut gpui::TestAppContext)
assert_eq!(
all_tasks,
vec![
(
global_task_source_kind.clone(),
"cargo check".to_string(),
vec!["check".to_string(), "--all".to_string()],
HashMap::default(),
),
(
TaskSourceKind::Worktree {
id: worktree_id,
abs_path: PathBuf::from("/the-root/b/.zed/tasks.json"),
id_base: "local_tasks_for_worktree".into(),
directory_in_worktree: PathBuf::from("b/.zed"),
id_base: "local worktree tasks from directory \"b/.zed\"".into(),
},
"cargo check".to_string(),
vec!["check".to_string()],
HashMap::default(),
),
(
topmost_local_task_source_kind.clone(),
"cargo check all".to_string(),
vec!["check".to_string(), "--all".to_string()],
HashMap::default(),
),
]
);
let (_, resolved_task) = cx
.update(|cx| get_all_tasks(&project, Some(worktree_id), &task_context, cx))
.await
.into_iter()
.find(|(source_kind, _)| source_kind == &global_task_source_kind)
.find(|(source_kind, _)| source_kind == &topmost_local_task_source_kind)
.expect("should have one global task");
project.update(cx, |project, cx| {
project.task_inventory().update(cx, |inventory, _| {
inventory.task_scheduled(global_task_source_kind.clone(), resolved_task);
let task_inventory = project
.task_store
.read(cx)
.task_inventory()
.cloned()
.unwrap();
task_inventory.update(cx, |inventory, _| {
inventory.task_scheduled(topmost_local_task_source_kind.clone(), resolved_task);
inventory
.update_file_based_tasks(
None,
Some(
&json!([{
"label": "cargo check unstable",
"command": "cargo",
"args": [
"check",
"--all",
"--all-targets"
],
"env": {
"RUSTFLAGS": "-Zunstable-options"
}
}])
.to_string(),
),
)
.unwrap();
});
});
let tasks = serde_json::to_string(&TaskTemplates(vec![TaskTemplate {
label: "cargo check".to_string(),
command: "cargo".to_string(),
args: vec![
"check".to_string(),
"--all".to_string(),
"--all-targets".to_string(),
],
env: HashMap::from_iter(Some((
"RUSTFLAGS".to_string(),
"-Zunstable-options".to_string(),
))),
..TaskTemplate::default()
}]))
.unwrap();
let (tx, rx) = futures::channel::mpsc::unbounded();
cx.update(|cx| {
project.update(cx, |project, cx| {
project.task_inventory().update(cx, |inventory, cx| {
inventory.remove_local_static_source(Path::new("/the-root/.zed/tasks.json"));
inventory.add_source(
global_task_source_kind.clone(),
|tx, cx| StaticSource::new(TrackedFile::new(rx, tx, cx)),
cx,
);
});
})
});
tx.unbounded_send(tasks).unwrap();
cx.run_until_parked();
let all_tasks = cx
.update(|cx| get_all_tasks(&project, Some(worktree_id), &task_context, cx))
.await
.into_iter()
.map(|(source_kind, task)| {
let resolved = task.resolved.unwrap();
@ -265,33 +259,38 @@ async fn test_managing_project_specific_settings(cx: &mut gpui::TestAppContext)
assert_eq!(
all_tasks,
vec![
(
topmost_local_task_source_kind.clone(),
"cargo check all".to_string(),
vec!["check".to_string(), "--all".to_string()],
HashMap::default(),
),
(
TaskSourceKind::Worktree {
id: worktree_id,
abs_path: PathBuf::from("/the-root/.zed/tasks.json"),
id_base: "local_tasks_for_worktree".into(),
directory_in_worktree: PathBuf::from("b/.zed"),
id_base: "local worktree tasks from directory \"b/.zed\"".into(),
},
"cargo check".to_string(),
vec!["check".to_string()],
HashMap::default(),
),
(
TaskSourceKind::AbsPath {
abs_path: paths::tasks_file().clone(),
id_base: "global tasks.json".into(),
},
"cargo check unstable".to_string(),
vec![
"check".to_string(),
"--all".to_string(),
"--all-targets".to_string()
"--all-targets".to_string(),
],
HashMap::from_iter(Some((
"RUSTFLAGS".to_string(),
"-Zunstable-options".to_string()
))),
),
(
TaskSourceKind::Worktree {
id: worktree_id,
abs_path: PathBuf::from("/the-root/b/.zed/tasks.json"),
id_base: "local_tasks_for_worktree".into(),
},
"cargo check".to_string(),
vec!["check".to_string()],
HashMap::default(),
),
]
);
}
@ -5416,17 +5415,16 @@ fn get_all_tasks(
worktree_id: Option<WorktreeId>,
task_context: &TaskContext,
cx: &mut AppContext,
) -> Task<Vec<(TaskSourceKind, ResolvedTask)>> {
let resolved_tasks = project.update(cx, |project, cx| {
) -> Vec<(TaskSourceKind, ResolvedTask)> {
let (mut old, new) = project.update(cx, |project, cx| {
project
.task_inventory()
.task_store
.read(cx)
.used_and_current_resolved_tasks(None, worktree_id, None, task_context, cx)
.task_inventory()
.unwrap()
.read(cx)
.used_and_current_resolved_tasks(worktree_id, None, task_context, cx)
});
cx.spawn(|_| async move {
let (mut old, new) = resolved_tasks.await;
old.extend(new);
old
})
old.extend(new);
old
}