Store shared buffers on LocalWorktree
It's okay for our domain objects to model remote state. We should minimize what we need to store in the rpc::ClientState struct.
This commit is contained in:
+6
-8
@@ -1,5 +1,5 @@
|
||||
use super::util::SurfResultExt as _;
|
||||
use crate::{editor::Buffer, language::LanguageRegistry, worktree::Worktree};
|
||||
use crate::{language::LanguageRegistry, worktree::Worktree};
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use gpui::executor::Background;
|
||||
use gpui::{AsyncAppContext, ModelHandle, Task, WeakModelHandle};
|
||||
@@ -29,22 +29,21 @@ pub struct Client {
|
||||
|
||||
pub struct ClientState {
|
||||
connection_id: Option<ConnectionId>,
|
||||
pub remote_worktrees: HashMap<u64, WeakModelHandle<Worktree>>,
|
||||
pub shared_buffers: HashMap<PeerId, HashMap<u64, ModelHandle<Buffer>>>,
|
||||
pub shared_worktrees: HashMap<u64, WeakModelHandle<Worktree>>,
|
||||
pub languages: Arc<LanguageRegistry>,
|
||||
}
|
||||
|
||||
impl ClientState {
|
||||
pub fn remote_worktree(
|
||||
pub fn shared_worktree(
|
||||
&mut self,
|
||||
id: u64,
|
||||
cx: &mut AsyncAppContext,
|
||||
) -> Result<ModelHandle<Worktree>> {
|
||||
if let Some(worktree) = self.remote_worktrees.get(&id) {
|
||||
if let Some(worktree) = self.shared_worktrees.get(&id) {
|
||||
if let Some(worktree) = cx.read(|cx| worktree.upgrade(cx)) {
|
||||
Ok(worktree)
|
||||
} else {
|
||||
self.remote_worktrees.remove(&id);
|
||||
self.shared_worktrees.remove(&id);
|
||||
Err(anyhow!("worktree {} was dropped", id))
|
||||
}
|
||||
} else {
|
||||
@@ -59,8 +58,7 @@ impl Client {
|
||||
peer: Peer::new(),
|
||||
state: Arc::new(Mutex::new(ClientState {
|
||||
connection_id: None,
|
||||
remote_worktrees: Default::default(),
|
||||
shared_buffers: Default::default(),
|
||||
shared_worktrees: Default::default(),
|
||||
languages,
|
||||
})),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user