mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-25 16:34:48 +01:00
chore: cargo fmt
This commit is contained in:
parent
721d71dd18
commit
9e977adcdd
12 changed files with 64 additions and 49 deletions
|
@ -6,8 +6,8 @@ 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::BufferUpdate;
|
|
||||||
use crate::api::controller::{AsyncReceiver, AsyncSender, Controller, ControllerCallback};
|
use crate::api::controller::{AsyncReceiver, AsyncSender, Controller, ControllerCallback};
|
||||||
|
use crate::api::BufferUpdate;
|
||||||
use crate::api::TextChange;
|
use crate::api::TextChange;
|
||||||
use crate::errors::ControllerResult;
|
use crate::errors::ControllerResult;
|
||||||
use crate::ext::IgnorableError;
|
use crate::ext::IgnorableError;
|
||||||
|
@ -37,8 +37,12 @@ impl BufferController {
|
||||||
|
|
||||||
/// Notify CRDT that changes up to the given version have been merged succesfully.
|
/// Notify CRDT that changes up to the given version have been merged succesfully.
|
||||||
pub fn ack(&self, version: Vec<i64>) {
|
pub fn ack(&self, version: Vec<i64>) {
|
||||||
let version = version.into_iter().map(|x| usize::from_ne_bytes(x.to_ne_bytes())).collect();
|
let version = version
|
||||||
self.0.ack_tx
|
.into_iter()
|
||||||
|
.map(|x| usize::from_ne_bytes(x.to_ne_bytes()))
|
||||||
|
.collect();
|
||||||
|
self.0
|
||||||
|
.ack_tx
|
||||||
.send(version)
|
.send(version)
|
||||||
.unwrap_or_warn("no worker to receive sent ack");
|
.unwrap_or_warn("no worker to receive sent ack");
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@ use tokio::sync::{mpsc, oneshot, watch};
|
||||||
use tonic::Streaming;
|
use tonic::Streaming;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::api::BufferUpdate;
|
|
||||||
use crate::api::controller::ControllerCallback;
|
use crate::api::controller::ControllerCallback;
|
||||||
|
use crate::api::BufferUpdate;
|
||||||
use crate::api::TextChange;
|
use crate::api::TextChange;
|
||||||
use crate::ext::IgnorableError;
|
use crate::ext::IgnorableError;
|
||||||
|
|
||||||
|
@ -212,7 +212,11 @@ impl BufferWorker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_delta_request(&mut self, last_ver: LocalVersion, tx: oneshot::Sender<Option<BufferUpdate>>) {
|
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())
|
||||||
|
@ -239,18 +243,24 @@ impl BufferWorker {
|
||||||
}
|
}
|
||||||
crate::api::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::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(),
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
diamond_types::list::operation::OpKind::Del => crate::api::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::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,
|
||||||
|
|
|
@ -8,9 +8,7 @@ use tokio::sync::{mpsc, oneshot, watch};
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{
|
api::{
|
||||||
controller::{AsyncReceiver, AsyncSender, ControllerCallback},
|
controller::{AsyncReceiver, AsyncSender, ControllerCallback},
|
||||||
Controller,
|
Controller, Cursor, Selection,
|
||||||
Cursor,
|
|
||||||
Selection
|
|
||||||
},
|
},
|
||||||
errors::ControllerResult,
|
errors::ControllerResult,
|
||||||
};
|
};
|
||||||
|
@ -41,9 +39,9 @@ impl Controller<Selection, Cursor> for CursorController {}
|
||||||
#[cfg_attr(feature = "async-trait", async_trait::async_trait)]
|
#[cfg_attr(feature = "async-trait", async_trait::async_trait)]
|
||||||
impl AsyncSender<Selection> for CursorController {
|
impl AsyncSender<Selection> for CursorController {
|
||||||
fn send(&self, mut cursor: Selection) -> ControllerResult<()> {
|
fn send(&self, mut cursor: Selection) -> ControllerResult<()> {
|
||||||
if cursor.start_row > cursor.end_row || (
|
if cursor.start_row > cursor.end_row
|
||||||
cursor.start_row == cursor.end_row && cursor.start_col > cursor.end_col
|
|| (cursor.start_row == cursor.end_row && cursor.start_col > cursor.end_col)
|
||||||
) {
|
{
|
||||||
std::mem::swap(&mut cursor.start_row, &mut cursor.end_row);
|
std::mem::swap(&mut cursor.start_row, &mut cursor.end_row);
|
||||||
std::mem::swap(&mut cursor.start_col, &mut cursor.end_col);
|
std::mem::swap(&mut cursor.start_col, &mut cursor.end_col);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,7 @@ use jni_toolbox::jni;
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{
|
api::{
|
||||||
controller::{AsyncReceiver, AsyncSender},
|
controller::{AsyncReceiver, AsyncSender},
|
||||||
BufferUpdate,
|
BufferUpdate, TextChange,
|
||||||
TextChange
|
|
||||||
},
|
},
|
||||||
errors::ControllerError,
|
errors::ControllerError,
|
||||||
};
|
};
|
||||||
|
@ -26,7 +25,9 @@ fn get_content(controller: &mut crate::buffer::Controller) -> Result<String, Con
|
||||||
|
|
||||||
/// Try to fetch a [TextChange], or return null if there's nothing.
|
/// Try to fetch a [TextChange], or return null if there's nothing.
|
||||||
#[jni(package = "mp.code", class = "BufferController")]
|
#[jni(package = "mp.code", class = "BufferController")]
|
||||||
fn try_recv(controller: &mut crate::buffer::Controller) -> Result<Option<BufferUpdate>, ControllerError> {
|
fn try_recv(
|
||||||
|
controller: &mut crate::buffer::Controller,
|
||||||
|
) -> Result<Option<BufferUpdate>, ControllerError> {
|
||||||
super::tokio().block_on(controller.try_recv())
|
super::tokio().block_on(controller.try_recv())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{
|
api::{
|
||||||
controller::{AsyncReceiver, AsyncSender},
|
controller::{AsyncReceiver, AsyncSender},
|
||||||
Cursor,
|
Cursor, Selection,
|
||||||
Selection
|
|
||||||
},
|
},
|
||||||
errors::ControllerError,
|
errors::ControllerError,
|
||||||
};
|
};
|
||||||
|
|
|
@ -421,7 +421,13 @@ impl<'j> jni_toolbox::FromJava<'j> for crate::api::Selection {
|
||||||
unsafe { env.get_string_unchecked(&jfield.into()) }?.into()
|
unsafe { env.get_string_unchecked(&jfield.into()) }?.into()
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Self { start_row, start_col, end_row, end_col, buffer })
|
Ok(Self {
|
||||||
|
start_row,
|
||||||
|
start_col,
|
||||||
|
end_row,
|
||||||
|
end_col,
|
||||||
|
buffer,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,7 +459,7 @@ impl<'j> jni_toolbox::FromJava<'j> for crate::api::TextChange {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
content
|
content,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::api::controller::{AsyncReceiver, AsyncSender};
|
use crate::api::controller::{AsyncReceiver, AsyncSender};
|
||||||
use crate::api::{TextChange, BufferUpdate};
|
use crate::api::{BufferUpdate, TextChange};
|
||||||
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,
|
||||||
|
@ -51,9 +51,7 @@ impl BufferController {
|
||||||
|
|
||||||
/// Return next buffer event if present
|
/// Return next buffer event if present
|
||||||
#[napi(js_name = "try_recv")]
|
#[napi(js_name = "try_recv")]
|
||||||
pub async fn js_try_recv(
|
pub async fn js_try_recv(&self) -> napi::Result<Option<BufferUpdate>> {
|
||||||
&self,
|
|
||||||
) -> napi::Result<Option<BufferUpdate>> {
|
|
||||||
Ok(self.try_recv().await?)
|
Ok(self.try_recv().await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,9 @@ impl LuaUserData for CodempBufferController {
|
||||||
Ok(format!("{:?}", this))
|
Ok(format!("{:?}", this))
|
||||||
});
|
});
|
||||||
|
|
||||||
methods.add_method("send", |_, this, (change,): (CodempTextChange,)|
|
methods.add_method("send", |_, this, (change,): (CodempTextChange,)| {
|
||||||
Ok(this.send(change)?)
|
Ok(this.send(change)?)
|
||||||
);
|
});
|
||||||
|
|
||||||
methods.add_method(
|
methods.add_method(
|
||||||
"try_recv",
|
"try_recv",
|
||||||
|
@ -21,7 +21,9 @@ impl LuaUserData for CodempBufferController {
|
||||||
);
|
);
|
||||||
methods.add_method("recv", |_, this, ()| a_sync! { this => this.recv().await? });
|
methods.add_method("recv", |_, this, ()| a_sync! { this => this.recv().await? });
|
||||||
methods.add_method("poll", |_, this, ()| a_sync! { this => this.poll().await? });
|
methods.add_method("poll", |_, this, ()| a_sync! { this => this.poll().await? });
|
||||||
methods.add_method_mut("ack", |_, this, (version,):(Vec<i64>,)| Ok(this.ack(version)));
|
methods.add_method_mut("ack", |_, this, (version,): (Vec<i64>,)| {
|
||||||
|
Ok(this.ack(version))
|
||||||
|
});
|
||||||
|
|
||||||
methods.add_method(
|
methods.add_method(
|
||||||
"content",
|
"content",
|
||||||
|
@ -29,11 +31,11 @@ impl LuaUserData for CodempBufferController {
|
||||||
);
|
);
|
||||||
|
|
||||||
methods.add_method("clear_callback", |_, this, ()| Ok(this.clear_callback()));
|
methods.add_method("clear_callback", |_, this, ()| Ok(this.clear_callback()));
|
||||||
methods.add_method("callback", |_, this, (cb,): (LuaFunction,)|
|
methods.add_method("callback", |_, this, (cb,): (LuaFunction,)| {
|
||||||
Ok(this.callback(move |controller: CodempBufferController|
|
Ok(this.callback(move |controller: CodempBufferController| {
|
||||||
super::ext::callback().invoke(cb.clone(), controller)
|
super::ext::callback().invoke(cb.clone(), controller)
|
||||||
))
|
}))
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,11 @@ impl LuaUserData for CodempCursorController {
|
||||||
methods.add_method("poll", |_, this, ()| a_sync! { this => this.poll().await? });
|
methods.add_method("poll", |_, this, ()| a_sync! { this => this.poll().await? });
|
||||||
|
|
||||||
methods.add_method("clear_callback", |_, this, ()| Ok(this.clear_callback()));
|
methods.add_method("clear_callback", |_, this, ()| Ok(this.clear_callback()));
|
||||||
methods.add_method("callback", |_, this, (cb,): (LuaFunction,)|
|
methods.add_method("callback", |_, this, (cb,): (LuaFunction,)| {
|
||||||
Ok(this.callback(move |controller: CodempCursorController|
|
Ok(this.callback(move |controller: CodempCursorController| {
|
||||||
super::ext::callback().invoke(cb.clone(), controller)
|
super::ext::callback().invoke(cb.clone(), controller)
|
||||||
))
|
}))
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,15 +60,13 @@ impl LuaUserData for CodempWorkspace {
|
||||||
|
|
||||||
methods.add_method("poll", |_, this, ()| a_sync! { this => this.poll().await? });
|
methods.add_method("poll", |_, this, ()| a_sync! { this => this.poll().await? });
|
||||||
|
|
||||||
methods.add_method("callback", |_, this, (cb,): (LuaFunction,)|
|
methods.add_method("callback", |_, this, (cb,): (LuaFunction,)| {
|
||||||
Ok(this.callback(move |controller: CodempWorkspace|
|
Ok(this.callback(move |controller: CodempWorkspace| {
|
||||||
super::ext::callback().invoke(cb.clone(), controller)
|
super::ext::callback().invoke(cb.clone(), controller)
|
||||||
))
|
}))
|
||||||
);
|
});
|
||||||
|
|
||||||
methods.add_method("clear_callbacl", |_, this, ()|
|
methods.add_method("clear_callbacl", |_, this, ()| Ok(this.clear_callback()));
|
||||||
Ok(this.clear_callback())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_fields<F: LuaUserDataFields<Self>>(fields: &mut F) {
|
fn add_fields<F: LuaUserDataFields<Self>>(fields: &mut F) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::api::controller::{AsyncReceiver, AsyncSender};
|
use crate::api::controller::{AsyncReceiver, AsyncSender};
|
||||||
use crate::api::{Cursor, Selection};
|
|
||||||
use crate::api::TextChange;
|
use crate::api::TextChange;
|
||||||
|
use crate::api::{Cursor, Selection};
|
||||||
use crate::buffer::Controller as BufferController;
|
use crate::buffer::Controller as BufferController;
|
||||||
use crate::cursor::Controller as CursorController;
|
use crate::cursor::Controller as CursorController;
|
||||||
use pyo3::exceptions::PyValueError;
|
use pyo3::exceptions::PyValueError;
|
||||||
|
|
|
@ -3,10 +3,9 @@
|
||||||
|
|
||||||
pub use crate::api::{
|
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,
|
BufferUpdate as CodempBufferUpdate, Config as CodempConfig, Controller as CodempController,
|
||||||
Event as CodempEvent, TextChange as CodempTextChange, User as CodempUser,
|
Cursor as CodempCursor, Event as CodempEvent, Selection as CodempSelection,
|
||||||
BufferUpdate as CodempBufferUpdate,
|
TextChange as CodempTextChange, User as CodempUser,
|
||||||
Selection as CodempSelection,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
|
|
Loading…
Reference in a new issue