remote projects: Allow reusing window (#11058)

Release Notes:

- Allow reusing the window when opening a remote project from the recent
projects picker
- Fixed an issue, which would not let you rejoin a remote project after
disconnecting from it for the first time

---------

Co-authored-by: Conrad <conrad@zed.dev>
Co-authored-by: Remco <djsmits12@gmail.com>
This commit is contained in:
Bennet Bo Fenner 2024-04-26 21:04:34 +02:00 committed by GitHub
parent 1af1a9e8b3
commit 314b723292
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 80 additions and 23 deletions

View file

@ -9,8 +9,8 @@ use fs::Fs;
use futures::stream::StreamExt;
use futures_batch::ChunksTimeoutStreamExt;
use gpui::{
AppContext, AsyncAppContext, Context, EntityId, EventEmitter, Global, Model, ModelContext,
Subscription, Task, WeakModel,
AppContext, AsyncAppContext, BorrowAppContext, Context, Entity, EntityId, EventEmitter, Global,
Model, ModelContext, Subscription, Task, WeakModel,
};
use heed::types::{SerdeBincode, Str};
use language::LanguageRegistry;
@ -68,6 +68,18 @@ impl SemanticIndex {
project: Model<Project>,
cx: &mut AppContext,
) -> Model<ProjectIndex> {
let project_weak = project.downgrade();
project.update(cx, move |_, cx| {
cx.on_release(move |_, cx| {
if cx.has_global::<SemanticIndex>() {
cx.update_global::<SemanticIndex, _>(|this, _| {
this.project_indices.remove(&project_weak);
})
}
})
.detach();
});
self.project_indices
.entry(project.downgrade())
.or_insert_with(|| {
@ -86,7 +98,7 @@ impl SemanticIndex {
pub struct ProjectIndex {
db_connection: heed::Env,
project: Model<Project>,
project: WeakModel<Project>,
worktree_indices: HashMap<EntityId, WorktreeIndexHandle>,
language_registry: Arc<LanguageRegistry>,
fs: Arc<dyn Fs>,
@ -116,7 +128,7 @@ impl ProjectIndex {
let fs = project.read(cx).fs().clone();
let mut this = ProjectIndex {
db_connection,
project: project.clone(),
project: project.downgrade(),
worktree_indices: HashMap::default(),
language_registry,
fs,
@ -143,8 +155,11 @@ impl ProjectIndex {
}
fn update_worktree_indices(&mut self, cx: &mut ModelContext<Self>) {
let worktrees = self
.project
let Some(project) = self.project.upgrade() else {
return;
};
let worktrees = project
.read(cx)
.visible_worktrees(cx)
.filter_map(|worktree| {