Refactor workspace notifications to use explicit NotificationId
type (#10342)
This PR reworks the way workspace notifications are identified to use a new `NotificationId` type. A `NotificationId` is bound to a given type that is used as a unique identifier. Generally this will be a unit struct that can be used to uniquely identify this notification. A `NotificationId` can also accept an optional `ElementId` in order to distinguish between different notifications of the same type. This system avoids the issue we had previously of selecting `usize` IDs somewhat arbitrarily and running the risk of having two independent notifications collide (and thus interfere with each other). This also fixes a bug where multiple suggestion notifications for the same extension could be live at once Fixes https://github.com/zed-industries/zed/issues/10320. Release Notes: - Fixed a bug where multiple extension suggestions for the same extension could be shown at once ([#10320](https://github.com/zed-industries/zed/issues/10320)). --------- Co-authored-by: Max <max@zed.dev>
This commit is contained in:
parent
322f68f3d6
commit
8cbdd9e0fa
12 changed files with 212 additions and 98 deletions
|
@ -5,9 +5,10 @@ use std::sync::{Arc, OnceLock};
|
|||
use db::kvp::KEY_VALUE_STORE;
|
||||
use editor::Editor;
|
||||
use extension::ExtensionStore;
|
||||
use gpui::{Entity, Model, VisualContext};
|
||||
use gpui::{Model, VisualContext};
|
||||
use language::Buffer;
|
||||
use ui::ViewContext;
|
||||
use ui::{SharedString, ViewContext};
|
||||
use workspace::notifications::NotificationId;
|
||||
use workspace::{notifications::simple_message_notification, Workspace};
|
||||
|
||||
fn suggested_extensions() -> &'static HashMap<&'static str, Arc<str>> {
|
||||
|
@ -140,7 +141,13 @@ pub(crate) fn suggest(buffer: Model<Buffer>, cx: &mut ViewContext<Workspace>) {
|
|||
return;
|
||||
}
|
||||
|
||||
workspace.show_notification(buffer.entity_id().as_u64() as usize, cx, |cx| {
|
||||
struct ExtensionSuggestionNotification;
|
||||
|
||||
let notification_id = NotificationId::identified::<ExtensionSuggestionNotification>(
|
||||
SharedString::from(extension_id.clone()),
|
||||
);
|
||||
|
||||
workspace.show_notification(notification_id, cx, |cx| {
|
||||
cx.new_view(move |_cx| {
|
||||
simple_message_notification::MessageNotification::new(format!(
|
||||
"Do you want to install the recommended '{}' extension for '{}' files?",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue