Eliminate GPUI View, ViewContext, and WindowContext types (#22632)
There's still a bit more work to do on this, but this PR is compiling (with warnings) after eliminating the key types. When the tasks below are complete, this will be the new narrative for GPUI: - `Entity<T>` - This replaces `View<T>`/`Model<T>`. It represents a unit of state, and if `T` implements `Render`, then `Entity<T>` implements `Element`. - `&mut App` This replaces `AppContext` and represents the app. - `&mut Context<T>` This replaces `ModelContext` and derefs to `App`. It is provided by the framework when updating an entity. - `&mut Window` Broken out of `&mut WindowContext` which no longer exists. Every method that once took `&mut WindowContext` now takes `&mut Window, &mut App` and every method that took `&mut ViewContext<T>` now takes `&mut Window, &mut Context<T>` Not pictured here are the two other failed attempts. It's been quite a month! Tasks: - [x] Remove `View`, `ViewContext`, `WindowContext` and thread through `Window` - [x] [@cole-miller @mikayla-maki] Redraw window when entities change - [x] [@cole-miller @mikayla-maki] Get examples and Zed running - [x] [@cole-miller @mikayla-maki] Fix Zed rendering - [x] [@mikayla-maki] Fix todo! macros and comments - [x] Fix a bug where the editor would not be redrawn because of view caching - [x] remove publicness window.notify() and replace with `AppContext::notify` - [x] remove `observe_new_window_models`, replace with `observe_new_models` with an optional window - [x] Fix a bug where the project panel would not be redrawn because of the wrong refresh() call being used - [x] Fix the tests - [x] Fix warnings by eliminating `Window` params or using `_` - [x] Fix conflicts - [x] Simplify generic code where possible - [x] Rename types - [ ] Update docs ### issues post merge - [x] Issues switching between normal and insert mode - [x] Assistant re-rendering failure - [x] Vim test failures - [x] Mac build issue Release Notes: - N/A --------- Co-authored-by: Antonio Scandurra <me@as-cii.com> Co-authored-by: Cole Miller <cole@zed.dev> Co-authored-by: Mikayla <mikayla@zed.dev> Co-authored-by: Joseph <joseph@zed.dev> Co-authored-by: max <max@zed.dev> Co-authored-by: Michael Sloan <michael@zed.dev> Co-authored-by: Mikayla Maki <mikaylamaki@Mikaylas-MacBook-Pro.local> Co-authored-by: Mikayla <mikayla.c.maki@gmail.com> Co-authored-by: joão <joao@zed.dev>
This commit is contained in:
parent
21b4a0d50e
commit
6fca1d2b0b
648 changed files with 36248 additions and 28208 deletions
|
@ -8,6 +8,9 @@ license = "GPL-3.0-or-later"
|
|||
[lints]
|
||||
workspace = true
|
||||
|
||||
[lib]
|
||||
path = "src/tasks_ui.rs"
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
editor.workspace = true
|
||||
|
|
|
@ -3,9 +3,9 @@ use std::sync::Arc;
|
|||
use crate::active_item_selection_properties;
|
||||
use fuzzy::{StringMatch, StringMatchCandidate};
|
||||
use gpui::{
|
||||
rems, Action, AnyElement, AppContext, DismissEvent, EventEmitter, FocusableView,
|
||||
InteractiveElement, Model, ParentElement, Render, SharedString, Styled, Subscription, Task,
|
||||
View, ViewContext, VisualContext, WeakView,
|
||||
rems, Action, AnyElement, App, AppContext as _, Context, DismissEvent, Entity, EventEmitter,
|
||||
Focusable, InteractiveElement, ParentElement, Render, SharedString, Styled, Subscription, Task,
|
||||
WeakEntity, Window,
|
||||
};
|
||||
use picker::{highlighted_match_with_paths::HighlightedText, Picker, PickerDelegate};
|
||||
use project::{task_store::TaskStore, TaskSourceKind};
|
||||
|
@ -14,7 +14,6 @@ use ui::{
|
|||
div, h_flex, v_flex, ActiveTheme, Button, ButtonCommon, ButtonSize, Clickable, Color,
|
||||
FluentBuilder as _, Icon, IconButton, IconButtonShape, IconName, IconSize, IntoElement,
|
||||
KeyBinding, LabelSize, ListItem, ListItemSpacing, RenderOnce, Toggleable, Tooltip,
|
||||
WindowContext,
|
||||
};
|
||||
use util::ResultExt;
|
||||
use workspace::{tasks::schedule_resolved_task, ModalView, Workspace};
|
||||
|
@ -22,14 +21,14 @@ pub use zed_actions::{Rerun, Spawn};
|
|||
|
||||
/// A modal used to spawn new tasks.
|
||||
pub(crate) struct TasksModalDelegate {
|
||||
task_store: Model<TaskStore>,
|
||||
task_store: Entity<TaskStore>,
|
||||
candidates: Option<Vec<(TaskSourceKind, ResolvedTask)>>,
|
||||
task_overrides: Option<TaskOverrides>,
|
||||
last_used_candidate_index: Option<usize>,
|
||||
divider_index: Option<usize>,
|
||||
matches: Vec<StringMatch>,
|
||||
selected_index: usize,
|
||||
workspace: WeakView<Workspace>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
prompt: String,
|
||||
task_context: TaskContext,
|
||||
placeholder_text: Arc<str>,
|
||||
|
@ -44,10 +43,10 @@ pub(crate) struct TaskOverrides {
|
|||
|
||||
impl TasksModalDelegate {
|
||||
fn new(
|
||||
task_store: Model<TaskStore>,
|
||||
task_store: Entity<TaskStore>,
|
||||
task_context: TaskContext,
|
||||
task_overrides: Option<TaskOverrides>,
|
||||
workspace: WeakView<Workspace>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
) -> Self {
|
||||
let placeholder_text = if let Some(TaskOverrides {
|
||||
reveal_target: Some(RevealTarget::Center),
|
||||
|
@ -96,7 +95,7 @@ impl TasksModalDelegate {
|
|||
))
|
||||
}
|
||||
|
||||
fn delete_previously_used(&mut self, ix: usize, cx: &mut AppContext) {
|
||||
fn delete_previously_used(&mut self, ix: usize, cx: &mut App) {
|
||||
let Some(candidates) = self.candidates.as_mut() else {
|
||||
return;
|
||||
};
|
||||
|
@ -116,21 +115,23 @@ impl TasksModalDelegate {
|
|||
}
|
||||
|
||||
pub(crate) struct TasksModal {
|
||||
picker: View<Picker<TasksModalDelegate>>,
|
||||
picker: Entity<Picker<TasksModalDelegate>>,
|
||||
_subscription: Subscription,
|
||||
}
|
||||
|
||||
impl TasksModal {
|
||||
pub(crate) fn new(
|
||||
task_store: Model<TaskStore>,
|
||||
task_store: Entity<TaskStore>,
|
||||
task_context: TaskContext,
|
||||
task_overrides: Option<TaskOverrides>,
|
||||
workspace: WeakView<Workspace>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Self {
|
||||
let picker = cx.new_view(|cx| {
|
||||
let picker = cx.new(|cx| {
|
||||
Picker::uniform_list(
|
||||
TasksModalDelegate::new(task_store, task_context, task_overrides, workspace),
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
});
|
||||
|
@ -145,7 +146,11 @@ impl TasksModal {
|
|||
}
|
||||
|
||||
impl Render for TasksModal {
|
||||
fn render(&mut self, _: &mut ViewContext<Self>) -> impl gpui::prelude::IntoElement {
|
||||
fn render(
|
||||
&mut self,
|
||||
_window: &mut Window,
|
||||
_: &mut Context<Self>,
|
||||
) -> impl gpui::prelude::IntoElement {
|
||||
v_flex()
|
||||
.key_context("TasksModal")
|
||||
.w(rems(34.))
|
||||
|
@ -155,8 +160,8 @@ impl Render for TasksModal {
|
|||
|
||||
impl EventEmitter<DismissEvent> for TasksModal {}
|
||||
|
||||
impl FocusableView for TasksModal {
|
||||
fn focus_handle(&self, cx: &gpui::AppContext) -> gpui::FocusHandle {
|
||||
impl Focusable for TasksModal {
|
||||
fn focus_handle(&self, cx: &gpui::App) -> gpui::FocusHandle {
|
||||
self.picker.read(cx).focus_handle(cx)
|
||||
}
|
||||
}
|
||||
|
@ -174,20 +179,26 @@ impl PickerDelegate for TasksModalDelegate {
|
|||
self.selected_index
|
||||
}
|
||||
|
||||
fn set_selected_index(&mut self, ix: usize, _cx: &mut ViewContext<picker::Picker<Self>>) {
|
||||
fn set_selected_index(
|
||||
&mut self,
|
||||
ix: usize,
|
||||
_window: &mut Window,
|
||||
_cx: &mut Context<picker::Picker<Self>>,
|
||||
) {
|
||||
self.selected_index = ix;
|
||||
}
|
||||
|
||||
fn placeholder_text(&self, _: &mut WindowContext) -> Arc<str> {
|
||||
fn placeholder_text(&self, _window: &mut Window, _: &mut App) -> Arc<str> {
|
||||
self.placeholder_text.clone()
|
||||
}
|
||||
|
||||
fn update_matches(
|
||||
&mut self,
|
||||
query: String,
|
||||
cx: &mut ViewContext<picker::Picker<Self>>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<picker::Picker<Self>>,
|
||||
) -> Task<()> {
|
||||
cx.spawn(move |picker, mut cx| async move {
|
||||
cx.spawn_in(window, move |picker, mut cx| async move {
|
||||
let Some(candidates) = picker
|
||||
.update(&mut cx, |picker, cx| {
|
||||
match &mut picker.delegate.candidates {
|
||||
|
@ -271,7 +282,12 @@ impl PickerDelegate for TasksModalDelegate {
|
|||
})
|
||||
}
|
||||
|
||||
fn confirm(&mut self, omit_history_entry: bool, cx: &mut ViewContext<picker::Picker<Self>>) {
|
||||
fn confirm(
|
||||
&mut self,
|
||||
omit_history_entry: bool,
|
||||
_: &mut Window,
|
||||
cx: &mut Context<picker::Picker<Self>>,
|
||||
) {
|
||||
let current_match_index = self.selected_index();
|
||||
let task = self
|
||||
.matches
|
||||
|
@ -302,7 +318,7 @@ impl PickerDelegate for TasksModalDelegate {
|
|||
cx.emit(DismissEvent);
|
||||
}
|
||||
|
||||
fn dismissed(&mut self, cx: &mut ViewContext<picker::Picker<Self>>) {
|
||||
fn dismissed(&mut self, _window: &mut Window, cx: &mut Context<picker::Picker<Self>>) {
|
||||
cx.emit(DismissEvent);
|
||||
}
|
||||
|
||||
|
@ -310,7 +326,8 @@ impl PickerDelegate for TasksModalDelegate {
|
|||
&self,
|
||||
ix: usize,
|
||||
selected: bool,
|
||||
cx: &mut ViewContext<picker::Picker<Self>>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<picker::Picker<Self>>,
|
||||
) -> Option<Self::ListItem> {
|
||||
let candidates = self.candidates.as_ref()?;
|
||||
let hit = &self.matches[ix];
|
||||
|
@ -336,7 +353,7 @@ impl PickerDelegate for TasksModalDelegate {
|
|||
let tooltip_label = if tooltip_label_text.trim().is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(Tooltip::text(tooltip_label_text, cx))
|
||||
Some(Tooltip::simple(tooltip_label_text, cx))
|
||||
};
|
||||
|
||||
let highlighted_location = HighlightedText {
|
||||
|
@ -377,7 +394,7 @@ impl PickerDelegate for TasksModalDelegate {
|
|||
.end_slot::<AnyElement>(history_run_icon)
|
||||
.spacing(ListItemSpacing::Sparse)
|
||||
.when_some(tooltip_label, |list_item, item_label| {
|
||||
list_item.tooltip(move |_| item_label.clone())
|
||||
list_item.tooltip(move |_, _| item_label.clone())
|
||||
})
|
||||
.map(|item| {
|
||||
let item = if matches!(source_kind, TaskSourceKind::UserInput)
|
||||
|
@ -390,9 +407,9 @@ impl PickerDelegate for TasksModalDelegate {
|
|||
.icon_color(Color::Muted)
|
||||
.size(ButtonSize::None)
|
||||
.icon_size(IconSize::XSmall)
|
||||
.on_click(cx.listener(move |picker, _event, cx| {
|
||||
.on_click(cx.listener(move |picker, _event, window, cx| {
|
||||
cx.stop_propagation();
|
||||
cx.prevent_default();
|
||||
window.prevent_default();
|
||||
|
||||
picker.delegate.delete_previously_used(task_index, cx);
|
||||
picker.delegate.last_used_candidate_index = picker
|
||||
|
@ -400,10 +417,10 @@ impl PickerDelegate for TasksModalDelegate {
|
|||
.last_used_candidate_index
|
||||
.unwrap_or(0)
|
||||
.checked_sub(1);
|
||||
picker.refresh(cx);
|
||||
picker.refresh(window, cx);
|
||||
}))
|
||||
.tooltip(|cx| {
|
||||
Tooltip::text("Delete Previously Scheduled Task", cx)
|
||||
.tooltip(|_, cx| {
|
||||
Tooltip::simple("Delete Previously Scheduled Task", cx)
|
||||
}),
|
||||
);
|
||||
item.end_hover_slot(delete_button)
|
||||
|
@ -413,14 +430,15 @@ impl PickerDelegate for TasksModalDelegate {
|
|||
item
|
||||
})
|
||||
.toggle_state(selected)
|
||||
.child(highlighted_location.render(cx)),
|
||||
.child(highlighted_location.render(window, cx)),
|
||||
)
|
||||
}
|
||||
|
||||
fn confirm_completion(
|
||||
&mut self,
|
||||
_: String,
|
||||
_: &mut ViewContext<Picker<Self>>,
|
||||
_window: &mut Window,
|
||||
_: &mut Context<Picker<Self>>,
|
||||
) -> Option<String> {
|
||||
let task_index = self.matches.get(self.selected_index())?.candidate_id;
|
||||
let tasks = self.candidates.as_ref()?;
|
||||
|
@ -428,7 +446,12 @@ impl PickerDelegate for TasksModalDelegate {
|
|||
Some(task.resolved.as_ref()?.command_label.clone())
|
||||
}
|
||||
|
||||
fn confirm_input(&mut self, omit_history_entry: bool, cx: &mut ViewContext<Picker<Self>>) {
|
||||
fn confirm_input(
|
||||
&mut self,
|
||||
omit_history_entry: bool,
|
||||
_: &mut Window,
|
||||
cx: &mut Context<Picker<Self>>,
|
||||
) {
|
||||
let Some((task_source_kind, mut task)) = self.spawn_oneshot() else {
|
||||
return;
|
||||
};
|
||||
|
@ -456,9 +479,13 @@ impl PickerDelegate for TasksModalDelegate {
|
|||
Vec::new()
|
||||
}
|
||||
}
|
||||
fn render_footer(&self, cx: &mut ViewContext<Picker<Self>>) -> Option<gpui::AnyElement> {
|
||||
fn render_footer(
|
||||
&self,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Picker<Self>>,
|
||||
) -> Option<gpui::AnyElement> {
|
||||
let is_recent_selected = self.divider_index >= Some(self.selected_index);
|
||||
let current_modifiers = cx.modifiers();
|
||||
let current_modifiers = window.modifiers();
|
||||
let left_button = if self
|
||||
.task_store
|
||||
.read(cx)
|
||||
|
@ -484,13 +511,13 @@ impl PickerDelegate for TasksModalDelegate {
|
|||
.child(
|
||||
left_button
|
||||
.map(|(label, action)| {
|
||||
let keybind = KeyBinding::for_action(&*action, cx);
|
||||
let keybind = KeyBinding::for_action(&*action, window);
|
||||
|
||||
Button::new("edit-current-task", label)
|
||||
.label_size(LabelSize::Small)
|
||||
.when_some(keybind, |this, keybind| this.key_binding(keybind))
|
||||
.on_click(move |_, cx| {
|
||||
cx.dispatch_action(action.boxed_clone());
|
||||
.on_click(move |_, window, cx| {
|
||||
window.dispatch_action(action.boxed_clone(), cx);
|
||||
})
|
||||
.into_any_element()
|
||||
})
|
||||
|
@ -503,7 +530,7 @@ impl PickerDelegate for TasksModalDelegate {
|
|||
secondary: current_modifiers.secondary(),
|
||||
}
|
||||
.boxed_clone();
|
||||
this.children(KeyBinding::for_action(&*action, cx).map(|keybind| {
|
||||
this.children(KeyBinding::for_action(&*action, window).map(|keybind| {
|
||||
let spawn_oneshot_label = if current_modifiers.secondary() {
|
||||
"Spawn Oneshot Without History"
|
||||
} else {
|
||||
|
@ -513,10 +540,12 @@ impl PickerDelegate for TasksModalDelegate {
|
|||
Button::new("spawn-onehshot", spawn_oneshot_label)
|
||||
.label_size(LabelSize::Small)
|
||||
.key_binding(keybind)
|
||||
.on_click(move |_, cx| cx.dispatch_action(action.boxed_clone()))
|
||||
.on_click(move |_, window, cx| {
|
||||
window.dispatch_action(action.boxed_clone(), cx)
|
||||
})
|
||||
}))
|
||||
} else if current_modifiers.secondary() {
|
||||
this.children(KeyBinding::for_action(&menu::SecondaryConfirm, cx).map(
|
||||
this.children(KeyBinding::for_action(&menu::SecondaryConfirm, window).map(
|
||||
|keybind| {
|
||||
let label = if is_recent_selected {
|
||||
"Rerun Without History"
|
||||
|
@ -526,23 +555,28 @@ impl PickerDelegate for TasksModalDelegate {
|
|||
Button::new("spawn", label)
|
||||
.label_size(LabelSize::Small)
|
||||
.key_binding(keybind)
|
||||
.on_click(move |_, cx| {
|
||||
cx.dispatch_action(menu::SecondaryConfirm.boxed_clone())
|
||||
.on_click(move |_, window, cx| {
|
||||
window.dispatch_action(
|
||||
menu::SecondaryConfirm.boxed_clone(),
|
||||
cx,
|
||||
)
|
||||
})
|
||||
},
|
||||
))
|
||||
} else {
|
||||
this.children(KeyBinding::for_action(&menu::Confirm, cx).map(|keybind| {
|
||||
let run_entry_label =
|
||||
if is_recent_selected { "Rerun" } else { "Spawn" };
|
||||
this.children(KeyBinding::for_action(&menu::Confirm, window).map(
|
||||
|keybind| {
|
||||
let run_entry_label =
|
||||
if is_recent_selected { "Rerun" } else { "Spawn" };
|
||||
|
||||
Button::new("spawn", run_entry_label)
|
||||
.label_size(LabelSize::Small)
|
||||
.key_binding(keybind)
|
||||
.on_click(|_, cx| {
|
||||
cx.dispatch_action(menu::Confirm.boxed_clone());
|
||||
})
|
||||
}))
|
||||
Button::new("spawn", run_entry_label)
|
||||
.label_size(LabelSize::Small)
|
||||
.key_binding(keybind)
|
||||
.on_click(|_, window, cx| {
|
||||
window.dispatch_action(menu::Confirm.boxed_clone(), cx);
|
||||
})
|
||||
},
|
||||
))
|
||||
}
|
||||
})
|
||||
.into_any_element(),
|
||||
|
@ -602,7 +636,8 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(fs, ["/dir".as_ref()], cx).await;
|
||||
let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project, cx));
|
||||
let (workspace, cx) =
|
||||
cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
|
||||
|
||||
let tasks_picker = open_spawn_tasks(&workspace, cx);
|
||||
assert_eq!(
|
||||
|
@ -618,8 +653,8 @@ mod tests {
|
|||
drop(tasks_picker);
|
||||
|
||||
let _ = workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
workspace.open_abs_path(PathBuf::from("/dir/a.ts"), true, cx)
|
||||
.update_in(cx, |workspace, window, cx| {
|
||||
workspace.open_abs_path(PathBuf::from("/dir/a.ts"), true, window, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -766,7 +801,8 @@ mod tests {
|
|||
.await;
|
||||
|
||||
let project = Project::test(fs, ["/dir".as_ref()], cx).await;
|
||||
let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let (workspace, cx) =
|
||||
cx.add_window_view(|window, cx| Workspace::test_new(project.clone(), window, cx));
|
||||
|
||||
let tasks_picker = open_spawn_tasks(&workspace, cx);
|
||||
assert_eq!(
|
||||
|
@ -781,8 +817,13 @@ mod tests {
|
|||
cx.executor().run_until_parked();
|
||||
|
||||
let _ = workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
workspace.open_abs_path(PathBuf::from("/dir/file_with.odd_extension"), true, cx)
|
||||
.update_in(cx, |workspace, window, cx| {
|
||||
workspace.open_abs_path(
|
||||
PathBuf::from("/dir/file_with.odd_extension"),
|
||||
true,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -803,15 +844,22 @@ mod tests {
|
|||
cx.executor().run_until_parked();
|
||||
|
||||
let second_item = workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
workspace.open_abs_path(PathBuf::from("/dir/file_without_extension"), true, cx)
|
||||
.update_in(cx, |workspace, window, cx| {
|
||||
workspace.open_abs_path(
|
||||
PathBuf::from("/dir/file_without_extension"),
|
||||
true,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let editor = cx.update(|cx| second_item.act_as::<Editor>(cx)).unwrap();
|
||||
editor.update(cx, |editor, cx| {
|
||||
editor.change_selections(None, cx, |s| {
|
||||
let editor = cx
|
||||
.update(|_window, cx| second_item.act_as::<Editor>(cx))
|
||||
.unwrap();
|
||||
editor.update_in(cx, |editor, window, cx| {
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
s.select_ranges(Some(Point::new(1, 2)..Point::new(1, 5)))
|
||||
})
|
||||
});
|
||||
|
@ -902,11 +950,12 @@ mod tests {
|
|||
))),
|
||||
));
|
||||
});
|
||||
let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let (workspace, cx) =
|
||||
cx.add_window_view(|window, cx| Workspace::test_new(project.clone(), window, cx));
|
||||
|
||||
let _ts_file_1 = workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
workspace.open_abs_path(PathBuf::from("/dir/a1.ts"), true, cx)
|
||||
.update_in(cx, |workspace, window, cx| {
|
||||
workspace.open_abs_path(PathBuf::from("/dir/a1.ts"), true, window, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -941,8 +990,8 @@ mod tests {
|
|||
cx.executor().run_until_parked();
|
||||
|
||||
let _ts_file_2 = workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
workspace.open_abs_path(PathBuf::from("/dir/a2.ts"), true, cx)
|
||||
.update_in(cx, |workspace, window, cx| {
|
||||
workspace.open_abs_path(PathBuf::from("/dir/a2.ts"), true, window, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -964,8 +1013,8 @@ mod tests {
|
|||
cx.executor().run_until_parked();
|
||||
|
||||
let _rs_file = workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
workspace.open_abs_path(PathBuf::from("/dir/b.rs"), true, cx)
|
||||
.update_in(cx, |workspace, window, cx| {
|
||||
workspace.open_abs_path(PathBuf::from("/dir/b.rs"), true, window, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -979,8 +1028,8 @@ mod tests {
|
|||
cx.dispatch_action(CloseInactiveTabsAndPanes::default());
|
||||
emulate_task_schedule(tasks_picker, &project, "Rust task", cx);
|
||||
let _ts_file_2 = workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
workspace.open_abs_path(PathBuf::from("/dir/a2.ts"), true, cx)
|
||||
.update_in(cx, |workspace, window, cx| {
|
||||
workspace.open_abs_path(PathBuf::from("/dir/a2.ts"), true, window, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -999,8 +1048,8 @@ mod tests {
|
|||
}
|
||||
|
||||
fn emulate_task_schedule(
|
||||
tasks_picker: View<Picker<TasksModalDelegate>>,
|
||||
project: &Model<Project>,
|
||||
tasks_picker: Entity<Picker<TasksModalDelegate>>,
|
||||
project: &Entity<Project>,
|
||||
scheduled_task_label: &str,
|
||||
cx: &mut VisualTestContext,
|
||||
) {
|
||||
|
@ -1030,9 +1079,9 @@ mod tests {
|
|||
}
|
||||
|
||||
fn open_spawn_tasks(
|
||||
workspace: &View<Workspace>,
|
||||
workspace: &Entity<Workspace>,
|
||||
cx: &mut VisualTestContext,
|
||||
) -> View<Picker<TasksModalDelegate>> {
|
||||
) -> Entity<Picker<TasksModalDelegate>> {
|
||||
cx.dispatch_action(Spawn::modal());
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
workspace
|
||||
|
@ -1044,12 +1093,15 @@ mod tests {
|
|||
})
|
||||
}
|
||||
|
||||
fn query(spawn_tasks: &View<Picker<TasksModalDelegate>>, cx: &mut VisualTestContext) -> String {
|
||||
fn query(
|
||||
spawn_tasks: &Entity<Picker<TasksModalDelegate>>,
|
||||
cx: &mut VisualTestContext,
|
||||
) -> String {
|
||||
spawn_tasks.update(cx, |spawn_tasks, cx| spawn_tasks.query(cx))
|
||||
}
|
||||
|
||||
fn task_names(
|
||||
spawn_tasks: &View<Picker<TasksModalDelegate>>,
|
||||
spawn_tasks: &Entity<Picker<TasksModalDelegate>>,
|
||||
cx: &mut VisualTestContext,
|
||||
) -> Vec<String> {
|
||||
spawn_tasks.update(cx, |spawn_tasks, _| {
|
||||
|
|
|
@ -19,10 +19,7 @@ impl Settings for TaskSettings {
|
|||
|
||||
type FileContent = TaskSettingsContent;
|
||||
|
||||
fn load(
|
||||
sources: SettingsSources<Self::FileContent>,
|
||||
_: &mut gpui::AppContext,
|
||||
) -> gpui::Result<Self> {
|
||||
fn load(sources: SettingsSources<Self::FileContent>, _: &mut gpui::App) -> gpui::Result<Self> {
|
||||
sources.json_merge()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ::settings::Settings;
|
||||
use editor::{tasks::task_context, Editor};
|
||||
use gpui::{AppContext, Task as AsyncTask, ViewContext, WindowContext};
|
||||
use gpui::{App, Context, Task as AsyncTask, Window};
|
||||
use modal::{TaskOverrides, TasksModal};
|
||||
use project::{Location, WorktreeId};
|
||||
use task::{RevealTarget, TaskId};
|
||||
|
@ -12,13 +12,13 @@ mod settings;
|
|||
|
||||
pub use modal::{Rerun, Spawn};
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
pub fn init(cx: &mut App) {
|
||||
settings::TaskSettings::register(cx);
|
||||
cx.observe_new_views(
|
||||
|workspace: &mut Workspace, _: &mut ViewContext<Workspace>| {
|
||||
cx.observe_new(
|
||||
|workspace: &mut Workspace, _window: Option<&mut Window>, _: &mut Context<Workspace>| {
|
||||
workspace
|
||||
.register_action(spawn_task_or_modal)
|
||||
.register_action(move |workspace, action: &modal::Rerun, cx| {
|
||||
.register_action(move |workspace, action: &modal::Rerun, window, cx| {
|
||||
if let Some((task_source_kind, mut last_scheduled_task)) = workspace
|
||||
.project()
|
||||
.read(cx)
|
||||
|
@ -43,8 +43,8 @@ pub fn init(cx: &mut AppContext) {
|
|||
if let Some(use_new_terminal) = action.use_new_terminal {
|
||||
original_task.use_new_terminal = use_new_terminal;
|
||||
}
|
||||
let context_task = task_context(workspace, cx);
|
||||
cx.spawn(|workspace, mut cx| async move {
|
||||
let context_task = task_context(workspace, window, cx);
|
||||
cx.spawn_in(window, |workspace, mut cx| async move {
|
||||
let task_context = context_task.await;
|
||||
workspace
|
||||
.update(&mut cx, |workspace, cx| {
|
||||
|
@ -79,7 +79,7 @@ pub fn init(cx: &mut AppContext) {
|
|||
);
|
||||
}
|
||||
} else {
|
||||
toggle_modal(workspace, None, cx).detach();
|
||||
toggle_modal(workspace, None, window, cx).detach();
|
||||
};
|
||||
});
|
||||
},
|
||||
|
@ -87,7 +87,12 @@ pub fn init(cx: &mut AppContext) {
|
|||
.detach();
|
||||
}
|
||||
|
||||
fn spawn_task_or_modal(workspace: &mut Workspace, action: &Spawn, cx: &mut ViewContext<Workspace>) {
|
||||
fn spawn_task_or_modal(
|
||||
workspace: &mut Workspace,
|
||||
action: &Spawn,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Workspace>,
|
||||
) {
|
||||
match action {
|
||||
Spawn::ByName {
|
||||
task_name,
|
||||
|
@ -96,16 +101,19 @@ fn spawn_task_or_modal(workspace: &mut Workspace, action: &Spawn, cx: &mut ViewC
|
|||
let overrides = reveal_target.map(|reveal_target| TaskOverrides {
|
||||
reveal_target: Some(reveal_target),
|
||||
});
|
||||
spawn_task_with_name(task_name.clone(), overrides, cx).detach_and_log_err(cx)
|
||||
spawn_task_with_name(task_name.clone(), overrides, window, cx).detach_and_log_err(cx)
|
||||
}
|
||||
Spawn::ViaModal { reveal_target } => {
|
||||
toggle_modal(workspace, *reveal_target, window, cx).detach()
|
||||
}
|
||||
Spawn::ViaModal { reveal_target } => toggle_modal(workspace, *reveal_target, cx).detach(),
|
||||
}
|
||||
}
|
||||
|
||||
fn toggle_modal(
|
||||
workspace: &mut Workspace,
|
||||
reveal_target: Option<RevealTarget>,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Workspace>,
|
||||
) -> AsyncTask<()> {
|
||||
let task_store = workspace.project().read(cx).task_store().clone();
|
||||
let workspace_handle = workspace.weak_handle();
|
||||
|
@ -113,12 +121,12 @@ fn toggle_modal(
|
|||
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 context_task = task_context(workspace, window, cx);
|
||||
cx.spawn_in(window, |workspace, mut cx| async move {
|
||||
let task_context = context_task.await;
|
||||
workspace
|
||||
.update(&mut cx, |workspace, cx| {
|
||||
workspace.toggle_modal(cx, |cx| {
|
||||
.update_in(&mut cx, |workspace, window, cx| {
|
||||
workspace.toggle_modal(window, cx, |window, cx| {
|
||||
TasksModal::new(
|
||||
task_store.clone(),
|
||||
task_context,
|
||||
|
@ -126,6 +134,7 @@ fn toggle_modal(
|
|||
reveal_target: Some(target),
|
||||
}),
|
||||
workspace_handle,
|
||||
window,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
|
@ -140,11 +149,13 @@ fn toggle_modal(
|
|||
fn spawn_task_with_name(
|
||||
name: String,
|
||||
overrides: Option<TaskOverrides>,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Workspace>,
|
||||
) -> AsyncTask<anyhow::Result<()>> {
|
||||
cx.spawn(|workspace, mut cx| async move {
|
||||
let context_task =
|
||||
workspace.update(&mut cx, |workspace, cx| task_context(workspace, cx))?;
|
||||
cx.spawn_in(window, |workspace, mut cx| async move {
|
||||
let context_task = workspace.update_in(&mut cx, |workspace, window, cx| {
|
||||
task_context(workspace, window, cx)
|
||||
})?;
|
||||
let task_context = context_task.await;
|
||||
let tasks = workspace.update(&mut cx, |workspace, cx| {
|
||||
let Some(task_inventory) = workspace
|
||||
|
@ -194,12 +205,13 @@ fn spawn_task_with_name(
|
|||
.is_some();
|
||||
if !did_spawn {
|
||||
workspace
|
||||
.update(&mut cx, |workspace, cx| {
|
||||
.update_in(&mut cx, |workspace, window, cx| {
|
||||
spawn_task_or_modal(
|
||||
workspace,
|
||||
&Spawn::ViaModal {
|
||||
reveal_target: overrides.and_then(|overrides| overrides.reveal_target),
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
|
@ -212,7 +224,7 @@ fn spawn_task_with_name(
|
|||
|
||||
fn active_item_selection_properties(
|
||||
workspace: &Workspace,
|
||||
cx: &mut WindowContext,
|
||||
cx: &mut App,
|
||||
) -> (Option<WorktreeId>, Option<Location>) {
|
||||
let active_item = workspace.active_item(cx);
|
||||
let worktree_id = active_item
|
||||
|
@ -244,7 +256,7 @@ mod tests {
|
|||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
use editor::Editor;
|
||||
use gpui::{Entity, TestAppContext};
|
||||
use gpui::TestAppContext;
|
||||
use language::{Language, LanguageConfig};
|
||||
use project::{task_store::TaskStore, BasicContextProvider, FakeFs, Project};
|
||||
use serde_json::json;
|
||||
|
@ -324,7 +336,8 @@ mod tests {
|
|||
let worktree_id = project.update(cx, |project, cx| {
|
||||
project.worktrees(cx).next().unwrap().read(cx).id()
|
||||
});
|
||||
let (workspace, cx) = cx.add_window_view(|cx| Workspace::test_new(project.clone(), cx));
|
||||
let (workspace, cx) =
|
||||
cx.add_window_view(|window, cx| Workspace::test_new(project.clone(), window, cx));
|
||||
|
||||
let buffer1 = workspace
|
||||
.update(cx, |this, cx| {
|
||||
|
@ -336,7 +349,9 @@ mod tests {
|
|||
buffer1.update(cx, |this, cx| {
|
||||
this.set_language(Some(typescript_language), cx)
|
||||
});
|
||||
let editor1 = cx.new_view(|cx| Editor::for_buffer(buffer1, Some(project.clone()), cx));
|
||||
let editor1 = cx.new_window_model(|window, cx| {
|
||||
Editor::for_buffer(buffer1, Some(project.clone()), window, cx)
|
||||
});
|
||||
let buffer2 = workspace
|
||||
.update(cx, |this, cx| {
|
||||
this.project().update(cx, |this, cx| {
|
||||
|
@ -346,17 +361,18 @@ mod tests {
|
|||
.await
|
||||
.unwrap();
|
||||
buffer2.update(cx, |this, cx| this.set_language(Some(rust_language), cx));
|
||||
let editor2 = cx.new_view(|cx| Editor::for_buffer(buffer2, Some(project), cx));
|
||||
let editor2 = cx
|
||||
.new_window_model(|window, cx| Editor::for_buffer(buffer2, Some(project), window, cx));
|
||||
|
||||
let first_context = workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
workspace.add_item_to_center(Box::new(editor1.clone()), cx);
|
||||
workspace.add_item_to_center(Box::new(editor2.clone()), cx);
|
||||
.update_in(cx, |workspace, window, cx| {
|
||||
workspace.add_item_to_center(Box::new(editor1.clone()), window, cx);
|
||||
workspace.add_item_to_center(Box::new(editor2.clone()), window, cx);
|
||||
assert_eq!(
|
||||
workspace.active_item(cx).unwrap().item_id(),
|
||||
editor2.entity_id()
|
||||
);
|
||||
task_context(workspace, cx)
|
||||
task_context(workspace, window, cx)
|
||||
})
|
||||
.await;
|
||||
assert_eq!(
|
||||
|
@ -378,13 +394,17 @@ mod tests {
|
|||
);
|
||||
|
||||
// And now, let's select an identifier.
|
||||
editor2.update(cx, |editor, cx| {
|
||||
editor.change_selections(None, cx, |selections| selections.select_ranges([14..18]))
|
||||
editor2.update_in(cx, |editor, window, cx| {
|
||||
editor.change_selections(None, window, cx, |selections| {
|
||||
selections.select_ranges([14..18])
|
||||
})
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
workspace
|
||||
.update(cx, |workspace, cx| { task_context(workspace, cx) })
|
||||
.update_in(cx, |workspace, window, cx| {
|
||||
task_context(workspace, window, cx)
|
||||
})
|
||||
.await,
|
||||
TaskContext {
|
||||
cwd: Some("/dir".into()),
|
||||
|
@ -406,10 +426,10 @@ mod tests {
|
|||
|
||||
assert_eq!(
|
||||
workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
.update_in(cx, |workspace, window, cx| {
|
||||
// Now, let's switch the active item to .ts file.
|
||||
workspace.activate_item(&editor1, true, true, cx);
|
||||
task_context(workspace, cx)
|
||||
workspace.activate_item(&editor1, true, true, window, cx);
|
||||
task_context(workspace, window, cx)
|
||||
})
|
||||
.await,
|
||||
TaskContext {
|
Loading…
Add table
Add a link
Reference in a new issue