Fix leaked editor (#25530)

Closes #ISSUE

Release Notes:

- Fixed a bug that would prevent rejoining projects sometimes
This commit is contained in:
Conrad Irwin 2025-02-24 20:10:45 -07:00 committed by GitHub
parent 3f168e85c2
commit bcbb19e06e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 26 deletions

View file

@ -9,7 +9,6 @@ mod rate_completion_modal;
pub(crate) use completion_diff_element::*;
use db::kvp::KEY_VALUE_STORE;
use editor::Editor;
pub use init::*;
use inline_completion::DataCollectionState;
pub use license_detection::is_license_eligible_for_data_collection;
@ -24,7 +23,7 @@ use collections::{HashMap, HashSet, VecDeque};
use futures::AsyncReadExt;
use gpui::{
actions, App, AppContext as _, AsyncApp, Context, Entity, EntityId, Global, SemanticVersion,
Subscription, Task,
Subscription, Task, WeakEntity,
};
use http_client::{HttpClient, Method};
use input_excerpt::excerpt_for_cursor_position;
@ -186,7 +185,7 @@ impl std::fmt::Debug for InlineCompletion {
}
pub struct Zeta {
editor: Option<Entity<Editor>>,
workspace: Option<WeakEntity<Workspace>>,
client: Arc<Client>,
events: VecDeque<Event>,
registered_buffers: HashMap<gpui::EntityId, RegisteredBuffer>,
@ -209,14 +208,14 @@ impl Zeta {
}
pub fn register(
editor: Option<Entity<Editor>>,
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(editor, client, user_store, cx));
let entity = cx.new(|cx| Self::new(workspace, client, user_store, cx));
cx.set_global(ZetaGlobal(entity.clone()));
entity
});
@ -239,7 +238,7 @@ impl Zeta {
}
fn new(
editor: Option<Entity<Editor>>,
workspace: Option<WeakEntity<Workspace>>,
client: Arc<Client>,
user_store: Entity<UserStore>,
cx: &mut Context<Self>,
@ -250,7 +249,7 @@ impl Zeta {
let data_collection_choice = cx.new(|_| data_collection_choice);
Self {
editor,
workspace,
client,
events: VecDeque::new(),
shown_completions: VecDeque::new(),
@ -705,10 +704,7 @@ and then another
can_collect_data: bool,
cx: &mut Context<Self>,
) -> Task<Result<Option<InlineCompletion>>> {
let workspace = self
.editor
.as_ref()
.and_then(|editor| editor.read(cx).workspace());
let workspace = self.workspace.as_ref().and_then(|w| w.upgrade());
self.request_completion_impl(
workspace,
project,