fix: imports, Arc<T>

This commit is contained in:
əlemi 2023-08-11 15:50:17 +02:00
parent 98cae0969d
commit 8595d0c927
2 changed files with 10 additions and 26 deletions

View file

@ -5,7 +5,7 @@ use uuid::Uuid;
use crate::{ use crate::{
ControllerWorker, ControllerWorker,
cursor::tracker::{CursorTracker, CursorTrackerWorker}, cursor::tracker::{CursorTracker, CursorTrackerWorker},
buffer::controller::{OperationControllerHandle, OperationControllerEditor, OperationControllerWorker}, buffer::handle::{BufferHandle, OperationControllerEditor, OperationControllerWorker},
proto::{buffer_client::BufferClient, BufferPayload, RawOp, OperationRequest}, proto::{buffer_client::BufferClient, BufferPayload, RawOp, OperationRequest},
}; };
@ -62,7 +62,7 @@ impl BufferController {
Ok(handle) Ok(handle)
} }
pub async fn attach(&mut self, path: &str) -> Result<OperationControllerHandle, Status> { pub async fn attach(&mut self, path: &str) -> Result<BufferHandle, Status> {
let req = BufferPayload { let req = BufferPayload {
path: path.to_string(), path: path.to_string(),
content: None, content: None,

View file

@ -1,11 +1,11 @@
use std::{collections::BTreeMap, sync::Arc}; use std::{collections::BTreeMap, sync::Arc};
use tokio::sync::{RwLock, Mutex}; use tokio::sync::RwLock;
use tonic::async_trait;
use crate::{ use crate::{
buffer::{controller::BufferController, handle::OperationControllerEditor}, buffer::{controller::BufferController, handle::BufferHandle},
errors::CodempError, Controller, proto::Cursor, cursor::tracker::CursorTracker, cursor::tracker::CursorTracker,
errors::CodempError,
}; };
@ -25,14 +25,14 @@ pub mod instance {
} }
pub struct Workspace { pub struct Workspace {
client: CodempClient, client: BufferController,
buffers: RwLock<BTreeMap<Box<str>, BufferController>>, buffers: RwLock<BTreeMap<Box<str>, Arc<BufferHandle>>>,
cursor: Arc<CursorTracker>, cursor: Arc<CursorTracker>,
} }
impl Workspace { impl Workspace {
pub async fn new(dest: &str) -> Result<Self, CodempError> { pub async fn new(dest: &str) -> Result<Self, CodempError> {
let mut client = CodempClient::new(dest).await?; let mut client = BufferController::new(dest).await?;
let cursor = Arc::new(client.listen().await?); let cursor = Arc::new(client.listen().await?);
Ok( Ok(
Workspace { Workspace {
@ -49,7 +49,7 @@ impl Workspace {
} }
// Buffer // Buffer
pub async fn buffer(&self, path: &str) -> Option<BufferController> { pub async fn buffer(&self, path: &str) -> Option<Arc<BufferHandle>> {
self.buffers.read().await.get(path).cloned() self.buffers.read().await.get(path).cloned()
} }
@ -62,20 +62,4 @@ impl Workspace {
self.buffers.write().await.insert(path.into(), Arc::new(controller)); self.buffers.write().await.insert(path.into(), Arc::new(controller));
Ok(()) Ok(())
} }
// pub async fn diff(&self, path: &str, span: Range<usize>, text: &str) {
// if let Some(controller) = self.inner.read().await.buffers.get(path) {
// if let Some(op) = controller.delta(span.start, text, span.end) {
// controller.apply(op).await
// }
// }
// }
// async fn send(&self, path: &str, start: (i32, i32), end: (i32, i32)) {
// self.inner.read().await.cursor.send(path, start.into(), end.into()).await
// }
// pub async fn recv(&self) -> Option<Cursor> {
// self.inner.write().await.cursor.poll().await
// }
} }