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

@ -18,10 +18,14 @@ pub fn init(cx: &mut AppContext) {
workspace
.register_action(spawn_task_or_modal)
.register_action(move |workspace, action: &modal::Rerun, cx| {
if let Some((task_source_kind, mut last_scheduled_task)) =
workspace.project().update(cx, |project, cx| {
project
.task_inventory()
if let Some((task_source_kind, mut last_scheduled_task)) = workspace
.project()
.read(cx)
.task_store()
.read(cx)
.task_inventory()
.and_then(|inventory| {
inventory
.read(cx)
.last_scheduled_task(action.task_id.as_ref())
})
@ -86,23 +90,26 @@ fn spawn_task_or_modal(workspace: &mut Workspace, action: &Spawn, cx: &mut ViewC
}
fn toggle_modal(workspace: &mut Workspace, cx: &mut ViewContext<'_, Workspace>) -> AsyncTask<()> {
let project = workspace.project().clone();
let task_store = workspace.project().read(cx).task_store().clone();
let workspace_handle = workspace.weak_handle();
let context_task = task_context(workspace, cx);
cx.spawn(|workspace, mut cx| async move {
let task_context = context_task.await;
workspace
.update(&mut cx, |workspace, cx| {
if workspace.project().update(cx, |project, cx| {
project.is_local() || project.ssh_connection_string(cx).is_some()
}) {
let can_open_modal = workspace.project().update(cx, |project, cx| {
project.is_local() || project.ssh_connection_string(cx).is_some() || project.is_via_ssh()
});
if can_open_modal {
let context_task = task_context(workspace, cx);
cx.spawn(|workspace, mut cx| async move {
let task_context = context_task.await;
workspace
.update(&mut cx, |workspace, cx| {
workspace.toggle_modal(cx, |cx| {
TasksModal::new(project, task_context, workspace_handle, cx)
TasksModal::new(task_store.clone(), task_context, workspace_handle, cx)
})
}
})
.ok();
})
})
.ok();
})
} else {
AsyncTask::ready(())
}
}
fn spawn_task_with_name(
@ -113,14 +120,31 @@ fn spawn_task_with_name(
let context_task =
workspace.update(&mut cx, |workspace, cx| task_context(workspace, cx))?;
let task_context = context_task.await;
let tasks = workspace
.update(&mut cx, |workspace, cx| {
let (worktree, location) = active_item_selection_properties(workspace, cx);
workspace.project().update(cx, |project, cx| {
project.task_templates(worktree, location, cx)
let tasks = workspace.update(&mut cx, |workspace, cx| {
let Some(task_inventory) = workspace
.project()
.read(cx)
.task_store()
.read(cx)
.task_inventory()
.cloned()
else {
return Vec::new();
};
let (worktree, location) = active_item_selection_properties(workspace, cx);
let (file, language) = location
.map(|location| {
let buffer = location.buffer.read(cx);
(
buffer.file().cloned(),
buffer.language_at(location.range.start),
)
})
})?
.await?;
.unwrap_or_default();
task_inventory
.read(cx)
.list_tasks(file, language, worktree, cx)
})?;
let did_spawn = workspace
.update(&mut cx, |workspace, cx| {
@ -185,7 +209,7 @@ mod tests {
use editor::Editor;
use gpui::{Entity, TestAppContext};
use language::{Language, LanguageConfig};
use project::{BasicContextProvider, FakeFs, Project};
use project::{task_store::TaskStore, BasicContextProvider, FakeFs, Project};
use serde_json::json;
use task::{TaskContext, TaskVariables, VariableName};
use ui::VisualContext;
@ -223,6 +247,7 @@ mod tests {
)
.await;
let project = Project::test(fs, ["/dir".as_ref()], cx).await;
let worktree_store = project.update(cx, |project, _| project.worktree_store().clone());
let rust_language = Arc::new(
Language::new(
LanguageConfig::default(),
@ -234,7 +259,9 @@ mod tests {
name: (_) @name) @item"#,
)
.unwrap()
.with_context_provider(Some(Arc::new(BasicContextProvider::new(project.clone())))),
.with_context_provider(Some(Arc::new(BasicContextProvider::new(
worktree_store.clone(),
)))),
);
let typescript_language = Arc::new(
@ -252,7 +279,9 @@ mod tests {
")" @context)) @item"#,
)
.unwrap()
.with_context_provider(Some(Arc::new(BasicContextProvider::new(project.clone())))),
.with_context_provider(Some(Arc::new(BasicContextProvider::new(
worktree_store.clone(),
)))),
);
let worktree_id = project.update(cx, |project, cx| {
@ -373,6 +402,7 @@ mod tests {
editor::init(cx);
workspace::init_settings(cx);
Project::init_settings(cx);
TaskStore::init(None);
state
})
}