Use proper Workspace references when querying for tasks by name (#10383)

Closes https://github.com/zed-industries/zed/issues/10380

Release Notes:

- Fixed Zed panicking when running tasks via a keybinding
([10380](https://github.com/zed-industries/zed/issues/10380))
This commit is contained in:
Kirill Bulatov 2024-04-10 23:42:17 +02:00 committed by GitHub
parent 8cbdd9e0fa
commit fd3ee5a9d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 15 deletions

View file

@ -195,8 +195,13 @@ impl PickerDelegate for TasksModalDelegate {
let Some(candidates) = picker
.update(&mut cx, |picker, cx| {
let candidates = picker.delegate.candidates.get_or_insert_with(|| {
let (worktree, language) =
active_item_selection_properties(&picker.delegate.workspace, cx);
let Ok((worktree, language)) =
picker.delegate.workspace.update(cx, |workspace, cx| {
active_item_selection_properties(workspace, cx)
})
else {
return Vec::new();
};
picker.delegate.inventory.update(cx, |inventory, cx| {
inventory.list_tasks(language, worktree, true, cx)
})
@ -376,6 +381,8 @@ mod tests {
use project::{FakeFs, Project};
use serde_json::json;
use crate::modal::Spawn;
use super::*;
#[gpui::test]
@ -514,13 +521,29 @@ mod tests {
vec!["echo 4", "another one", "example task", "echo 40"],
"Last recently used one show task should be listed last, as it is a fire-and-forget task"
);
cx.dispatch_action(Spawn {
task_name: Some("example task".to_string()),
});
let tasks_picker = workspace.update(cx, |workspace, cx| {
workspace
.active_modal::<TasksModal>(cx)
.unwrap()
.read(cx)
.picker
.clone()
});
assert_eq!(
task_names(&tasks_picker, cx),
vec!["echo 4", "another one", "example task", "echo 40"],
);
}
fn open_spawn_tasks(
workspace: &View<Workspace>,
cx: &mut VisualTestContext,
) -> View<Picker<TasksModalDelegate>> {
cx.dispatch_action(crate::modal::Spawn::default());
cx.dispatch_action(Spawn::default());
workspace.update(cx, |workspace, cx| {
workspace
.active_modal::<TasksModal>(cx)