diff --git a/src/api/config.rs b/src/api/config.rs index 23dc7ef..b23d962 100644 --- a/src/api/config.rs +++ b/src/api/config.rs @@ -1,11 +1,11 @@ //! # Config //! Data structure defining clients configuration -/// Configuration struct for `codemp` client +/// Configuration struct for the `codemp` client. /// -/// username and password are required fields, while everything else is optional +/// `username` and `password` are required fields, everything else is optional. /// -/// host, port and tls affect all connections to all grpc services +/// `host`, `port` and `tls` affect all connections to all gRPC services; the /// resulting endpoint is composed like this: /// http{tls?'s':''}://{host}:{port} #[derive(Clone, Debug)] @@ -16,20 +16,20 @@ )] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct Config { - /// user identifier used to register, possibly your email + /// User identifier used to register, possibly your email. pub username: String, - /// user password chosen upon registration + /// User password chosen upon registration. pub password: String, - /// address of server to connect to, default api.code.mp + /// Address of server to connect to, default api.code.mp. pub host: Option, - /// port to connect to, default 50053 + /// Port to connect to, default 50053. pub port: Option, - /// enable or disable tls, default true + /// Enable or disable tls, default true. pub tls: Option, } impl Config { - /// construct a new Config object, with given username and password + /// Construct a new Config object, with given username and password. pub fn new(username: impl ToString, password: impl ToString) -> Self { Self { username: username.to_string(), diff --git a/src/api/cursor.rs b/src/api/cursor.rs index 93226f5..89ecd5e 100644 --- a/src/api/cursor.rs +++ b/src/api/cursor.rs @@ -4,7 +4,7 @@ #[cfg(any(feature = "py", feature = "py-noabi"))] use pyo3::prelude::*; -/// User cursor position in a buffer +/// An event that occurred about a user's cursor. #[derive(Clone, Debug, Default)] #[cfg_attr(feature = "js", napi_derive::napi(object))] #[cfg_attr(any(feature = "py", feature = "py-noabi"), pyclass)] @@ -13,11 +13,11 @@ use pyo3::prelude::*; pub struct Cursor { /// User who sent the cursor. pub user: String, - /// Cursor selection + /// The updated cursor selection. pub sel: Selection, } -/// A cursor selection span, with row-column tuples +/// A cursor selection span. #[derive(Clone, Debug, Default)] #[cfg_attr(feature = "js", napi_derive::napi(object))] #[cfg_attr(any(feature = "py", feature = "py-noabi"), pyclass)] diff --git a/src/buffer/controller.rs b/src/buffer/controller.rs index e452b2a..bd860d7 100644 --- a/src/buffer/controller.rs +++ b/src/buffer/controller.rs @@ -6,14 +6,12 @@ use std::sync::Arc; use diamond_types::LocalVersion; use tokio::sync::{mpsc, oneshot, watch}; -use crate::api::change::BufferUpdate; +use crate::api::BufferUpdate; use crate::api::controller::{AsyncReceiver, AsyncSender, Controller, ControllerCallback}; use crate::api::TextChange; use crate::errors::ControllerResult; use crate::ext::IgnorableError; -use super::worker::DeltaRequest; - /// A [Controller] to asynchronously interact with remote buffers. /// /// Each buffer controller internally tracks the last acknowledged state, remaining always in sync @@ -54,7 +52,7 @@ pub(crate) struct BufferControllerInner { pub(crate) ops_in: mpsc::UnboundedSender, pub(crate) poller: mpsc::UnboundedSender>, pub(crate) content_request: mpsc::Sender>, - pub(crate) delta_request: mpsc::Sender, + pub(crate) delta_request: mpsc::Sender<(LocalVersion, oneshot::Sender>)>, pub(crate) callback: watch::Sender>>, pub(crate) ack_tx: mpsc::UnboundedSender, } diff --git a/src/buffer/worker.rs b/src/buffer/worker.rs index a021174..bfa372c 100644 --- a/src/buffer/worker.rs +++ b/src/buffer/worker.rs @@ -6,7 +6,7 @@ use tokio::sync::{mpsc, oneshot, watch}; use tonic::Streaming; use uuid::Uuid; -use crate::api::change::BufferUpdate; +use crate::api::BufferUpdate; use crate::api::controller::ControllerCallback; use crate::api::TextChange; use crate::ext::IgnorableError; @@ -15,9 +15,6 @@ use codemp_proto::buffer::{BufferEvent, Operation}; use super::controller::{BufferController, BufferControllerInner}; -pub(crate) type DeltaOp = Option; -pub(crate) type DeltaRequest = (LocalVersion, oneshot::Sender); - struct BufferWorker { user_id: Uuid, path: String, @@ -28,7 +25,7 @@ struct BufferWorker { poller: mpsc::UnboundedReceiver>, pollers: Vec>, content_checkout: mpsc::Receiver>, - delta_req: mpsc::Receiver, + delta_req: mpsc::Receiver<(LocalVersion, oneshot::Sender>)>, controller: std::sync::Weak, callback: watch::Receiver>>, oplog: OpLog, @@ -215,7 +212,7 @@ impl BufferWorker { } } - async fn handle_delta_request(&mut self, last_ver: LocalVersion, tx: oneshot::Sender) { + async fn handle_delta_request(&mut self, last_ver: LocalVersion, tx: oneshot::Sender>) { if let Some((lv, Some(dtop))) = self .oplog .iter_xf_operations_from(&last_ver, self.oplog.local_version_ref()) @@ -240,10 +237,10 @@ impl BufferWorker { { tracing::error!("[?!?!] Insert span differs from effective content len (TODO remove this error after a bit)"); } - crate::api::change::BufferUpdate { + crate::api::BufferUpdate { hash, version: step_ver.into_iter().map(|x| i64::from_ne_bytes(x.to_ne_bytes())).collect(), // TODO this is wasteful - change: crate::api::change::TextChange { + change: crate::api::TextChange { start: dtop.start() as u32, end: dtop.start() as u32, content: dtop.content_as_str().unwrap_or_default().to_string(), @@ -251,10 +248,10 @@ impl BufferWorker { } } - diamond_types::list::operation::OpKind::Del => crate::api::change::BufferUpdate { + diamond_types::list::operation::OpKind::Del => crate::api::BufferUpdate { hash, version: step_ver.into_iter().map(|x| i64::from_ne_bytes(x.to_ne_bytes())).collect(), // TODO this is wasteful - change: crate::api::change::TextChange { + change: crate::api::TextChange { start: dtop.start() as u32, end: dtop.end() as u32, content: dtop.content_as_str().unwrap_or_default().to_string(), diff --git a/src/cursor/controller.rs b/src/cursor/controller.rs index aa57fe9..211fbc2 100644 --- a/src/cursor/controller.rs +++ b/src/cursor/controller.rs @@ -7,7 +7,10 @@ use tokio::sync::{mpsc, oneshot, watch}; use crate::{ api::{ - controller::{AsyncReceiver, AsyncSender, ControllerCallback}, cursor::Selection, Controller, Cursor + controller::{AsyncReceiver, AsyncSender, ControllerCallback}, + Controller, + Cursor, + Selection }, errors::ControllerResult, }; diff --git a/src/cursor/worker.rs b/src/cursor/worker.rs index 91f07d5..a690a9a 100644 --- a/src/cursor/worker.rs +++ b/src/cursor/worker.rs @@ -5,7 +5,7 @@ use tonic::Streaming; use uuid::Uuid; use crate::{ - api::{controller::ControllerCallback, cursor::Selection, Cursor, User}, + api::{controller::ControllerCallback, Cursor, Selection, User}, ext::IgnorableError, }; use codemp_proto::cursor::{CursorEvent, CursorPosition}; diff --git a/src/ffi/js/buffer.rs b/src/ffi/js/buffer.rs index 5bb8f21..8499a45 100644 --- a/src/ffi/js/buffer.rs +++ b/src/ffi/js/buffer.rs @@ -1,5 +1,5 @@ use crate::api::controller::{AsyncReceiver, AsyncSender}; -use crate::api::change::{TextChange, BufferUpdate}; +use crate::api::{TextChange, BufferUpdate}; use crate::buffer::controller::BufferController; use napi::threadsafe_function::{ ErrorStrategy::Fatal, ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode, diff --git a/src/ffi/js/cursor.rs b/src/ffi/js/cursor.rs index d1ae476..9131abc 100644 --- a/src/ffi/js/cursor.rs +++ b/src/ffi/js/cursor.rs @@ -39,7 +39,7 @@ impl CursorController { /// Send a new cursor event to remote #[napi(js_name = "send")] - pub fn js_send(&self, sel: crate::api::cursor::Selection) -> napi::Result<()> { + pub fn js_send(&self, sel: crate::api::Selection) -> napi::Result<()> { Ok(self.send(sel)?) } diff --git a/src/ffi/python/controllers.rs b/src/ffi/python/controllers.rs index 0d2ccf3..6c1f188 100644 --- a/src/ffi/python/controllers.rs +++ b/src/ffi/python/controllers.rs @@ -1,5 +1,5 @@ use crate::api::controller::{AsyncReceiver, AsyncSender}; -use crate::api::cursor::{Cursor, Selection}; +use crate::api::{Cursor, Selection}; use crate::api::TextChange; use crate::buffer::Controller as BufferController; use crate::cursor::Controller as CursorController; diff --git a/src/prelude.rs b/src/prelude.rs index f7d6fc1..35003a8 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -5,8 +5,8 @@ pub use crate::api::{ controller::AsyncReceiver as CodempAsyncReceiver, controller::AsyncSender as CodempAsyncSender, Config as CodempConfig, Controller as CodempController, Cursor as CodempCursor, Event as CodempEvent, TextChange as CodempTextChange, User as CodempUser, - change::BufferUpdate as CodempBufferUpdate, - cursor::Selection as CodempSelection, + BufferUpdate as CodempBufferUpdate, + Selection as CodempSelection, }; pub use crate::{