edit predictions: Update migration banner text and rename chore (#24713)

Rationale for the changes:

* `requires migration` -> `uses some deprecated settings` changed
because really it isn't required by this version of Zed, and I believe
we hope to offer support for deprecated settings and their migration for
a long time.

* Rename of `migration` -> `updated` is because to me, "updated" feels
lighter and more accurate. To me migration has connotations of moving to
a whole new format.

Formatting changes are due to shortening the line causing cargo fmt to
go from not formatting the code to doing so.

Release Notes:

- N/A

---------

Co-authored-by: smit <0xtimsb@gmail.com>
This commit is contained in:
Michael Sloan 2025-02-12 06:58:29 -07:00 committed by GitHub
parent e148815e04
commit eb389a5132
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 48 additions and 49 deletions

View file

@ -29,7 +29,7 @@ use gpui::{
WindowOptions, WindowOptions,
}; };
use image_viewer::ImageInfo; use image_viewer::ImageInfo;
use migrate::{MigrationType, MigratorBanner, MigratorEvent, MigratorNotification}; use migrate::{MigrationBanner, MigrationEvent, MigrationNotification, MigrationType};
use migrator::{migrate_keymap, migrate_settings}; use migrator::{migrate_keymap, migrate_settings};
pub use open_listener::*; pub use open_listener::*;
use outline_panel::OutlinePanel; use outline_panel::OutlinePanel;
@ -871,8 +871,8 @@ fn initialize_pane(
toolbar.add_item(lsp_log_item, window, cx); toolbar.add_item(lsp_log_item, window, cx);
let syntax_tree_item = cx.new(|_| language_tools::SyntaxTreeToolbarItemView::new()); let syntax_tree_item = cx.new(|_| language_tools::SyntaxTreeToolbarItemView::new());
toolbar.add_item(syntax_tree_item, window, cx); toolbar.add_item(syntax_tree_item, window, cx);
let migrator_banner = cx.new(|cx| MigratorBanner::new(workspace, cx)); let migration_banner = cx.new(|cx| MigrationBanner::new(workspace, cx));
toolbar.add_item(migrator_banner, window, cx); toolbar.add_item(migration_banner, window, cx);
}) })
}); });
} }
@ -1106,7 +1106,7 @@ pub fn handle_settings_file_changes(
cx: &mut App, cx: &mut App,
settings_changed: impl Fn(Option<anyhow::Error>, &mut App) + 'static, settings_changed: impl Fn(Option<anyhow::Error>, &mut App) + 'static,
) { ) {
MigratorNotification::set_global(cx.new(|_| MigratorNotification), cx); MigrationNotification::set_global(cx.new(|_| MigrationNotification), cx);
let content = cx let content = cx
.background_executor() .background_executor()
.block(user_settings_file_rx.next()) .block(user_settings_file_rx.next())
@ -1137,9 +1137,9 @@ pub fn handle_settings_file_changes(
} }
cx.update(|cx| { cx.update(|cx| {
if let Some(notifier) = MigratorNotification::try_global(cx) { if let Some(notifier) = MigrationNotification::try_global(cx) {
notifier.update(cx, |_, cx| { notifier.update(cx, |_, cx| {
cx.emit(MigratorEvent::ContentChanged { cx.emit(MigrationEvent::ContentChanged {
migration_type: MigrationType::Settings, migration_type: MigrationType::Settings,
migrated: content_migrated, migrated: content_migrated,
}); });
@ -1221,9 +1221,9 @@ pub fn handle_keymap_file_changes(
} }
}; };
cx.update(|cx| { cx.update(|cx| {
if let Some(notifier) = MigratorNotification::try_global(cx) { if let Some(notifier) = MigrationNotification::try_global(cx) {
notifier.update(cx, |_, cx| { notifier.update(cx, |_, cx| {
cx.emit(MigratorEvent::ContentChanged { cx.emit(MigrationEvent::ContentChanged {
migration_type: MigrationType::Keymap, migration_type: MigrationType::Keymap,
migrated: content_migrated, migrated: content_migrated,
}); });

View file

@ -18,42 +18,42 @@ pub enum MigrationType {
Settings, Settings,
} }
pub struct MigratorBanner { pub struct MigrationBanner {
migration_type: Option<MigrationType>, migration_type: Option<MigrationType>,
} }
pub enum MigratorEvent { pub enum MigrationEvent {
ContentChanged { ContentChanged {
migration_type: MigrationType, migration_type: MigrationType,
migrated: bool, migrated: bool,
}, },
} }
pub struct MigratorNotification; pub struct MigrationNotification;
impl EventEmitter<MigratorEvent> for MigratorNotification {} impl EventEmitter<MigrationEvent> for MigrationNotification {}
impl MigratorNotification { impl MigrationNotification {
pub fn try_global(cx: &App) -> Option<Entity<Self>> { pub fn try_global(cx: &App) -> Option<Entity<Self>> {
cx.try_global::<GlobalMigratorNotification>() cx.try_global::<GlobalMigrationNotification>()
.map(|notifier| notifier.0.clone()) .map(|notifier| notifier.0.clone())
} }
pub fn set_global(notifier: Entity<Self>, cx: &mut App) { pub fn set_global(notifier: Entity<Self>, cx: &mut App) {
cx.set_global(GlobalMigratorNotification(notifier)); cx.set_global(GlobalMigrationNotification(notifier));
} }
} }
struct GlobalMigratorNotification(Entity<MigratorNotification>); struct GlobalMigrationNotification(Entity<MigrationNotification>);
impl Global for GlobalMigratorNotification {} impl Global for GlobalMigrationNotification {}
impl MigratorBanner { impl MigrationBanner {
pub fn new(_: &Workspace, cx: &mut Context<'_, Self>) -> Self { pub fn new(_: &Workspace, cx: &mut Context<'_, Self>) -> Self {
if let Some(notifier) = MigratorNotification::try_global(cx) { if let Some(notifier) = MigrationNotification::try_global(cx) {
cx.subscribe( cx.subscribe(
&notifier, &notifier,
move |migrator_banner, _, event: &MigratorEvent, cx| { move |migrator_banner, _, event: &MigrationEvent, cx| {
migrator_banner.handle_notification(event, cx); migrator_banner.handle_notification(event, cx);
}, },
) )
@ -80,9 +80,9 @@ impl MigratorBanner {
} }
} }
fn handle_notification(&mut self, event: &MigratorEvent, cx: &mut Context<'_, Self>) { fn handle_notification(&mut self, event: &MigrationEvent, cx: &mut Context<'_, Self>) {
match event { match event {
MigratorEvent::ContentChanged { MigrationEvent::ContentChanged {
migration_type, migration_type,
migrated, migrated,
} => { } => {
@ -100,9 +100,9 @@ impl MigratorBanner {
} }
} }
impl EventEmitter<ToolbarItemEvent> for MigratorBanner {} impl EventEmitter<ToolbarItemEvent> for MigrationBanner {}
impl ToolbarItemView for MigratorBanner { impl ToolbarItemView for MigrationBanner {
fn set_active_pane_item( fn set_active_pane_item(
&mut self, &mut self,
active_pane_item: Option<&dyn ItemHandle>, active_pane_item: Option<&dyn ItemHandle>,
@ -155,7 +155,7 @@ impl ToolbarItemView for MigratorBanner {
} }
} }
impl Render for MigratorBanner { impl Render for MigrationBanner {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let migration_type = self.migration_type; let migration_type = self.migration_type;
let file_type = match migration_type { let file_type = match migration_type {
@ -189,10 +189,11 @@ impl Render for MigratorBanner {
.gap_0p5() .gap_0p5()
.child( .child(
Label::new(format!( Label::new(format!(
"Your {} file requires migration to support this version of Zed. A backup will be saved to", "Your {} file uses deprecated settings which can be \
automatically updated. A backup will be saved to",
file_type file_type
)) ))
.color(Color::Default) .color(Color::Default),
) )
.child( .child(
div() div()
@ -202,32 +203,30 @@ impl Render for MigratorBanner {
.child( .child(
Label::new(backup_file_name) Label::new(backup_file_name)
.buffer_font(cx) .buffer_font(cx)
.size(LabelSize::Small) .size(LabelSize::Small),
), ),
) ),
) ),
) )
.child( .child(
Button::new("backup-and-migrate", "Backup and Migrate").on_click( Button::new("backup-and-migrate", "Backup and Update").on_click(move |_, _, cx| {
move |_, _, cx| { let fs = <dyn Fs>::global(cx);
let fs = <dyn Fs>::global(cx); match migration_type {
match migration_type { Some(MigrationType::Keymap) => {
Some(MigrationType::Keymap) => { cx.spawn(
cx.spawn( move |_| async move { write_keymap_migration(&fs).await.ok() },
move |_| async move { write_keymap_migration(&fs).await.ok() }, )
) .detach();
.detach();
}
Some(MigrationType::Settings) => {
cx.spawn(move |_| async move {
write_settings_migration(&fs).await.ok()
})
.detach();
}
None => unreachable!(),
} }
}, Some(MigrationType::Settings) => {
), cx.spawn(
move |_| async move { write_settings_migration(&fs).await.ok() },
)
.detach();
}
None => unreachable!(),
}
}),
) )
.into_any_element() .into_any_element()
} }