mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-21 14:54:49 +01:00
feat: cursor+buffer controllers know their ws id
This commit is contained in:
parent
4fcab00d34
commit
03a158e678
5 changed files with 22 additions and 5 deletions
|
@ -22,9 +22,14 @@ use crate::ext::IgnorableError;
|
|||
pub struct BufferController(pub(crate) Arc<BufferControllerInner>);
|
||||
|
||||
impl BufferController {
|
||||
/// Get id of workspace containing this controller
|
||||
pub fn workspace_id(&self) -> &str {
|
||||
&self.0.workspace_id
|
||||
}
|
||||
|
||||
/// Get the buffer path.
|
||||
pub fn path(&self) -> &str {
|
||||
&self.0.name
|
||||
&self.0.path
|
||||
}
|
||||
|
||||
/// Return buffer whole content, updating internal acknowledgement tracker.
|
||||
|
@ -50,7 +55,7 @@ impl BufferController {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct BufferControllerInner {
|
||||
pub(crate) name: String,
|
||||
pub(crate) path: String,
|
||||
pub(crate) latest_version: watch::Receiver<diamond_types::LocalVersion>,
|
||||
pub(crate) local_version: watch::Receiver<diamond_types::LocalVersion>,
|
||||
pub(crate) ops_in: mpsc::UnboundedSender<TextChange>,
|
||||
|
@ -59,6 +64,7 @@ pub(crate) struct BufferControllerInner {
|
|||
pub(crate) delta_request: mpsc::Sender<oneshot::Sender<Option<BufferUpdate>>>,
|
||||
pub(crate) callback: watch::Sender<Option<ControllerCallback<BufferController>>>,
|
||||
pub(crate) ack_tx: mpsc::UnboundedSender<LocalVersion>,
|
||||
pub(crate) workspace_id: String,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "async-trait", async_trait::async_trait)]
|
||||
|
|
|
@ -40,6 +40,7 @@ impl BufferController {
|
|||
path: &str,
|
||||
tx: mpsc::Sender<Operation>,
|
||||
rx: Streaming<BufferEvent>,
|
||||
workspace_id: &str,
|
||||
) -> Self {
|
||||
let init = diamond_types::LocalVersion::default();
|
||||
|
||||
|
@ -57,7 +58,7 @@ impl BufferController {
|
|||
let agent_id = oplog.get_or_create_agent_id(&user_id.to_string());
|
||||
|
||||
let controller = Arc::new(BufferControllerInner {
|
||||
name: path.to_string(),
|
||||
path: path.to_string(),
|
||||
latest_version: latest_version_rx,
|
||||
local_version: my_version_rx,
|
||||
ops_in: opin_tx,
|
||||
|
@ -66,6 +67,7 @@ impl BufferController {
|
|||
delta_request: recv_tx,
|
||||
callback: cb_tx,
|
||||
ack_tx,
|
||||
workspace_id: workspace_id.to_string(),
|
||||
});
|
||||
|
||||
let weak = Arc::downgrade(&controller);
|
||||
|
|
|
@ -25,12 +25,19 @@ use codemp_proto::{
|
|||
#[cfg_attr(feature = "js", napi_derive::napi)]
|
||||
pub struct CursorController(pub(crate) Arc<CursorControllerInner>);
|
||||
|
||||
impl CursorController {
|
||||
pub fn workspace_id(&self) -> &str {
|
||||
&self.0.workspace_id
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct CursorControllerInner {
|
||||
pub(crate) op: mpsc::UnboundedSender<CursorPosition>,
|
||||
pub(crate) stream: mpsc::Sender<oneshot::Sender<Option<Cursor>>>,
|
||||
pub(crate) poll: mpsc::UnboundedSender<oneshot::Sender<()>>,
|
||||
pub(crate) callback: watch::Sender<Option<ControllerCallback<CursorController>>>,
|
||||
pub(crate) workspace_id: String,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "async-trait", async_trait::async_trait)]
|
||||
|
|
|
@ -28,6 +28,7 @@ impl CursorController {
|
|||
user_map: Arc<dashmap::DashMap<Uuid, User>>,
|
||||
tx: mpsc::Sender<CursorPosition>,
|
||||
rx: Streaming<CursorEvent>,
|
||||
workspace_id: &str,
|
||||
) -> Self {
|
||||
// TODO we should tweak the channel buffer size to better propagate backpressure
|
||||
let (op_tx, op_rx) = mpsc::unbounded_channel();
|
||||
|
@ -39,6 +40,7 @@ impl CursorController {
|
|||
stream: stream_tx,
|
||||
callback: cb_tx,
|
||||
poll: poll_tx,
|
||||
workspace_id: workspace_id.to_string(),
|
||||
});
|
||||
|
||||
let weak = Arc::downgrade(&controller);
|
||||
|
|
|
@ -113,7 +113,7 @@ impl Workspace {
|
|||
|
||||
let users = Arc::new(DashMap::default());
|
||||
|
||||
let controller = cursor::Controller::spawn(users.clone(), tx, cur_stream);
|
||||
let controller = cursor::Controller::spawn(users.clone(), tx, cur_stream, &name);
|
||||
|
||||
let ws = Self(Arc::new(WorkspaceInner {
|
||||
name,
|
||||
|
@ -175,7 +175,7 @@ impl Workspace {
|
|||
);
|
||||
let stream = self.0.services.buf().attach(req).await?.into_inner();
|
||||
|
||||
let controller = buffer::Controller::spawn(self.0.user.id, path, tx, stream);
|
||||
let controller = buffer::Controller::spawn(self.0.user.id, path, tx, stream, &self.0.name);
|
||||
self.0.buffers.insert(path.to_string(), controller.clone());
|
||||
|
||||
Ok(controller)
|
||||
|
|
Loading…
Reference in a new issue