mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-21 23:04:49 +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 tokio::sync::{mpsc, oneshot, watch};
|
||||
|
||||
use crate::api::BufferUpdate;
|
||||
use crate::api::controller::{AsyncReceiver, AsyncSender, Controller, ControllerCallback};
|
||||
use crate::api::BufferUpdate;
|
||||
use crate::api::TextChange;
|
||||
use crate::errors::ControllerResult;
|
||||
use crate::ext::IgnorableError;
|
||||
|
@ -37,8 +37,12 @@ impl BufferController {
|
|||
|
||||
/// Notify CRDT that changes up to the given version have been merged succesfully.
|
||||
pub fn ack(&self, version: Vec<i64>) {
|
||||
let version = version.into_iter().map(|x| usize::from_ne_bytes(x.to_ne_bytes())).collect();
|
||||
self.0.ack_tx
|
||||
let version = version
|
||||
.into_iter()
|
||||
.map(|x| usize::from_ne_bytes(x.to_ne_bytes()))
|
||||
.collect();
|
||||
self.0
|
||||
.ack_tx
|
||||
.send(version)
|
||||
.unwrap_or_warn("no worker to receive sent ack");
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ use tokio::sync::{mpsc, oneshot, watch};
|
|||
use tonic::Streaming;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::api::BufferUpdate;
|
||||
use crate::api::controller::ControllerCallback;
|
||||
use crate::api::BufferUpdate;
|
||||
use crate::api::TextChange;
|
||||
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
|
||||
.oplog
|
||||
.iter_xf_operations_from(&last_ver, self.oplog.local_version_ref())
|
||||
|
@ -239,18 +243,24 @@ impl BufferWorker {
|
|||
}
|
||||
crate::api::BufferUpdate {
|
||||
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 {
|
||||
start: dtop.start() as u32,
|
||||
end: dtop.start() as u32,
|
||||
content: dtop.content_as_str().unwrap_or_default().to_string(),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
version: step_ver
|
||||
.into_iter()
|
||||
.map(|x| i64::from_ne_bytes(x.to_ne_bytes()))
|
||||
.collect(), // TODO this is wasteful
|
||||
change: crate::api::TextChange {
|
||||
start: dtop.start() as u32,
|
||||
end: dtop.end() as u32,
|
||||
|
|
|
@ -8,9 +8,7 @@ use tokio::sync::{mpsc, oneshot, watch};
|
|||
use crate::{
|
||||
api::{
|
||||
controller::{AsyncReceiver, AsyncSender, ControllerCallback},
|
||||
Controller,
|
||||
Cursor,
|
||||
Selection
|
||||
Controller, Cursor, Selection,
|
||||
},
|
||||
errors::ControllerResult,
|
||||
};
|
||||
|
@ -41,9 +39,9 @@ impl Controller<Selection, Cursor> for CursorController {}
|
|||
#[cfg_attr(feature = "async-trait", async_trait::async_trait)]
|
||||
impl AsyncSender<Selection> for CursorController {
|
||||
fn send(&self, mut cursor: Selection) -> ControllerResult<()> {
|
||||
if cursor.start_row > cursor.end_row || (
|
||||
cursor.start_row == cursor.end_row && cursor.start_col > cursor.end_col
|
||||
) {
|
||||
if cursor.start_row > cursor.end_row
|
||||
|| (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_col, &mut cursor.end_col);
|
||||
}
|
||||
|
|
|
@ -4,8 +4,7 @@ use jni_toolbox::jni;
|
|||
use crate::{
|
||||
api::{
|
||||
controller::{AsyncReceiver, AsyncSender},
|
||||
BufferUpdate,
|
||||
TextChange
|
||||
BufferUpdate, TextChange,
|
||||
},
|
||||
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.
|
||||
#[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())
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use crate::{
|
||||
api::{
|
||||
controller::{AsyncReceiver, AsyncSender},
|
||||
Cursor,
|
||||
Selection
|
||||
Cursor, Selection,
|
||||
},
|
||||
errors::ControllerError,
|
||||
};
|
||||
|
|
|
@ -421,7 +421,13 @@ impl<'j> jni_toolbox::FromJava<'j> for crate::api::Selection {
|
|||
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 {
|
||||
start,
|
||||
end,
|
||||
content
|
||||
content,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::api::controller::{AsyncReceiver, AsyncSender};
|
||||
use crate::api::{TextChange, BufferUpdate};
|
||||
use crate::api::{BufferUpdate, TextChange};
|
||||
use crate::buffer::controller::BufferController;
|
||||
use napi::threadsafe_function::{
|
||||
ErrorStrategy::Fatal, ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode,
|
||||
|
@ -51,9 +51,7 @@ impl BufferController {
|
|||
|
||||
/// Return next buffer event if present
|
||||
#[napi(js_name = "try_recv")]
|
||||
pub async fn js_try_recv(
|
||||
&self,
|
||||
) -> napi::Result<Option<BufferUpdate>> {
|
||||
pub async fn js_try_recv(&self) -> napi::Result<Option<BufferUpdate>> {
|
||||
Ok(self.try_recv().await?)
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,9 @@ impl LuaUserData for CodempBufferController {
|
|||
Ok(format!("{:?}", this))
|
||||
});
|
||||
|
||||
methods.add_method("send", |_, this, (change,): (CodempTextChange,)|
|
||||
methods.add_method("send", |_, this, (change,): (CodempTextChange,)| {
|
||||
Ok(this.send(change)?)
|
||||
);
|
||||
});
|
||||
|
||||
methods.add_method(
|
||||
"try_recv",
|
||||
|
@ -21,7 +21,9 @@ impl LuaUserData for CodempBufferController {
|
|||
);
|
||||
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_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(
|
||||
"content",
|
||||
|
@ -29,11 +31,11 @@ impl LuaUserData for CodempBufferController {
|
|||
);
|
||||
|
||||
methods.add_method("clear_callback", |_, this, ()| Ok(this.clear_callback()));
|
||||
methods.add_method("callback", |_, this, (cb,): (LuaFunction,)|
|
||||
Ok(this.callback(move |controller: CodempBufferController|
|
||||
methods.add_method("callback", |_, this, (cb,): (LuaFunction,)| {
|
||||
Ok(this.callback(move |controller: CodempBufferController| {
|
||||
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("clear_callback", |_, this, ()| Ok(this.clear_callback()));
|
||||
methods.add_method("callback", |_, this, (cb,): (LuaFunction,)|
|
||||
Ok(this.callback(move |controller: CodempCursorController|
|
||||
methods.add_method("callback", |_, this, (cb,): (LuaFunction,)| {
|
||||
Ok(this.callback(move |controller: CodempCursorController| {
|
||||
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("callback", |_, this, (cb,): (LuaFunction,)|
|
||||
Ok(this.callback(move |controller: CodempWorkspace|
|
||||
methods.add_method("callback", |_, this, (cb,): (LuaFunction,)| {
|
||||
Ok(this.callback(move |controller: CodempWorkspace| {
|
||||
super::ext::callback().invoke(cb.clone(), controller)
|
||||
))
|
||||
);
|
||||
}))
|
||||
});
|
||||
|
||||
methods.add_method("clear_callbacl", |_, this, ()|
|
||||
Ok(this.clear_callback())
|
||||
);
|
||||
methods.add_method("clear_callbacl", |_, this, ()| Ok(this.clear_callback()));
|
||||
}
|
||||
|
||||
fn add_fields<F: LuaUserDataFields<Self>>(fields: &mut F) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::api::controller::{AsyncReceiver, AsyncSender};
|
||||
use crate::api::{Cursor, Selection};
|
||||
use crate::api::TextChange;
|
||||
use crate::api::{Cursor, Selection};
|
||||
use crate::buffer::Controller as BufferController;
|
||||
use crate::cursor::Controller as CursorController;
|
||||
use pyo3::exceptions::PyValueError;
|
||||
|
|
|
@ -3,10 +3,9 @@
|
|||
|
||||
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,
|
||||
BufferUpdate as CodempBufferUpdate,
|
||||
Selection as CodempSelection,
|
||||
BufferUpdate as CodempBufferUpdate, Config as CodempConfig, Controller as CodempController,
|
||||
Cursor as CodempCursor, Event as CodempEvent, Selection as CodempSelection,
|
||||
TextChange as CodempTextChange, User as CodempUser,
|
||||
};
|
||||
|
||||
pub use crate::{
|
||||
|
|
Loading…
Reference in a new issue