Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

zeta: Show update required notification on appropriate window(s) (#37130)

Michael Sloancfd56a744d59
diff --git a/crates/zed/src/zed/edit_prediction_registry.rs b/crates/zed/src/zed/edit_prediction_registry.rs
index bc2d757fd19..7b8b98018e6 100644
--- a/crates/zed/src/zed/edit_prediction_registry.rs
+++ b/crates/zed/src/zed/edit_prediction_registry.rs
@@ -8,7 +8,6 @@ use settings::SettingsStore;
use std::{cell::RefCell, rc::Rc, sync::Arc};
use supermaven::{Supermaven, SupermavenCompletionProvider};
use ui::Window;
-use workspace::Workspace;
use zeta::{ProviderDataCollection, ZetaEditPredictionProvider};
pub fn init(client: Arc<Client>, user_store: Entity<UserStore>, cx: &mut App) {
@@ -204,13 +203,7 @@ fn assign_edit_prediction_provider(
}
}
- let workspace = window
- .root::<Workspace>()
- .flatten()
- .map(|workspace| workspace.downgrade());
-
- let zeta =
- zeta::Zeta::register(workspace, worktree, client.clone(), user_store, cx);
+ let zeta = zeta::Zeta::register(worktree, client.clone(), user_store, cx);
if let Some(buffer) = &singleton_buffer
&& buffer.read(cx).file().is_some()
diff --git a/crates/zeta/src/zeta.rs b/crates/zeta/src/zeta.rs
index 7b14d127960..e0cfd23dd26 100644
--- a/crates/zeta/src/zeta.rs
+++ b/crates/zeta/src/zeta.rs
@@ -24,7 +24,7 @@ use collections::{HashMap, HashSet, VecDeque};
use futures::AsyncReadExt;
use gpui::{
App, AppContext as _, AsyncApp, Context, Entity, EntityId, Global, SemanticVersion,
- Subscription, Task, WeakEntity, actions,
+ SharedString, Subscription, Task, actions,
};
use http_client::{AsyncBody, HttpClient, Method, Request, Response};
use input_excerpt::excerpt_for_cursor_position;
@@ -51,8 +51,7 @@ use telemetry_events::EditPredictionRating;
use thiserror::Error;
use util::ResultExt;
use uuid::Uuid;
-use workspace::Workspace;
-use workspace::notifications::{ErrorMessagePrompt, NotificationId};
+use workspace::notifications::{ErrorMessagePrompt, NotificationId, show_app_notification};
use worktree::Worktree;
const CURSOR_MARKER: &str = "<|user_cursor_is_here|>";
@@ -212,7 +211,6 @@ impl std::fmt::Debug for EditPrediction {
}
pub struct Zeta {
- workspace: Option<WeakEntity<Workspace>>,
client: Arc<Client>,
events: VecDeque<Event>,
registered_buffers: HashMap<gpui::EntityId, RegisteredBuffer>,
@@ -233,14 +231,13 @@ impl Zeta {
}
pub fn register(
- workspace: Option<WeakEntity<Workspace>>,
worktree: Option<Entity<Worktree>>,
client: Arc<Client>,
user_store: Entity<UserStore>,
cx: &mut App,
) -> Entity<Self> {
let this = Self::global(cx).unwrap_or_else(|| {
- let entity = cx.new(|cx| Self::new(workspace, client, user_store, cx));
+ let entity = cx.new(|cx| Self::new(client, user_store, cx));
cx.set_global(ZetaGlobal(entity.clone()));
entity
});
@@ -265,19 +262,13 @@ impl Zeta {
self.user_store.read(cx).edit_prediction_usage()
}
- fn new(
- workspace: Option<WeakEntity<Workspace>>,
- client: Arc<Client>,
- user_store: Entity<UserStore>,
- cx: &mut Context<Self>,
- ) -> Self {
+ fn new(client: Arc<Client>, user_store: Entity<UserStore>, cx: &mut Context<Self>) -> Self {
let refresh_llm_token_listener = RefreshLlmTokenListener::global(cx);
let data_collection_choice = Self::load_data_collection_choices();
let data_collection_choice = cx.new(|_| data_collection_choice);
Self {
- workspace,
client,
events: VecDeque::new(),
shown_completions: VecDeque::new(),
@@ -370,7 +361,6 @@ impl Zeta {
fn request_completion_impl<F, R>(
&mut self,
- workspace: Option<Entity<Workspace>>,
project: Option<&Entity<Project>>,
buffer: &Entity<Buffer>,
cursor: language::Anchor,
@@ -453,23 +443,20 @@ impl Zeta {
zeta.update_required = true;
});
- if let Some(workspace) = workspace {
- workspace.update(cx, |workspace, cx| {
- workspace.show_notification(
- NotificationId::unique::<ZedUpdateRequiredError>(),
- cx,
- |cx| {
- cx.new(|cx| {
- ErrorMessagePrompt::new(err.to_string(), cx)
- .with_link_button(
- "Update Zed",
- "https://zed.dev/releases",
- )
- })
- },
- );
- });
- }
+ let error_message: SharedString = err.to_string().into();
+ show_app_notification(
+ NotificationId::unique::<ZedUpdateRequiredError>(),
+ cx,
+ move |cx| {
+ cx.new(|cx| {
+ ErrorMessagePrompt::new(error_message.clone(), cx)
+ .with_link_button(
+ "Update Zed",
+ "https://zed.dev/releases",
+ )
+ })
+ },
+ );
})
.ok();
}
@@ -689,7 +676,7 @@ and then another
) -> Task<Result<Option<EditPrediction>>> {
use std::future::ready;
- self.request_completion_impl(None, project, buffer, position, false, cx, |_params| {
+ self.request_completion_impl(project, buffer, position, false, cx, |_params| {
ready(Ok((response, None)))
})
}
@@ -702,12 +689,7 @@ and then another
can_collect_data: bool,
cx: &mut Context<Self>,
) -> Task<Result<Option<EditPrediction>>> {
- let workspace = self
- .workspace
- .as_ref()
- .and_then(|workspace| workspace.upgrade());
self.request_completion_impl(
- workspace,
project,
buffer,
position,
@@ -2029,7 +2011,7 @@ mod tests {
// Construct the fake server to authenticate.
let _server = FakeServer::for_client(42, &client, cx).await;
let user_store = cx.new(|cx| UserStore::new(client.clone(), cx));
- let zeta = cx.new(|cx| Zeta::new(None, client, user_store.clone(), cx));
+ let zeta = cx.new(|cx| Zeta::new(client, user_store.clone(), cx));
let buffer = cx.new(|cx| Buffer::local(buffer_content, cx));
let cursor = buffer.read_with(cx, |buffer, _| buffer.anchor_before(Point::new(1, 0)));
@@ -2093,7 +2075,7 @@ mod tests {
// Construct the fake server to authenticate.
let _server = FakeServer::for_client(42, &client, cx).await;
let user_store = cx.new(|cx| UserStore::new(client.clone(), cx));
- let zeta = cx.new(|cx| Zeta::new(None, client, user_store.clone(), cx));
+ let zeta = cx.new(|cx| Zeta::new(client, user_store.clone(), cx));
let buffer = cx.new(|cx| Buffer::local(buffer_content, cx));
let snapshot = buffer.read_with(cx, |buffer, _| buffer.snapshot());