fix: some tweaks to make rust-analyzer happy

stuff used to make sense but I changed some things below. Now I need to
redo my plumbing, but I don't want my language server going crazy.
This commit is contained in:
əlemi 2022-08-28 23:38:45 +02:00
parent 5bb535385b
commit 692c3f4977
3 changed files with 18 additions and 14 deletions

View file

@ -2,7 +2,10 @@ use operational_transform::OperationSeq;
use tokio::sync::{broadcast, mpsc, watch}; use tokio::sync::{broadcast, mpsc, watch};
use tracing::error; use tracing::error;
use crate::events::Event;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
/// A view of a buffer, with references to access value and send operations
pub struct BufferView { pub struct BufferView {
pub name: String, pub name: String,
pub content: watch::Receiver<String>, pub content: watch::Receiver<String>,
@ -30,7 +33,7 @@ impl Drop for Buffer {
} }
impl Buffer { impl Buffer {
pub fn new(name: String, bus: broadcast::Sender<(String, OperationSeq)>) -> Self { pub fn new(name: String, bus: broadcast::Sender<Event>) -> Self {
let (op_tx, mut op_rx) = mpsc::channel(32); let (op_tx, mut op_rx) = mpsc::channel(32);
let (stop_tx, stop_rx) = watch::channel(true); let (stop_tx, stop_rx) = watch::channel(true);
let (content_tx, content_rx) = watch::channel(String::new()); let (content_tx, content_rx) = watch::channel(String::new());
@ -50,7 +53,7 @@ impl Buffer {
// TODO handle these errors!! // TODO handle these errors!!
let op = op_rx.recv().await.unwrap(); let op = op_rx.recv().await.unwrap();
content = op.apply(content.as_str()).unwrap(); content = op.apply(content.as_str()).unwrap();
bus.send((name.clone(), op)).unwrap(); // TODO fails when there are no receivers subscribed // bus.send((name.clone(), op)).unwrap(); // TODO fails when there are no receivers subscribed
content_tx.send(content.clone()).unwrap(); content_tx.send(content.clone()).unwrap();
} }
}); });

View file

@ -7,22 +7,22 @@ use crate::actor::workspace::Workspace;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct UserCursor{ pub struct UserCursor{
// buffer: i64, pub buffer: i64,
// x: i32, pub x: i32,
// y: i32 pub y: i32
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct User { pub struct User {
// name: String, pub name: String,
// cursor: UserCursor, pub cursor: UserCursor,
} }
#[derive(Debug)] #[derive(Debug)]
pub enum AlterState { pub enum AlterState {
ADD { ADD {
key: String, key: String,
w: Workspace // w: Workspace
}, },
REMOVE { REMOVE {
key: String key: String
@ -63,9 +63,9 @@ impl StateManager {
while stop_rx.borrow().to_owned() { while stop_rx.borrow().to_owned() {
if let Some(event) = rx.recv().await { if let Some(event) = rx.recv().await {
match event { match event {
AlterState::ADD { key, w } => { AlterState::ADD { key/*, w */} => {
store.insert(key, Arc::new(w)); // TODO put in hashmap // store.insert(key, Arc::new(w)); // TODO put in hashmap
workspaces_tx.send(store.clone()).unwrap(); // workspaces_tx.send(store.clone()).unwrap();
}, },
AlterState::REMOVE { key } => { AlterState::REMOVE { key } => {
store.remove(&key); store.remove(&key);

View file

@ -23,6 +23,7 @@ use tonic::Streaming;
//use futures::{Stream, StreamExt}; //use futures::{Stream, StreamExt};
use crate::actor::{buffer::BufferView, state::StateManager}; use crate::actor::{buffer::BufferView, state::StateManager};
use crate::events::Event;
use self::proto::{BufferPayload, BufferResponse}; // TODO fuck x2! use self::proto::{BufferPayload, BufferResponse}; // TODO fuck x2!
@ -44,7 +45,7 @@ async fn buffer_worker(
bv: BufferView, bv: BufferView,
mut client_rx: Streaming<Operation>, mut client_rx: Streaming<Operation>,
tx_client: mpsc::Sender<Result<Operation, Status>>, tx_client: mpsc::Sender<Result<Operation, Status>>,
mut rx_core: broadcast::Receiver<(String, OperationSeq)>, mut rx_core: broadcast::Receiver<Event>,
) { ) {
let mut queue: VecDeque<Operation> = VecDeque::new(); let mut queue: VecDeque<Operation> = VecDeque::new();
loop { loop {
@ -77,7 +78,7 @@ async fn buffer_worker(
} }
} }
if send_op { if send_op {
tx_client.send(Ok(op_net(&oop.1))).await.unwrap(); // tx_client.send(Ok(op_net(&oop.1))).await.unwrap();
} }
} }
} }
@ -115,7 +116,7 @@ impl Buffer for BufferService {
let in_stream = req.into_inner(); let in_stream = req.into_inner();
let (tx_og, rx) = mpsc::channel::<Result<Operation, Status>>(128); let (tx_og, rx) = mpsc::channel::<Result<Operation, Status>>(128);
let b: BufferView = workspace.buffers_ref().get(&path).unwrap().clone(); let b: BufferView = workspace.buffers.borrow().get(&path).unwrap().clone();
let w = workspace.clone(); let w = workspace.clone();
tokio::spawn(async move { tokio::spawn(async move {
buffer_worker(b, in_stream, tx_og, w.bus.subscribe()).await; buffer_worker(b, in_stream, tx_og, w.bus.subscribe()).await;