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:
Nathan Sobo 2025-01-25 20:02:45 -07:00 committed by GitHub
parent 21b4a0d50e
commit 6fca1d2b0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
648 changed files with 36248 additions and 28208 deletions

View file

@ -29,7 +29,7 @@ impl ParentElement for ExtensionCard {
}
impl RenderOnce for ExtensionCard {
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
div().w_full().child(
v_flex()
.w_full()

View file

@ -44,7 +44,7 @@ impl FeatureUpsell {
}
impl RenderOnce for FeatureUpsell {
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
self.base
.p_4()
.justify_between()
@ -63,7 +63,7 @@ impl RenderOnce for FeatureUpsell {
)
.on_click({
let docs_url = docs_url.clone();
move |_event, cx| {
move |_event, _window, cx| {
telemetry::event!(
"Documentation Viewed",
source = "Feature Upsell",

View file

@ -5,13 +5,10 @@ use std::sync::{Arc, OnceLock};
use db::kvp::KEY_VALUE_STORE;
use editor::Editor;
use extension_host::ExtensionStore;
use gpui::{Model, VisualContext};
use gpui::{AppContext as _, Context, Entity, SharedString, Window};
use language::Buffer;
use ui::{SharedString, ViewContext};
use workspace::{
notifications::{simple_message_notification, NotificationId},
Workspace,
};
use workspace::notifications::simple_message_notification::MessageNotification;
use workspace::{notifications::NotificationId, Workspace};
const SUGGESTIONS_BY_EXTENSION_ID: &[(&str, &[&str])] = &[
("astro", &["astro"]),
@ -136,7 +133,7 @@ fn language_extension_key(extension_id: &str) -> String {
format!("{}_extension_suggest", extension_id)
}
pub(crate) fn suggest(buffer: Model<Buffer>, cx: &mut ViewContext<Workspace>) {
pub(crate) fn suggest(buffer: Entity<Buffer>, window: &mut Window, cx: &mut Context<Workspace>) {
let Some(file) = buffer.read(cx).file().cloned() else {
return;
};
@ -154,7 +151,7 @@ pub(crate) fn suggest(buffer: Model<Buffer>, cx: &mut ViewContext<Workspace>) {
return;
};
cx.on_next_frame(move |workspace, cx| {
cx.on_next_frame(window, move |workspace, _, cx| {
let Some(editor) = workspace.active_item_as::<Editor>(cx) else {
return;
};
@ -170,15 +167,15 @@ pub(crate) fn suggest(buffer: Model<Buffer>, cx: &mut ViewContext<Workspace>) {
);
workspace.show_notification(notification_id, cx, |cx| {
cx.new_view(move |_cx| {
simple_message_notification::MessageNotification::new(format!(
cx.new(move |_cx| {
MessageNotification::new(format!(
"Do you want to install the recommended '{}' extension for '{}' files?",
extension_id, file_name_or_extension
))
.with_click_message("Yes, install extension")
.on_click({
let extension_id = extension_id.clone();
move |cx| {
move |_window, cx| {
let extension_id = extension_id.clone();
let extension_store = ExtensionStore::global(cx);
extension_store.update(cx, move |store, cx| {
@ -187,7 +184,7 @@ pub(crate) fn suggest(buffer: Model<Buffer>, cx: &mut ViewContext<Workspace>) {
}
})
.with_secondary_click_message("No, don't install it")
.on_secondary_click(move |cx| {
.on_secondary_click(move |_window, cx| {
let key = language_extension_key(&extension_id);
db::write_and_log(cx, move || {
KEY_VALUE_STORE.write_kvp(key, "dismissed".to_string())

View file

@ -5,9 +5,7 @@ use client::ExtensionMetadata;
use extension_host::{ExtensionSettings, ExtensionStore};
use fs::Fs;
use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
use gpui::{
prelude::*, AppContext, DismissEvent, EventEmitter, FocusableView, Task, View, WeakView,
};
use gpui::{prelude::*, App, DismissEvent, Entity, EventEmitter, Focusable, Task, WeakEntity};
use picker::{Picker, PickerDelegate};
use release_channel::ReleaseChannel;
use semantic_version::SemanticVersion;
@ -17,35 +15,39 @@ use util::ResultExt;
use workspace::ModalView;
pub struct ExtensionVersionSelector {
picker: View<Picker<ExtensionVersionSelectorDelegate>>,
picker: Entity<Picker<ExtensionVersionSelectorDelegate>>,
}
impl ModalView for ExtensionVersionSelector {}
impl EventEmitter<DismissEvent> for ExtensionVersionSelector {}
impl FocusableView for ExtensionVersionSelector {
fn focus_handle(&self, cx: &AppContext) -> gpui::FocusHandle {
impl Focusable for ExtensionVersionSelector {
fn focus_handle(&self, cx: &App) -> gpui::FocusHandle {
self.picker.focus_handle(cx)
}
}
impl Render for ExtensionVersionSelector {
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
v_flex().w(rems(34.)).child(self.picker.clone())
}
}
impl ExtensionVersionSelector {
pub fn new(delegate: ExtensionVersionSelectorDelegate, cx: &mut ViewContext<Self>) -> Self {
let picker = cx.new_view(|cx| Picker::uniform_list(delegate, cx));
pub fn new(
delegate: ExtensionVersionSelectorDelegate,
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
let picker = cx.new(|cx| Picker::uniform_list(delegate, window, cx));
Self { picker }
}
}
pub struct ExtensionVersionSelectorDelegate {
fs: Arc<dyn Fs>,
view: WeakView<ExtensionVersionSelector>,
selector: WeakEntity<ExtensionVersionSelector>,
extension_versions: Vec<ExtensionMetadata>,
selected_index: usize,
matches: Vec<StringMatch>,
@ -54,7 +56,7 @@ pub struct ExtensionVersionSelectorDelegate {
impl ExtensionVersionSelectorDelegate {
pub fn new(
fs: Arc<dyn Fs>,
weak_view: WeakView<ExtensionVersionSelector>,
selector: WeakEntity<ExtensionVersionSelector>,
mut extension_versions: Vec<ExtensionMetadata>,
) -> Self {
extension_versions.sort_unstable_by(|a, b| {
@ -79,7 +81,7 @@ impl ExtensionVersionSelectorDelegate {
Self {
fs,
view: weak_view,
selector,
extension_versions,
selected_index: 0,
matches,
@ -90,7 +92,7 @@ impl ExtensionVersionSelectorDelegate {
impl PickerDelegate for ExtensionVersionSelectorDelegate {
type ListItem = ui::ListItem;
fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {
fn placeholder_text(&self, _window: &mut Window, _cx: &mut App) -> Arc<str> {
"Select extension version...".into()
}
@ -102,11 +104,21 @@ impl PickerDelegate for ExtensionVersionSelectorDelegate {
self.selected_index
}
fn set_selected_index(&mut self, ix: usize, _cx: &mut ViewContext<Picker<Self>>) {
fn set_selected_index(
&mut self,
ix: usize,
_window: &mut Window,
_cx: &mut Context<Picker<Self>>,
) {
self.selected_index = ix;
}
fn update_matches(&mut self, query: String, cx: &mut ViewContext<Picker<Self>>) -> Task<()> {
fn update_matches(
&mut self,
query: String,
window: &mut Window,
cx: &mut Context<Picker<Self>>,
) -> Task<()> {
let background_executor = cx.background_executor().clone();
let candidates = self
.extension_versions
@ -117,7 +129,7 @@ impl PickerDelegate for ExtensionVersionSelectorDelegate {
})
.collect::<Vec<_>>();
cx.spawn(move |this, mut cx| async move {
cx.spawn_in(window, move |this, mut cx| async move {
let matches = if query.is_empty() {
candidates
.into_iter()
@ -152,9 +164,9 @@ impl PickerDelegate for ExtensionVersionSelectorDelegate {
})
}
fn confirm(&mut self, _secondary: bool, cx: &mut ViewContext<Picker<Self>>) {
fn confirm(&mut self, _secondary: bool, window: &mut Window, cx: &mut Context<Picker<Self>>) {
if self.matches.is_empty() {
self.dismissed(cx);
self.dismissed(window, cx);
return;
}
@ -181,8 +193,8 @@ impl PickerDelegate for ExtensionVersionSelectorDelegate {
});
}
fn dismissed(&mut self, cx: &mut ViewContext<Picker<Self>>) {
self.view
fn dismissed(&mut self, _: &mut Window, cx: &mut Context<Picker<Self>>) {
self.selector
.update(cx, |_, cx| cx.emit(DismissEvent))
.log_err();
}
@ -191,7 +203,8 @@ impl PickerDelegate for ExtensionVersionSelectorDelegate {
&self,
ix: usize,
selected: bool,
cx: &mut ViewContext<Picker<Self>>,
_: &mut Window,
cx: &mut Context<Picker<Self>>,
) -> Option<Self::ListItem> {
let version_match = &self.matches[ix];
let extension_version = &self.extension_versions[version_match.candidate_id];

View file

@ -2,7 +2,6 @@ mod components;
mod extension_suggest;
mod extension_version_selector;
use std::ops::DerefMut;
use std::sync::OnceLock;
use std::time::Duration;
use std::{ops::Range, sync::Arc};
@ -13,9 +12,9 @@ use editor::{Editor, EditorElement, EditorStyle};
use extension_host::{ExtensionManifest, ExtensionOperation, ExtensionStore};
use fuzzy::{match_strings, StringMatchCandidate};
use gpui::{
actions, uniform_list, Action, AppContext, ClipboardItem, EventEmitter, Flatten, FocusableView,
InteractiveElement, KeyContext, ParentElement, Render, Styled, Task, TextStyle,
UniformListScrollHandle, View, ViewContext, VisualContext, WeakView, WindowContext,
actions, uniform_list, Action, App, ClipboardItem, Context, Entity, EventEmitter, Flatten,
Focusable, InteractiveElement, KeyContext, ParentElement, Render, Styled, Task, TextStyle,
UniformListScrollHandle, WeakEntity, Window,
};
use num_format::{Locale, ToFormattedString};
use project::DirectoryLister;
@ -36,10 +35,13 @@ use crate::extension_version_selector::{
actions!(zed, [InstallDevExtension]);
pub fn init(cx: &mut AppContext) {
cx.observe_new_views(move |workspace: &mut Workspace, cx| {
pub fn init(cx: &mut App) {
cx.observe_new(move |workspace: &mut Workspace, window, cx| {
let Some(window) = window else {
return;
};
workspace
.register_action(move |workspace, _: &zed_actions::Extensions, cx| {
.register_action(move |workspace, _: &zed_actions::Extensions, window, cx| {
let existing = workspace
.active_pane()
.read(cx)
@ -47,13 +49,19 @@ pub fn init(cx: &mut AppContext) {
.find_map(|item| item.downcast::<ExtensionsPage>());
if let Some(existing) = existing {
workspace.activate_item(&existing, true, true, cx);
workspace.activate_item(&existing, true, true, window, cx);
} else {
let extensions_page = ExtensionsPage::new(workspace, cx);
workspace.add_item_to_active_pane(Box::new(extensions_page), None, true, cx)
let extensions_page = ExtensionsPage::new(workspace, window, cx);
workspace.add_item_to_active_pane(
Box::new(extensions_page),
None,
true,
window,
cx,
)
}
})
.register_action(move |workspace, _: &InstallDevExtension, cx| {
.register_action(move |workspace, _: &InstallDevExtension, window, cx| {
let store = ExtensionStore::global(cx);
let prompt = workspace.prompt_for_open_path(
gpui::PathPromptOptions {
@ -62,12 +70,13 @@ pub fn init(cx: &mut AppContext) {
multiple: false,
},
DirectoryLister::Local(workspace.app_state().fs.clone()),
window,
cx,
);
let workspace_handle = cx.view().downgrade();
cx.deref_mut()
.spawn(|mut cx| async move {
let workspace_handle = cx.model().downgrade();
window
.spawn(cx, |mut cx| async move {
let extension_path =
match Flatten::flatten(prompt.await.map_err(|e| e.into())) {
Ok(Some(mut paths)) => paths.pop()?,
@ -107,9 +116,9 @@ pub fn init(cx: &mut AppContext) {
.detach();
});
cx.subscribe(workspace.project(), |_, _, event, cx| {
cx.subscribe_in(workspace.project(), window, |_, _, event, window, cx| {
if let project::Event::LanguageNotFound(buffer) = event {
extension_suggest::suggest(buffer.clone(), cx);
extension_suggest::suggest(buffer.clone(), window, cx);
}
})
.detach();
@ -192,14 +201,14 @@ fn keywords_by_feature() -> &'static BTreeMap<Feature, Vec<&'static str>> {
}
pub struct ExtensionsPage {
workspace: WeakView<Workspace>,
workspace: WeakEntity<Workspace>,
list: UniformListScrollHandle,
is_fetching_extensions: bool,
filter: ExtensionFilter,
remote_extension_entries: Vec<ExtensionMetadata>,
dev_extension_entries: Vec<Arc<ExtensionManifest>>,
filtered_remote_extension_indices: Vec<usize>,
query_editor: View<Editor>,
query_editor: Entity<Editor>,
query_contains_error: bool,
_subscriptions: [gpui::Subscription; 2],
extension_fetch_task: Option<Task<()>>,
@ -207,23 +216,37 @@ pub struct ExtensionsPage {
}
impl ExtensionsPage {
pub fn new(workspace: &Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> {
cx.new_view(|cx: &mut ViewContext<Self>| {
pub fn new(
workspace: &Workspace,
window: &mut Window,
cx: &mut Context<Workspace>,
) -> Entity<Self> {
cx.new(|cx| {
let store = ExtensionStore::global(cx);
let workspace_handle = workspace.weak_handle();
let subscriptions = [
cx.observe(&store, |_, _, cx| cx.notify()),
cx.subscribe(&store, move |this, _, event, cx| match event {
extension_host::Event::ExtensionsUpdated => this.fetch_extensions_debounced(cx),
extension_host::Event::ExtensionInstalled(extension_id) => {
this.on_extension_installed(workspace_handle.clone(), extension_id, cx)
}
_ => {}
}),
cx.observe(&store, |_: &mut Self, _, cx| cx.notify()),
cx.subscribe_in(
&store,
window,
move |this, _, event, window, cx| match event {
extension_host::Event::ExtensionsUpdated => {
this.fetch_extensions_debounced(cx)
}
extension_host::Event::ExtensionInstalled(extension_id) => this
.on_extension_installed(
workspace_handle.clone(),
extension_id,
window,
cx,
),
_ => {}
},
),
];
let query_editor = cx.new_view(|cx| {
let mut input = Editor::single_line(cx);
let query_editor = cx.new(|cx| {
let mut input = Editor::single_line(window, cx);
input.set_placeholder_text("Search extensions...", cx);
input
});
@ -250,9 +273,10 @@ impl ExtensionsPage {
fn on_extension_installed(
&mut self,
workspace: WeakView<Workspace>,
workspace: WeakEntity<Workspace>,
extension_id: &str,
cx: &mut ViewContext<Self>,
window: &mut Window,
cx: &mut Context<Self>,
) {
let extension_store = ExtensionStore::global(cx).read(cx);
let themes = extension_store
@ -262,11 +286,12 @@ impl ExtensionsPage {
if !themes.is_empty() {
workspace
.update(cx, |_workspace, cx| {
cx.dispatch_action(
window.dispatch_action(
zed_actions::theme_selector::Toggle {
themes_filter: Some(themes),
}
.boxed_clone(),
cx,
);
})
.ok();
@ -274,7 +299,7 @@ impl ExtensionsPage {
}
/// Returns whether a dev extension currently exists for the extension with the given ID.
fn dev_extension_exists(extension_id: &str, cx: &mut ViewContext<Self>) -> bool {
fn dev_extension_exists(extension_id: &str, cx: &mut Context<Self>) -> bool {
let extension_store = ExtensionStore::global(cx).read(cx);
extension_store
@ -282,7 +307,7 @@ impl ExtensionsPage {
.any(|dev_extension| dev_extension.id.as_ref() == extension_id)
}
fn extension_status(extension_id: &str, cx: &mut ViewContext<Self>) -> ExtensionStatus {
fn extension_status(extension_id: &str, cx: &mut Context<Self>) -> ExtensionStatus {
let extension_store = ExtensionStore::global(cx).read(cx);
match extension_store.outstanding_operations().get(extension_id) {
@ -296,7 +321,7 @@ impl ExtensionsPage {
}
}
fn filter_extension_entries(&mut self, cx: &mut ViewContext<Self>) {
fn filter_extension_entries(&mut self, cx: &mut Context<Self>) {
self.filtered_remote_extension_indices.clear();
self.filtered_remote_extension_indices.extend(
self.remote_extension_entries
@ -319,7 +344,7 @@ impl ExtensionsPage {
cx.notify();
}
fn fetch_extensions(&mut self, search: Option<String>, cx: &mut ViewContext<Self>) {
fn fetch_extensions(&mut self, search: Option<String>, cx: &mut Context<Self>) {
self.is_fetching_extensions = true;
cx.notify();
@ -374,7 +399,8 @@ impl ExtensionsPage {
fn render_extensions(
&mut self,
range: Range<usize>,
cx: &mut ViewContext<Self>,
_: &mut Window,
cx: &mut Context<Self>,
) -> Vec<ExtensionCard> {
let dev_extension_entries_len = if self.filter.include_dev_extensions() {
self.dev_extension_entries.len()
@ -399,7 +425,7 @@ impl ExtensionsPage {
fn render_dev_extension(
&self,
extension: &ExtensionManifest,
cx: &mut ViewContext<Self>,
cx: &mut Context<Self>,
) -> ExtensionCard {
let status = Self::extension_status(&extension.id, cx);
@ -430,7 +456,7 @@ impl ExtensionsPage {
)
.on_click({
let extension_id = extension.id.clone();
move |_, cx| {
move |_, _, cx| {
ExtensionStore::global(cx).update(cx, |store, cx| {
store.rebuild_dev_extension(extension_id.clone(), cx)
});
@ -443,7 +469,7 @@ impl ExtensionsPage {
Button::new(SharedString::from(extension.id.clone()), "Uninstall")
.on_click({
let extension_id = extension.id.clone();
move |_, cx| {
move |_, _, cx| {
ExtensionStore::global(cx).update(cx, |store, cx| {
store.uninstall_extension(extension_id.clone(), cx)
});
@ -493,11 +519,11 @@ impl ExtensionsPage {
.style(ButtonStyle::Filled)
.on_click(cx.listener({
let repository_url = repository_url.clone();
move |_, _, cx| {
move |_, _, _, cx| {
cx.open_url(&repository_url);
}
}))
.tooltip(move |cx| Tooltip::text(repository_url.clone(), cx))
.tooltip(Tooltip::text(repository_url.clone()))
})),
)
}
@ -505,9 +531,9 @@ impl ExtensionsPage {
fn render_remote_extension(
&self,
extension: &ExtensionMetadata,
cx: &mut ViewContext<Self>,
cx: &mut Context<Self>,
) -> ExtensionCard {
let this = cx.view().clone();
let this = cx.model().clone();
let status = Self::extension_status(&extension.id, cx);
let has_dev_extension = Self::dev_extension_exists(&extension.id, cx);
@ -601,11 +627,11 @@ impl ExtensionsPage {
.style(ButtonStyle::Filled)
.on_click(cx.listener({
let repository_url = repository_url.clone();
move |_, _, cx| {
move |_, _, _, cx| {
cx.open_url(&repository_url);
}
}))
.tooltip(move |cx| Tooltip::text(repository_url.clone(), cx)),
.tooltip(Tooltip::text(repository_url.clone())),
)
.child(
PopoverMenu::new(SharedString::from(format!(
@ -621,10 +647,11 @@ impl ExtensionsPage {
.icon_size(IconSize::Small)
.style(ButtonStyle::Filled),
)
.menu(move |cx| {
.menu(move |window, cx| {
Some(Self::render_remote_extension_context_menu(
&this,
extension_id.clone(),
window,
cx,
))
}),
@ -634,23 +661,26 @@ impl ExtensionsPage {
}
fn render_remote_extension_context_menu(
this: &View<Self>,
this: &Entity<Self>,
extension_id: Arc<str>,
cx: &mut WindowContext,
) -> View<ContextMenu> {
let context_menu = ContextMenu::build(cx, |context_menu, cx| {
window: &mut Window,
cx: &mut App,
) -> Entity<ContextMenu> {
let context_menu = ContextMenu::build(window, cx, |context_menu, window, _| {
context_menu
.entry(
"Install Another Version...",
None,
cx.handler_for(this, {
window.handler_for(this, {
let extension_id = extension_id.clone();
move |this, cx| this.show_extension_version_list(extension_id.clone(), cx)
move |this, window, cx| {
this.show_extension_version_list(extension_id.clone(), window, cx)
}
}),
)
.entry("Copy Extension ID", None, {
let extension_id = extension_id.clone();
move |cx| {
move |_, cx| {
cx.write_to_clipboard(ClipboardItem::new_string(extension_id.to_string()));
}
})
@ -659,12 +689,17 @@ impl ExtensionsPage {
context_menu
}
fn show_extension_version_list(&mut self, extension_id: Arc<str>, cx: &mut ViewContext<Self>) {
fn show_extension_version_list(
&mut self,
extension_id: Arc<str>,
window: &mut Window,
cx: &mut Context<Self>,
) {
let Some(workspace) = self.workspace.upgrade() else {
return;
};
cx.spawn(move |this, mut cx| async move {
cx.spawn_in(window, move |this, mut cx| async move {
let extension_versions_task = this.update(&mut cx, |_, cx| {
let extension_store = ExtensionStore::global(cx);
@ -675,16 +710,16 @@ impl ExtensionsPage {
let extension_versions = extension_versions_task.await?;
workspace.update(&mut cx, |workspace, cx| {
workspace.update_in(&mut cx, |workspace, window, cx| {
let fs = workspace.project().read(cx).fs().clone();
workspace.toggle_modal(cx, |cx| {
workspace.toggle_modal(window, cx, |window, cx| {
let delegate = ExtensionVersionSelectorDelegate::new(
fs,
cx.view().downgrade(),
cx.model().downgrade(),
extension_versions,
);
ExtensionVersionSelector::new(delegate, cx)
ExtensionVersionSelector::new(delegate, window, cx)
});
})?;
@ -698,7 +733,7 @@ impl ExtensionsPage {
extension: &ExtensionMetadata,
status: &ExtensionStatus,
has_dev_extension: bool,
cx: &mut ViewContext<Self>,
cx: &mut Context<Self>,
) -> (Button, Option<Button>) {
let is_compatible =
extension_host::is_version_compatible(ReleaseChannel::global(cx), extension);
@ -716,7 +751,7 @@ impl ExtensionsPage {
ExtensionStatus::NotInstalled => (
Button::new(SharedString::from(extension.id.clone()), "Install").on_click({
let extension_id = extension.id.clone();
move |_, cx| {
move |_, _, cx| {
telemetry::event!("Extension Installed");
ExtensionStore::global(cx).update(cx, |store, cx| {
store.install_latest_extension(extension_id.clone(), cx)
@ -738,7 +773,7 @@ impl ExtensionsPage {
ExtensionStatus::Installed(installed_version) => (
Button::new(SharedString::from(extension.id.clone()), "Uninstall").on_click({
let extension_id = extension.id.clone();
move |_, cx| {
move |_, _, cx| {
telemetry::event!("Extension Uninstalled", extension_id);
ExtensionStore::global(cx).update(cx, |store, cx| {
store.uninstall_extension(extension_id.clone(), cx)
@ -753,12 +788,12 @@ impl ExtensionsPage {
.when(!is_compatible, |upgrade_button| {
upgrade_button.disabled(true).tooltip({
let version = extension.manifest.version.clone();
move |cx| {
Tooltip::text(
move |_, cx| {
Tooltip::simple(
format!(
"v{version} is not compatible with this version of Zed.",
),
cx,
cx,
)
}
})
@ -767,7 +802,7 @@ impl ExtensionsPage {
.on_click({
let extension_id = extension.id.clone();
let version = extension.manifest.version.clone();
move |_, cx| {
move |_, _, cx| {
telemetry::event!("Extension Installed", extension_id, version);
ExtensionStore::global(cx).update(cx, |store, cx| {
store
@ -790,7 +825,7 @@ impl ExtensionsPage {
}
}
fn render_search(&self, cx: &mut ViewContext<Self>) -> Div {
fn render_search(&self, cx: &mut Context<Self>) -> Div {
let mut key_context = KeyContext::new_with_defaults();
key_context.add("BufferSearchBar");
@ -815,7 +850,11 @@ impl ExtensionsPage {
)
}
fn render_text_input(&self, editor: &View<Editor>, cx: &ViewContext<Self>) -> impl IntoElement {
fn render_text_input(
&self,
editor: &Entity<Editor>,
cx: &mut Context<Self>,
) -> impl IntoElement {
let settings = ThemeSettings::get_global(cx);
let text_style = TextStyle {
color: if editor.read(cx).read_only(cx) {
@ -845,9 +884,9 @@ impl ExtensionsPage {
fn on_query_change(
&mut self,
_: View<Editor>,
_: Entity<Editor>,
event: &editor::EditorEvent,
cx: &mut ViewContext<Self>,
cx: &mut Context<Self>,
) {
if let editor::EditorEvent::Edited { .. } = event {
self.query_contains_error = false;
@ -856,7 +895,7 @@ impl ExtensionsPage {
}
}
fn fetch_extensions_debounced(&mut self, cx: &mut ViewContext<ExtensionsPage>) {
fn fetch_extensions_debounced(&mut self, cx: &mut Context<ExtensionsPage>) {
self.extension_fetch_task = Some(cx.spawn(|this, mut cx| async move {
let search = this
.update(&mut cx, |this, cx| this.search_query(cx))
@ -882,7 +921,7 @@ impl ExtensionsPage {
}));
}
pub fn search_query(&self, cx: &WindowContext) -> Option<String> {
pub fn search_query(&self, cx: &mut App) -> Option<String> {
let search = self.query_editor.read(cx).text(cx);
if search.trim().is_empty() {
None
@ -891,7 +930,7 @@ impl ExtensionsPage {
}
}
fn render_empty_state(&self, cx: &mut ViewContext<Self>) -> impl IntoElement {
fn render_empty_state(&self, cx: &mut Context<Self>) -> impl IntoElement {
let has_search = self.search_query(cx).is_some();
let message = if self.is_fetching_extensions {
@ -928,7 +967,8 @@ impl ExtensionsPage {
fn update_settings<T: Settings>(
&mut self,
selection: &ToggleState,
cx: &mut ViewContext<Self>,
cx: &mut Context<Self>,
callback: impl 'static + Send + Fn(&mut T::FileContent, bool),
) {
if let Some(workspace) = self.workspace.upgrade() {
@ -946,7 +986,7 @@ impl ExtensionsPage {
}
}
fn refresh_feature_upsells(&mut self, cx: &mut ViewContext<Self>) {
fn refresh_feature_upsells(&mut self, cx: &mut Context<Self>) {
let Some(search) = self.search_query(cx) else {
self.upsells.clear();
return;
@ -970,7 +1010,7 @@ impl ExtensionsPage {
}
}
fn render_feature_upsells(&self, cx: &mut ViewContext<Self>) -> impl IntoElement {
fn render_feature_upsells(&self, cx: &mut Context<Self>) -> impl IntoElement {
let upsells_count = self.upsells.len();
v_flex().children(self.upsells.iter().enumerate().map(|(ix, feature)| {
@ -993,7 +1033,7 @@ impl ExtensionsPage {
} else {
ui::ToggleState::Unselected
},
cx.listener(move |this, selection, cx| {
cx.listener(move |this, selection, _, cx| {
telemetry::event!("Vim Mode Toggled", source = "Feature Upsell");
this.update_settings::<VimModeSetting>(
selection,
@ -1028,7 +1068,7 @@ impl ExtensionsPage {
}
impl Render for ExtensionsPage {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
v_flex()
.size_full()
.bg(cx.theme().colors().editor_background)
@ -1049,8 +1089,8 @@ impl Render for ExtensionsPage {
Button::new("install-dev-extension", "Install Dev Extension")
.style(ButtonStyle::Filled)
.size(ButtonSize::Large)
.on_click(|_event, cx| {
cx.dispatch_action(Box::new(InstallDevExtension))
.on_click(|_event, window, cx| {
window.dispatch_action(Box::new(InstallDevExtension), cx)
}),
),
)
@ -1067,12 +1107,12 @@ impl Render for ExtensionsPage {
.style(ButtonStyle::Filled)
.size(ButtonSize::Large)
.toggle_state(self.filter == ExtensionFilter::All)
.on_click(cx.listener(|this, _event, cx| {
.on_click(cx.listener(|this, _event, _, cx| {
this.filter = ExtensionFilter::All;
this.filter_extension_entries(cx);
}))
.tooltip(move |cx| {
Tooltip::text("Show all extensions", cx)
.tooltip(move |_, cx| {
Tooltip::simple("Show all extensions", cx)
})
.first(),
)
@ -1081,12 +1121,12 @@ impl Render for ExtensionsPage {
.style(ButtonStyle::Filled)
.size(ButtonSize::Large)
.toggle_state(self.filter == ExtensionFilter::Installed)
.on_click(cx.listener(|this, _event, cx| {
.on_click(cx.listener(|this, _event, _, cx| {
this.filter = ExtensionFilter::Installed;
this.filter_extension_entries(cx);
}))
.tooltip(move |cx| {
Tooltip::text("Show installed extensions", cx)
.tooltip(move |_, cx| {
Tooltip::simple("Show installed extensions", cx)
})
.middle(),
)
@ -1097,12 +1137,12 @@ impl Render for ExtensionsPage {
.toggle_state(
self.filter == ExtensionFilter::NotInstalled,
)
.on_click(cx.listener(|this, _event, cx| {
.on_click(cx.listener(|this, _event, _, cx| {
this.filter = ExtensionFilter::NotInstalled;
this.filter_extension_entries(cx);
}))
.tooltip(move |cx| {
Tooltip::text("Show not installed extensions", cx)
.tooltip(move |_, cx| {
Tooltip::simple("Show not installed extensions", cx)
})
.last(),
),
@ -1120,10 +1160,10 @@ impl Render for ExtensionsPage {
return this.py_4().child(self.render_empty_state(cx));
}
let view = cx.view().clone();
let extensions_page = cx.model().clone();
let scroll_handle = self.list.clone();
this.child(
uniform_list(view, "entries", count, Self::render_extensions)
uniform_list(extensions_page, "entries", count, Self::render_extensions)
.flex_grow()
.pb_4()
.track_scroll(scroll_handle),
@ -1134,8 +1174,8 @@ impl Render for ExtensionsPage {
impl EventEmitter<ItemEvent> for ExtensionsPage {}
impl FocusableView for ExtensionsPage {
fn focus_handle(&self, cx: &AppContext) -> gpui::FocusHandle {
impl Focusable for ExtensionsPage {
fn focus_handle(&self, cx: &App) -> gpui::FocusHandle {
self.query_editor.read(cx).focus_handle(cx)
}
}
@ -1143,7 +1183,7 @@ impl FocusableView for ExtensionsPage {
impl Item for ExtensionsPage {
type Event = ItemEvent;
fn tab_content_text(&self, _cx: &WindowContext) -> Option<SharedString> {
fn tab_content_text(&self, _window: &Window, _cx: &App) -> Option<SharedString> {
Some("Extensions".into())
}
@ -1158,8 +1198,9 @@ impl Item for ExtensionsPage {
fn clone_on_split(
&self,
_workspace_id: Option<WorkspaceId>,
_: &mut ViewContext<Self>,
) -> Option<View<Self>> {
_window: &mut Window,
_: &mut Context<Self>,
) -> Option<Entity<Self>> {
None
}