mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 07:14:50 +01:00
chore: thanks clippy
This commit is contained in:
parent
0a29a293f5
commit
365811d963
5 changed files with 32 additions and 38 deletions
|
@ -19,19 +19,19 @@ struct NeovimHandler {
|
||||||
factories: Arc<Mutex<BTreeMap<String, Arc<OperationController>>>>,
|
factories: Arc<Mutex<BTreeMap<String, Arc<OperationController>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nullable_optional_str(args: &Vec<Value>, index: usize) -> Option<String> {
|
fn nullable_optional_str(args: &[Value], index: usize) -> Option<String> {
|
||||||
Some(args.get(index)?.as_str()?.to_string())
|
Some(args.get(index)?.as_str()?.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_empty_str(args: &Vec<Value>, index: usize) -> String {
|
fn default_empty_str(args: &[Value], index: usize) -> String {
|
||||||
nullable_optional_str(args, index).unwrap_or("".into())
|
nullable_optional_str(args, index).unwrap_or("".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nullable_optional_number(args: &Vec<Value>, index: usize) -> Option<i64> {
|
fn nullable_optional_number(args: &[Value], index: usize) -> Option<i64> {
|
||||||
Some(args.get(index)?.as_i64()?)
|
args.get(index)?.as_i64()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_zero_number(args: &Vec<Value>, index: usize) -> i64 {
|
fn default_zero_number(args: &[Value], index: usize) -> i64 {
|
||||||
nullable_optional_number(args, index).unwrap_or(0)
|
nullable_optional_number(args, index).unwrap_or(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ impl Handler for NeovimHandler {
|
||||||
"ping" => Ok(Value::from("pong")),
|
"ping" => Ok(Value::from("pong")),
|
||||||
|
|
||||||
"create" => {
|
"create" => {
|
||||||
if args.len() < 1 {
|
if args.is_empty() {
|
||||||
return Err(Value::from("no path given"));
|
return Err(Value::from("no path given"));
|
||||||
}
|
}
|
||||||
let path = default_empty_str(&args, 0);
|
let path = default_empty_str(&args, 0);
|
||||||
|
@ -77,7 +77,7 @@ impl Handler for NeovimHandler {
|
||||||
}
|
}
|
||||||
let path = default_empty_str(&args, 0);
|
let path = default_empty_str(&args, 0);
|
||||||
let txt = default_empty_str(&args, 1);
|
let txt = default_empty_str(&args, 1);
|
||||||
let mut pos = default_zero_number(&args, 2) as i64;
|
let mut pos = default_zero_number(&args, 2);
|
||||||
|
|
||||||
if pos <= 0 { pos = 0 } // TODO wtf vim??
|
if pos <= 0 { pos = 0 } // TODO wtf vim??
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ impl Handler for NeovimHandler {
|
||||||
},
|
},
|
||||||
|
|
||||||
"attach" => {
|
"attach" => {
|
||||||
if args.len() < 1 {
|
if args.is_empty() {
|
||||||
return Err(Value::from("no path given"));
|
return Err(Value::from("no path given"));
|
||||||
}
|
}
|
||||||
let path = default_empty_str(&args, 0);
|
let path = default_empty_str(&args, 0);
|
||||||
|
@ -141,7 +141,7 @@ impl Handler for NeovimHandler {
|
||||||
Err(e) => Err(Value::from(format!("could not attach to stream: {}", e))),
|
Err(e) => Err(Value::from(format!("could not attach to stream: {}", e))),
|
||||||
Ok(controller) => {
|
Ok(controller) => {
|
||||||
let _controller = controller.clone();
|
let _controller = controller.clone();
|
||||||
let lines : Vec<String> = _controller.content().split("\n").map(|x| x.to_string()).collect();
|
let lines : Vec<String> = _controller.content().split('\n').map(|x| x.to_string()).collect();
|
||||||
match buffer.set_lines(0, -1, false, lines).await {
|
match buffer.set_lines(0, -1, false, lines).await {
|
||||||
Err(e) => Err(Value::from(format!("could not sync buffer: {}", e))),
|
Err(e) => Err(Value::from(format!("could not sync buffer: {}", e))),
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
|
@ -150,7 +150,7 @@ impl Handler for NeovimHandler {
|
||||||
if !_controller.run() { break debug!("buffer updater clean exit") }
|
if !_controller.run() { break debug!("buffer updater clean exit") }
|
||||||
let _span = _controller.wait().await;
|
let _span = _controller.wait().await;
|
||||||
// TODO only change lines affected!
|
// TODO only change lines affected!
|
||||||
let lines : Vec<String> = _controller.content().split("\n").map(|x| x.to_string()).collect();
|
let lines : Vec<String> = _controller.content().split('\n').map(|x| x.to_string()).collect();
|
||||||
if let Err(e) = buffer.set_lines(0, -1, false, lines).await {
|
if let Err(e) = buffer.set_lines(0, -1, false, lines).await {
|
||||||
error!("could not update buffer: {}", e);
|
error!("could not update buffer: {}", e);
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ impl Handler for NeovimHandler {
|
||||||
},
|
},
|
||||||
|
|
||||||
"detach" => {
|
"detach" => {
|
||||||
if args.len() < 1 {
|
if args.is_empty() {
|
||||||
return Err(Value::from("no path given"));
|
return Err(Value::from("no path given"));
|
||||||
}
|
}
|
||||||
let path = default_empty_str(&args, 0);
|
let path = default_empty_str(&args, 0);
|
||||||
|
@ -176,7 +176,7 @@ impl Handler for NeovimHandler {
|
||||||
},
|
},
|
||||||
|
|
||||||
"listen" => {
|
"listen" => {
|
||||||
if args.len() < 1 {
|
if args.is_empty() {
|
||||||
return Err(Value::from("no path given"));
|
return Err(Value::from("no path given"));
|
||||||
}
|
}
|
||||||
let path = default_empty_str(&args, 0);
|
let path = default_empty_str(&args, 0);
|
||||||
|
|
|
@ -61,14 +61,9 @@ impl Buffer for BufferService {
|
||||||
let (tx, rx) = mpsc::channel(128);
|
let (tx, rx) = mpsc::channel(128);
|
||||||
let mut sub = handle.subscribe();
|
let mut sub = handle.subscribe();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
loop {
|
while let Ok(v) = sub.recv().await {
|
||||||
match sub.recv().await {
|
if v.user == myself { continue }
|
||||||
Ok(v) => {
|
tx.send(Ok(v)).await.unwrap(); // TODO unnecessary channel?
|
||||||
if v.user == myself { continue }
|
|
||||||
tx.send(Ok(v)).await.unwrap(); // TODO unnecessary channel?
|
|
||||||
}
|
|
||||||
Err(_e) => break,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let output_stream = ReceiverStream::new(rx);
|
let output_stream = ReceiverStream::new(rx);
|
||||||
|
@ -83,14 +78,9 @@ impl Buffer for BufferService {
|
||||||
let myself = req.into_inner().user;
|
let myself = req.into_inner().user;
|
||||||
let (tx, rx) = mpsc::channel(128);
|
let (tx, rx) = mpsc::channel(128);
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
loop {
|
while let Ok(v) = sub.recv().await {
|
||||||
match sub.recv().await {
|
if v.user == myself { continue }
|
||||||
Ok(v) => {
|
tx.send(Ok(v)).await.unwrap(); // TODO unnecessary channel?
|
||||||
if v.user == myself { continue }
|
|
||||||
tx.send(Ok(v)).await.unwrap(); // TODO unnecessary channel?
|
|
||||||
}
|
|
||||||
Err(_e) => break,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let output_stream = ReceiverStream::new(rx);
|
let output_stream = ReceiverStream::new(rx);
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::proto::CursorMov;
|
||||||
|
|
||||||
/// Note that this differs from any hashmap in its put method: no &mut!
|
/// Note that this differs from any hashmap in its put method: no &mut!
|
||||||
pub trait CursorStorage {
|
pub trait CursorStorage {
|
||||||
fn get(&self, id: &String) -> Option<Cursor>;
|
fn get(&self, id: &str) -> Option<Cursor>;
|
||||||
fn put(&self, id: String, val: Cursor);
|
fn put(&self, id: String, val: Cursor);
|
||||||
|
|
||||||
fn update(&self, event: CursorMov) -> Option<Cursor> {
|
fn update(&self, event: CursorMov) -> Option<Cursor> {
|
||||||
|
@ -44,8 +44,8 @@ pub struct CursorController {
|
||||||
_bus_keepalive: Mutex<broadcast::Receiver<(String, Cursor)>>,
|
_bus_keepalive: Mutex<broadcast::Receiver<(String, Cursor)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CursorController {
|
impl Default for CursorController {
|
||||||
pub fn new() -> Self {
|
fn default() -> Self {
|
||||||
let (tx, _rx) = broadcast::channel(64);
|
let (tx, _rx) = broadcast::channel(64);
|
||||||
CursorController {
|
CursorController {
|
||||||
users: Mutex::new(HashMap::new()),
|
users: Mutex::new(HashMap::new()),
|
||||||
|
@ -53,6 +53,12 @@ impl CursorController {
|
||||||
_bus_keepalive: Mutex::new(_rx),
|
_bus_keepalive: Mutex::new(_rx),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CursorController {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
CursorController::default()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn sub(&self) -> broadcast::Receiver<(String, Cursor)> {
|
pub fn sub(&self) -> broadcast::Receiver<(String, Cursor)> {
|
||||||
self.bus.subscribe()
|
self.bus.subscribe()
|
||||||
|
@ -77,7 +83,7 @@ impl CursorStorage for CursorController {
|
||||||
Some(cur)
|
Some(cur)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get(&self, id: &String) -> Option<Cursor> {
|
fn get(&self, id: &str) -> Option<Cursor> {
|
||||||
Some(self.users.lock().unwrap().get(id)?.clone())
|
Some(self.users.lock().unwrap().get(id)?.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl OperationController {
|
||||||
|
|
||||||
pub async fn poll(&self) -> Option<OperationSeq> {
|
pub async fn poll(&self) -> Option<OperationSeq> {
|
||||||
let len = self.queue.lock().unwrap().len();
|
let len = self.queue.lock().unwrap().len();
|
||||||
if len <= 0 {
|
if len == 0 {
|
||||||
let mut recv = self.last.lock().unwrap().clone();
|
let mut recv = self.last.lock().unwrap().clone();
|
||||||
// TODO less jank way
|
// TODO less jank way
|
||||||
recv.changed().await.unwrap_or_warn("wairing for op changes #1"); // acknowledge current state
|
recv.changed().await.unwrap_or_warn("wairing for op changes #1"); // acknowledge current state
|
||||||
|
@ -80,7 +80,7 @@ impl OperationController {
|
||||||
async fn operation(&self, op: &OperationSeq) -> Result<Range<u64>, OTError> {
|
async fn operation(&self, op: &OperationSeq) -> Result<Range<u64>, OTError> {
|
||||||
let txt = self.content();
|
let txt = self.content();
|
||||||
let res = op.apply(&txt)?;
|
let res = op.apply(&txt)?;
|
||||||
*self.text.lock().unwrap() = res.clone();
|
*self.text.lock().unwrap() = res;
|
||||||
Ok(op_effective_range(op))
|
Ok(op_effective_range(op))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,10 +15,8 @@ pub const fn tailing_noop(seq: &[Operation]) -> u64 { count_noop(seq.last()) }
|
||||||
const fn count_noop(op: Option<&Operation>) -> u64 {
|
const fn count_noop(op: Option<&Operation>) -> u64 {
|
||||||
match op {
|
match op {
|
||||||
None => 0,
|
None => 0,
|
||||||
Some(op) => match op {
|
Some(Operation::Retain(n)) => *n,
|
||||||
Operation::Retain(n) => *n,
|
Some(_) => 0,
|
||||||
_ => 0,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue