Add support for detecting tests in source files, and implement it for Rust (#11195)
Continuing work from #10873 Release Notes: - N/A --------- Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
parent
14c7782ce6
commit
5a71d8c7f1
29 changed files with 1148 additions and 606 deletions
83
crates/workspace/src/tasks.rs
Normal file
83
crates/workspace/src/tasks.rs
Normal file
|
@ -0,0 +1,83 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use project::TaskSourceKind;
|
||||
use task::{ResolvedTask, TaskContext, TaskTemplate};
|
||||
use ui::{ViewContext, WindowContext};
|
||||
|
||||
use crate::Workspace;
|
||||
|
||||
pub fn task_cwd(workspace: &Workspace, cx: &mut WindowContext) -> anyhow::Result<Option<PathBuf>> {
|
||||
let project = workspace.project().read(cx);
|
||||
let available_worktrees = project
|
||||
.worktrees()
|
||||
.filter(|worktree| {
|
||||
let worktree = worktree.read(cx);
|
||||
worktree.is_visible()
|
||||
&& worktree.is_local()
|
||||
&& worktree.root_entry().map_or(false, |e| e.is_dir())
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let cwd = match available_worktrees.len() {
|
||||
0 => None,
|
||||
1 => Some(available_worktrees[0].read(cx).abs_path()),
|
||||
_ => {
|
||||
let cwd_for_active_entry = project.active_entry().and_then(|entry_id| {
|
||||
available_worktrees.into_iter().find_map(|worktree| {
|
||||
let worktree = worktree.read(cx);
|
||||
if worktree.contains_entry(entry_id) {
|
||||
Some(worktree.abs_path())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
});
|
||||
anyhow::ensure!(
|
||||
cwd_for_active_entry.is_some(),
|
||||
"Cannot determine task cwd for multiple worktrees"
|
||||
);
|
||||
cwd_for_active_entry
|
||||
}
|
||||
};
|
||||
Ok(cwd.map(|path| path.to_path_buf()))
|
||||
}
|
||||
|
||||
pub fn schedule_task(
|
||||
workspace: &Workspace,
|
||||
task_source_kind: TaskSourceKind,
|
||||
task_to_resolve: &TaskTemplate,
|
||||
task_cx: &TaskContext,
|
||||
omit_history: bool,
|
||||
cx: &mut ViewContext<'_, Workspace>,
|
||||
) {
|
||||
if let Some(spawn_in_terminal) =
|
||||
task_to_resolve.resolve_task(&task_source_kind.to_id_base(), task_cx)
|
||||
{
|
||||
schedule_resolved_task(
|
||||
workspace,
|
||||
task_source_kind,
|
||||
spawn_in_terminal,
|
||||
omit_history,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn schedule_resolved_task(
|
||||
workspace: &Workspace,
|
||||
task_source_kind: TaskSourceKind,
|
||||
mut resolved_task: ResolvedTask,
|
||||
omit_history: bool,
|
||||
cx: &mut ViewContext<'_, Workspace>,
|
||||
) {
|
||||
if let Some(spawn_in_terminal) = resolved_task.resolved.take() {
|
||||
if !omit_history {
|
||||
resolved_task.resolved = Some(spawn_in_terminal.clone());
|
||||
workspace.project().update(cx, |project, cx| {
|
||||
project.task_inventory().update(cx, |inventory, _| {
|
||||
inventory.task_scheduled(task_source_kind, resolved_task);
|
||||
})
|
||||
});
|
||||
}
|
||||
cx.emit(crate::Event::SpawnTask(spawn_in_terminal));
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ mod persistence;
|
|||
pub mod searchable;
|
||||
pub mod shared_screen;
|
||||
mod status_bar;
|
||||
pub mod tasks;
|
||||
mod toolbar;
|
||||
mod workspace_settings;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue