chore: cleanup

This commit is contained in:
zaaarf 2024-10-10 12:14:44 +02:00 committed by alemi.dev
parent ae66f282d4
commit ce8dcc8b8c
10 changed files with 31 additions and 33 deletions

View file

@ -1,11 +1,11 @@
//! # Config //! # Config
//! Data structure defining clients configuration //! 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: /// resulting endpoint is composed like this:
/// http{tls?'s':''}://{host}:{port} /// http{tls?'s':''}://{host}:{port}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -16,20 +16,20 @@
)] )]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
pub struct Config { pub struct Config {
/// user identifier used to register, possibly your email /// User identifier used to register, possibly your email.
pub username: String, pub username: String,
/// user password chosen upon registration /// User password chosen upon registration.
pub password: String, 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<String>, pub host: Option<String>,
/// port to connect to, default 50053 /// Port to connect to, default 50053.
pub port: Option<u16>, pub port: Option<u16>,
/// enable or disable tls, default true /// Enable or disable tls, default true.
pub tls: Option<bool>, pub tls: Option<bool>,
} }
impl Config { 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 { pub fn new(username: impl ToString, password: impl ToString) -> Self {
Self { Self {
username: username.to_string(), username: username.to_string(),

View file

@ -4,7 +4,7 @@
#[cfg(any(feature = "py", feature = "py-noabi"))] #[cfg(any(feature = "py", feature = "py-noabi"))]
use pyo3::prelude::*; use pyo3::prelude::*;
/// User cursor position in a buffer /// An event that occurred about a user's cursor.
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "js", napi_derive::napi(object))] #[cfg_attr(feature = "js", napi_derive::napi(object))]
#[cfg_attr(any(feature = "py", feature = "py-noabi"), pyclass)] #[cfg_attr(any(feature = "py", feature = "py-noabi"), pyclass)]
@ -13,11 +13,11 @@ use pyo3::prelude::*;
pub struct Cursor { pub struct Cursor {
/// User who sent the cursor. /// User who sent the cursor.
pub user: String, pub user: String,
/// Cursor selection /// The updated cursor selection.
pub sel: Selection, pub sel: Selection,
} }
/// A cursor selection span, with row-column tuples /// A cursor selection span.
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "js", napi_derive::napi(object))] #[cfg_attr(feature = "js", napi_derive::napi(object))]
#[cfg_attr(any(feature = "py", feature = "py-noabi"), pyclass)] #[cfg_attr(any(feature = "py", feature = "py-noabi"), pyclass)]

View file

@ -6,14 +6,12 @@ use std::sync::Arc;
use diamond_types::LocalVersion; use diamond_types::LocalVersion;
use tokio::sync::{mpsc, oneshot, watch}; 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::controller::{AsyncReceiver, AsyncSender, Controller, ControllerCallback};
use crate::api::TextChange; use crate::api::TextChange;
use crate::errors::ControllerResult; use crate::errors::ControllerResult;
use crate::ext::IgnorableError; use crate::ext::IgnorableError;
use super::worker::DeltaRequest;
/// A [Controller] to asynchronously interact with remote buffers. /// A [Controller] to asynchronously interact with remote buffers.
/// ///
/// Each buffer controller internally tracks the last acknowledged state, remaining always in sync /// 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<TextChange>, pub(crate) ops_in: mpsc::UnboundedSender<TextChange>,
pub(crate) poller: mpsc::UnboundedSender<oneshot::Sender<()>>, pub(crate) poller: mpsc::UnboundedSender<oneshot::Sender<()>>,
pub(crate) content_request: mpsc::Sender<oneshot::Sender<String>>, pub(crate) content_request: mpsc::Sender<oneshot::Sender<String>>,
pub(crate) delta_request: mpsc::Sender<DeltaRequest>, pub(crate) delta_request: mpsc::Sender<(LocalVersion, oneshot::Sender<Option<BufferUpdate>>)>,
pub(crate) callback: watch::Sender<Option<ControllerCallback<BufferController>>>, pub(crate) callback: watch::Sender<Option<ControllerCallback<BufferController>>>,
pub(crate) ack_tx: mpsc::UnboundedSender<LocalVersion>, pub(crate) ack_tx: mpsc::UnboundedSender<LocalVersion>,
} }

View file

@ -6,7 +6,7 @@ use tokio::sync::{mpsc, oneshot, watch};
use tonic::Streaming; use tonic::Streaming;
use uuid::Uuid; use uuid::Uuid;
use crate::api::change::BufferUpdate; use crate::api::BufferUpdate;
use crate::api::controller::ControllerCallback; use crate::api::controller::ControllerCallback;
use crate::api::TextChange; use crate::api::TextChange;
use crate::ext::IgnorableError; use crate::ext::IgnorableError;
@ -15,9 +15,6 @@ use codemp_proto::buffer::{BufferEvent, Operation};
use super::controller::{BufferController, BufferControllerInner}; use super::controller::{BufferController, BufferControllerInner};
pub(crate) type DeltaOp = Option<BufferUpdate>;
pub(crate) type DeltaRequest = (LocalVersion, oneshot::Sender<DeltaOp>);
struct BufferWorker { struct BufferWorker {
user_id: Uuid, user_id: Uuid,
path: String, path: String,
@ -28,7 +25,7 @@ struct BufferWorker {
poller: mpsc::UnboundedReceiver<oneshot::Sender<()>>, poller: mpsc::UnboundedReceiver<oneshot::Sender<()>>,
pollers: Vec<oneshot::Sender<()>>, pollers: Vec<oneshot::Sender<()>>,
content_checkout: mpsc::Receiver<oneshot::Sender<String>>, content_checkout: mpsc::Receiver<oneshot::Sender<String>>,
delta_req: mpsc::Receiver<DeltaRequest>, delta_req: mpsc::Receiver<(LocalVersion, oneshot::Sender<Option<BufferUpdate>>)>,
controller: std::sync::Weak<BufferControllerInner>, controller: std::sync::Weak<BufferControllerInner>,
callback: watch::Receiver<Option<ControllerCallback<BufferController>>>, callback: watch::Receiver<Option<ControllerCallback<BufferController>>>,
oplog: OpLog, oplog: OpLog,
@ -215,7 +212,7 @@ impl BufferWorker {
} }
} }
async fn handle_delta_request(&mut self, last_ver: LocalVersion, tx: oneshot::Sender<DeltaOp>) { async fn handle_delta_request(&mut self, last_ver: LocalVersion, tx: oneshot::Sender<Option<BufferUpdate>>) {
if let Some((lv, Some(dtop))) = self if let Some((lv, Some(dtop))) = self
.oplog .oplog
.iter_xf_operations_from(&last_ver, self.oplog.local_version_ref()) .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)"); tracing::error!("[?!?!] Insert span differs from effective content len (TODO remove this error after a bit)");
} }
crate::api::change::BufferUpdate { crate::api::BufferUpdate {
hash, hash,
version: step_ver.into_iter().map(|x| i64::from_ne_bytes(x.to_ne_bytes())).collect(), // TODO this is wasteful 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, start: dtop.start() as u32,
end: dtop.start() as u32, end: dtop.start() as u32,
content: dtop.content_as_str().unwrap_or_default().to_string(), 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, hash,
version: step_ver.into_iter().map(|x| i64::from_ne_bytes(x.to_ne_bytes())).collect(), // TODO this is wasteful 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, start: dtop.start() as u32,
end: dtop.end() as u32, end: dtop.end() as u32,
content: dtop.content_as_str().unwrap_or_default().to_string(), content: dtop.content_as_str().unwrap_or_default().to_string(),

View file

@ -7,7 +7,10 @@ use tokio::sync::{mpsc, oneshot, watch};
use crate::{ use crate::{
api::{ api::{
controller::{AsyncReceiver, AsyncSender, ControllerCallback}, cursor::Selection, Controller, Cursor controller::{AsyncReceiver, AsyncSender, ControllerCallback},
Controller,
Cursor,
Selection
}, },
errors::ControllerResult, errors::ControllerResult,
}; };

View file

@ -5,7 +5,7 @@ use tonic::Streaming;
use uuid::Uuid; use uuid::Uuid;
use crate::{ use crate::{
api::{controller::ControllerCallback, cursor::Selection, Cursor, User}, api::{controller::ControllerCallback, Cursor, Selection, User},
ext::IgnorableError, ext::IgnorableError,
}; };
use codemp_proto::cursor::{CursorEvent, CursorPosition}; use codemp_proto::cursor::{CursorEvent, CursorPosition};

View file

@ -1,5 +1,5 @@
use crate::api::controller::{AsyncReceiver, AsyncSender}; use crate::api::controller::{AsyncReceiver, AsyncSender};
use crate::api::change::{TextChange, BufferUpdate}; use crate::api::{TextChange, BufferUpdate};
use crate::buffer::controller::BufferController; use crate::buffer::controller::BufferController;
use napi::threadsafe_function::{ use napi::threadsafe_function::{
ErrorStrategy::Fatal, ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode, ErrorStrategy::Fatal, ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode,

View file

@ -39,7 +39,7 @@ impl CursorController {
/// Send a new cursor event to remote /// Send a new cursor event to remote
#[napi(js_name = "send")] #[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)?) Ok(self.send(sel)?)
} }

View file

@ -1,5 +1,5 @@
use crate::api::controller::{AsyncReceiver, AsyncSender}; use crate::api::controller::{AsyncReceiver, AsyncSender};
use crate::api::cursor::{Cursor, Selection}; use crate::api::{Cursor, Selection};
use crate::api::TextChange; use crate::api::TextChange;
use crate::buffer::Controller as BufferController; use crate::buffer::Controller as BufferController;
use crate::cursor::Controller as CursorController; use crate::cursor::Controller as CursorController;

View file

@ -5,8 +5,8 @@ pub use crate::api::{
controller::AsyncReceiver as CodempAsyncReceiver, controller::AsyncSender as CodempAsyncSender, controller::AsyncReceiver as CodempAsyncReceiver, controller::AsyncSender as CodempAsyncSender,
Config as CodempConfig, Controller as CodempController, Cursor as CodempCursor, Config as CodempConfig, Controller as CodempController, Cursor as CodempCursor,
Event as CodempEvent, TextChange as CodempTextChange, User as CodempUser, Event as CodempEvent, TextChange as CodempTextChange, User as CodempUser,
change::BufferUpdate as CodempBufferUpdate, BufferUpdate as CodempBufferUpdate,
cursor::Selection as CodempSelection, Selection as CodempSelection,
}; };
pub use crate::{ pub use crate::{