mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-21 23:04:49 +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>>>>,
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
|
||||
fn nullable_optional_number(args: &Vec<Value>, index: usize) -> Option<i64> {
|
||||
Some(args.get(index)?.as_i64()?)
|
||||
fn nullable_optional_number(args: &[Value], index: usize) -> Option<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)
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ impl Handler for NeovimHandler {
|
|||
"ping" => Ok(Value::from("pong")),
|
||||
|
||||
"create" => {
|
||||
if args.len() < 1 {
|
||||
if args.is_empty() {
|
||||
return Err(Value::from("no path given"));
|
||||
}
|
||||
let path = default_empty_str(&args, 0);
|
||||
|
@ -77,7 +77,7 @@ impl Handler for NeovimHandler {
|
|||
}
|
||||
let path = default_empty_str(&args, 0);
|
||||
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??
|
||||
|
||||
|
@ -126,7 +126,7 @@ impl Handler for NeovimHandler {
|
|||
},
|
||||
|
||||
"attach" => {
|
||||
if args.len() < 1 {
|
||||
if args.is_empty() {
|
||||
return Err(Value::from("no path given"));
|
||||
}
|
||||
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))),
|
||||
Ok(controller) => {
|
||||
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 {
|
||||
Err(e) => Err(Value::from(format!("could not sync buffer: {}", e))),
|
||||
Ok(()) => {
|
||||
|
@ -150,7 +150,7 @@ impl Handler for NeovimHandler {
|
|||
if !_controller.run() { break debug!("buffer updater clean exit") }
|
||||
let _span = _controller.wait().await;
|
||||
// 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 {
|
||||
error!("could not update buffer: {}", e);
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ impl Handler for NeovimHandler {
|
|||
},
|
||||
|
||||
"detach" => {
|
||||
if args.len() < 1 {
|
||||
if args.is_empty() {
|
||||
return Err(Value::from("no path given"));
|
||||
}
|
||||
let path = default_empty_str(&args, 0);
|
||||
|
@ -176,7 +176,7 @@ impl Handler for NeovimHandler {
|
|||
},
|
||||
|
||||
"listen" => {
|
||||
if args.len() < 1 {
|
||||
if args.is_empty() {
|
||||
return Err(Value::from("no path given"));
|
||||
}
|
||||
let path = default_empty_str(&args, 0);
|
||||
|
|
|
@ -61,14 +61,9 @@ impl Buffer for BufferService {
|
|||
let (tx, rx) = mpsc::channel(128);
|
||||
let mut sub = handle.subscribe();
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
match sub.recv().await {
|
||||
Ok(v) => {
|
||||
if v.user == myself { continue }
|
||||
tx.send(Ok(v)).await.unwrap(); // TODO unnecessary channel?
|
||||
}
|
||||
Err(_e) => break,
|
||||
}
|
||||
while let Ok(v) = sub.recv().await {
|
||||
if v.user == myself { continue }
|
||||
tx.send(Ok(v)).await.unwrap(); // TODO unnecessary channel?
|
||||
}
|
||||
});
|
||||
let output_stream = ReceiverStream::new(rx);
|
||||
|
@ -83,14 +78,9 @@ impl Buffer for BufferService {
|
|||
let myself = req.into_inner().user;
|
||||
let (tx, rx) = mpsc::channel(128);
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
match sub.recv().await {
|
||||
Ok(v) => {
|
||||
if v.user == myself { continue }
|
||||
tx.send(Ok(v)).await.unwrap(); // TODO unnecessary channel?
|
||||
}
|
||||
Err(_e) => break,
|
||||
}
|
||||
while let Ok(v) = sub.recv().await {
|
||||
if v.user == myself { continue }
|
||||
tx.send(Ok(v)).await.unwrap(); // TODO unnecessary channel?
|
||||
}
|
||||
});
|
||||
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!
|
||||
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 update(&self, event: CursorMov) -> Option<Cursor> {
|
||||
|
@ -44,8 +44,8 @@ pub struct CursorController {
|
|||
_bus_keepalive: Mutex<broadcast::Receiver<(String, Cursor)>>,
|
||||
}
|
||||
|
||||
impl CursorController {
|
||||
pub fn new() -> Self {
|
||||
impl Default for CursorController {
|
||||
fn default() -> Self {
|
||||
let (tx, _rx) = broadcast::channel(64);
|
||||
CursorController {
|
||||
users: Mutex::new(HashMap::new()),
|
||||
|
@ -53,6 +53,12 @@ impl CursorController {
|
|||
_bus_keepalive: Mutex::new(_rx),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CursorController {
|
||||
pub fn new() -> Self {
|
||||
CursorController::default()
|
||||
}
|
||||
|
||||
pub fn sub(&self) -> broadcast::Receiver<(String, Cursor)> {
|
||||
self.bus.subscribe()
|
||||
|
@ -77,7 +83,7 @@ impl CursorStorage for CursorController {
|
|||
Some(cur)
|
||||
}
|
||||
|
||||
fn get(&self, id: &String) -> Option<Cursor> {
|
||||
fn get(&self, id: &str) -> Option<Cursor> {
|
||||
Some(self.users.lock().unwrap().get(id)?.clone())
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ impl OperationController {
|
|||
|
||||
pub async fn poll(&self) -> Option<OperationSeq> {
|
||||
let len = self.queue.lock().unwrap().len();
|
||||
if len <= 0 {
|
||||
if len == 0 {
|
||||
let mut recv = self.last.lock().unwrap().clone();
|
||||
// TODO less jank way
|
||||
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> {
|
||||
let txt = self.content();
|
||||
let res = op.apply(&txt)?;
|
||||
*self.text.lock().unwrap() = res.clone();
|
||||
*self.text.lock().unwrap() = res;
|
||||
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 {
|
||||
match op {
|
||||
None => 0,
|
||||
Some(op) => match op {
|
||||
Operation::Retain(n) => *n,
|
||||
_ => 0,
|
||||
}
|
||||
Some(Operation::Retain(n)) => *n,
|
||||
Some(_) => 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue