mirror of
https://github.com/hexedtech/codemp.git
synced 2024-12-23 05:14:54 +01:00
chore: cleanup
This commit is contained in:
parent
ae66f282d4
commit
ce8dcc8b8c
10 changed files with 31 additions and 33 deletions
|
@ -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<String>,
|
||||
/// port to connect to, default 50053
|
||||
/// Port to connect to, default 50053.
|
||||
pub port: Option<u16>,
|
||||
/// enable or disable tls, default true
|
||||
/// Enable or disable tls, default true.
|
||||
pub tls: Option<bool>,
|
||||
}
|
||||
|
||||
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(),
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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<TextChange>,
|
||||
pub(crate) poller: mpsc::UnboundedSender<oneshot::Sender<()>>,
|
||||
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) ack_tx: mpsc::UnboundedSender<LocalVersion>,
|
||||
}
|
||||
|
|
|
@ -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<BufferUpdate>;
|
||||
pub(crate) type DeltaRequest = (LocalVersion, oneshot::Sender<DeltaOp>);
|
||||
|
||||
struct BufferWorker {
|
||||
user_id: Uuid,
|
||||
path: String,
|
||||
|
@ -28,7 +25,7 @@ struct BufferWorker {
|
|||
poller: mpsc::UnboundedReceiver<oneshot::Sender<()>>,
|
||||
pollers: Vec<oneshot::Sender<()>>,
|
||||
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>,
|
||||
callback: watch::Receiver<Option<ControllerCallback<BufferController>>>,
|
||||
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
|
||||
.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(),
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)?)
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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::{
|
||||
|
|
Loading…
Reference in a new issue