mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-22 23:44:55 +01:00
feat: actually report true accepted status
This commit is contained in:
parent
365811d963
commit
975a082262
2 changed files with 23 additions and 16 deletions
|
@ -1,5 +1,5 @@
|
||||||
use codemp::proto::{RawOp, OperationRequest};
|
use codemp::{proto::{RawOp, OperationRequest}, errors::IgnorableError};
|
||||||
use tokio::sync::{mpsc, broadcast, watch};
|
use tokio::sync::{mpsc, broadcast, watch, oneshot};
|
||||||
use tracing::{error, warn};
|
use tracing::{error, warn};
|
||||||
// use md5::Digest;
|
// use md5::Digest;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ pub trait BufferStore<T> {
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct BufferHandle {
|
pub struct BufferHandle {
|
||||||
pub edit: mpsc::Sender<OperationRequest>,
|
pub edit: mpsc::Sender<(oneshot::Sender<bool>, OperationRequest)>,
|
||||||
events: broadcast::Sender<RawOp>,
|
events: broadcast::Sender<RawOp>,
|
||||||
// pub digest: watch::Receiver<Digest>,
|
// pub digest: watch::Receiver<Digest>,
|
||||||
pub content: watch::Receiver<String>,
|
pub content: watch::Receiver<String>,
|
||||||
|
@ -59,7 +59,7 @@ impl BufferHandle {
|
||||||
|
|
||||||
struct BufferWorker {
|
struct BufferWorker {
|
||||||
store: String,
|
store: String,
|
||||||
edits: mpsc::Receiver<OperationRequest>,
|
edits: mpsc::Receiver<(oneshot::Sender<bool>, OperationRequest)>,
|
||||||
events: broadcast::Sender<RawOp>,
|
events: broadcast::Sender<RawOp>,
|
||||||
// digest: watch::Sender<Digest>,
|
// digest: watch::Sender<Digest>,
|
||||||
content: watch::Sender<String>,
|
content: watch::Sender<String>,
|
||||||
|
@ -70,10 +70,16 @@ impl BufferWorker {
|
||||||
loop {
|
loop {
|
||||||
match self.edits.recv().await {
|
match self.edits.recv().await {
|
||||||
None => break warn!("channel closed"),
|
None => break warn!("channel closed"),
|
||||||
Some(v) => match serde_json::from_str::<OperationSeq>(&v.opseq) {
|
Some((ack, v)) => match serde_json::from_str::<OperationSeq>(&v.opseq) {
|
||||||
Err(e) => break error!("could not deserialize opseq: {}", e),
|
Err(e) => {
|
||||||
|
ack.send(false).unwrap_or_warn("could not reject undeserializable opseq");
|
||||||
|
error!("could not deserialize opseq: {}", e);
|
||||||
|
},
|
||||||
Ok(op) => match op.apply(&self.store) {
|
Ok(op) => match op.apply(&self.store) {
|
||||||
Err(e) => error!("coult not apply OpSeq '{:?}' on '{}' : {}", v, self.store, e), // TODO
|
Err(e) => {
|
||||||
|
ack.send(false).unwrap_or_warn("could not reject unappliable opseq");
|
||||||
|
error!("coult not apply OpSeq '{:?}' on '{}' : {}", v, self.store, e); // TODO
|
||||||
|
}
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
self.store = res;
|
self.store = res;
|
||||||
let msg = RawOp {
|
let msg = RawOp {
|
||||||
|
@ -83,12 +89,9 @@ impl BufferWorker {
|
||||||
// if let Err(e) = self.digest.send(md5::compute(&self.store)) {
|
// if let Err(e) = self.digest.send(md5::compute(&self.store)) {
|
||||||
// error!("could not update digest: {}", e);
|
// error!("could not update digest: {}", e);
|
||||||
// }
|
// }
|
||||||
if let Err(e) = self.content.send(self.store.clone()) {
|
ack.send(true).unwrap_or_warn("could not accept opseq");
|
||||||
error!("could not update content: {}", e);
|
self.content.send(self.store.clone()).unwrap_or_warn("could not update content");
|
||||||
}
|
self.events.send(msg).unwrap_or_warn("could not broadcast OpSeq");
|
||||||
if let Err(e) = self.events.send(msg) {
|
|
||||||
error!("could not broadcast OpSeq: {}", e);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{pin::Pin, sync::{Arc, RwLock}, collections::HashMap};
|
use std::{pin::Pin, sync::{Arc, RwLock}, collections::HashMap};
|
||||||
|
|
||||||
use tokio::sync::{mpsc, broadcast};
|
use tokio::sync::{mpsc, broadcast, oneshot};
|
||||||
use tonic::{Request, Response, Status};
|
use tonic::{Request, Response, Status};
|
||||||
|
|
||||||
use tokio_stream::{Stream, wrappers::ReceiverStream}; // TODO example used this?
|
use tokio_stream::{Stream, wrappers::ReceiverStream}; // TODO example used this?
|
||||||
|
@ -107,9 +107,13 @@ impl Buffer for BufferService {
|
||||||
None => return Err(Status::not_found("path not found")),
|
None => return Err(Status::not_found("path not found")),
|
||||||
};
|
};
|
||||||
info!("sending edit to buffer: {}", request.opseq);
|
info!("sending edit to buffer: {}", request.opseq);
|
||||||
match tx.send(request).await {
|
let (ack, status) = oneshot::channel();
|
||||||
Ok(()) => Ok(Response::new(BufferResponse { accepted: true, content: None })),
|
match tx.send((ack, request)).await {
|
||||||
Err(e) => Err(Status::internal(format!("error sending edit to buffer actor: {}", e))),
|
Err(e) => Err(Status::internal(format!("error sending edit to buffer actor: {}", e))),
|
||||||
|
Ok(()) => Ok(Response::new(BufferResponse {
|
||||||
|
accepted: status.await.unwrap_or(false),
|
||||||
|
content: None
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue