From 4a7b3aa4b8c6aa0f695c549d4302a86b8a86b385 Mon Sep 17 00:00:00 2001 From: Smit Barmase Date: Mon, 5 May 2025 18:13:26 +0530 Subject: [PATCH] zed: Fix migration message sometimes showing up on other tabs (#29917) image Release Notes: - Fixed an issue where the keymap/settings migration message sometimes showing up on tabs other than `settings.json` and `keymap.json`. --- crates/zed/src/zed/migrate.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/zed/src/zed/migrate.rs b/crates/zed/src/zed/migrate.rs index 55c5b56a57..50c94fcc43 100644 --- a/crates/zed/src/zed/migrate.rs +++ b/crates/zed/src/zed/migrate.rs @@ -7,7 +7,7 @@ use util::ResultExt; use std::sync::Arc; -use gpui::{Entity, EventEmitter, Global}; +use gpui::{Entity, EventEmitter, Global, Task}; use ui::prelude::*; use workspace::item::ItemHandle; use workspace::{ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace}; @@ -20,6 +20,7 @@ pub enum MigrationType { pub struct MigrationBanner { migration_type: Option, + should_migrate_task: Option>, } pub enum MigrationEvent { @@ -61,6 +62,7 @@ impl MigrationBanner { } Self { migration_type: None, + should_migrate_task: None, } } @@ -110,6 +112,7 @@ impl ToolbarItemView for MigrationBanner { cx: &mut Context, ) -> ToolbarItemLocation { cx.notify(); + self.should_migrate_task.take(); let Some(target) = active_pane_item .and_then(|item| item.act_as::(cx)) .and_then(|editor| editor.update(cx, |editor, cx| editor.target_file_abs_path(cx))) @@ -121,7 +124,7 @@ impl ToolbarItemView for MigrationBanner { self.migration_type = Some(MigrationType::Keymap); let fs = ::global(cx); let should_migrate = should_migrate_keymap(fs); - cx.spawn_in(window, async move |this, cx| { + self.should_migrate_task = Some(cx.spawn_in(window, async move |this, cx| { if let Ok(true) = should_migrate.await { this.update(cx, |_, cx| { cx.emit(ToolbarItemEvent::ChangeLocation( @@ -131,13 +134,12 @@ impl ToolbarItemView for MigrationBanner { }) .log_err(); } - }) - .detach(); + })); } else if &target == paths::settings_file() { self.migration_type = Some(MigrationType::Settings); let fs = ::global(cx); let should_migrate = should_migrate_settings(fs); - cx.spawn_in(window, async move |this, cx| { + self.should_migrate_task = Some(cx.spawn_in(window, async move |this, cx| { if let Ok(true) = should_migrate.await { this.update(cx, |_, cx| { cx.emit(ToolbarItemEvent::ChangeLocation( @@ -147,8 +149,7 @@ impl ToolbarItemView for MigrationBanner { }) .log_err(); } - }) - .detach(); + })); } return ToolbarItemLocation::Hidden;