From 4239ab4f9d7925aa8b114f26da262339fae8c82d Mon Sep 17 00:00:00 2001
From: "gcp-cherry-pick-bot[bot]"
<98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com>
Date: Tue, 6 May 2025 16:29:59 +0530
Subject: [PATCH] zed: Fix migration message sometimes showing up on other tabs
(cherry-pick #29917) (#29989)
Cherry-picked zed: Fix migration message sometimes showing up on other
tabs (#29917)
Release Notes:
- Fixed an issue where the keymap/settings migration message sometimes
showing up on tabs other than `settings.json` and `keymap.json`.
Co-authored-by: Smit Barmase
---
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 55c5b56a57a99aa82f7157ad4b6fcd78c9cefb09..50c94fcc4338aa2e385204dc48c91ba06ff997e7 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;