mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 07:14:50 +01:00
fix: inaccessible fields, pub(crate) constructor
This commit is contained in:
parent
c20cbde833
commit
b8578a89a4
6 changed files with 34 additions and 16 deletions
|
@ -13,6 +13,16 @@ pub struct BufferController {
|
||||||
stream: Mutex<broadcast::Receiver<OperationSeq>>,
|
stream: Mutex<broadcast::Receiver<OperationSeq>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl BufferController {
|
||||||
|
pub(crate) fn new(
|
||||||
|
content: watch::Receiver<String>,
|
||||||
|
operations: mpsc::Sender<OperationSeq>,
|
||||||
|
stream: Mutex<broadcast::Receiver<OperationSeq>>,
|
||||||
|
) -> Self {
|
||||||
|
BufferController { content, operations, stream }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl OperationFactory for BufferController {
|
impl OperationFactory for BufferController {
|
||||||
fn content(&self) -> String {
|
fn content(&self) -> String {
|
||||||
|
|
|
@ -51,11 +51,11 @@ impl ControllerWorker<TextChange> for BufferControllerWorker {
|
||||||
type Rx = Streaming<RawOp>;
|
type Rx = Streaming<RawOp>;
|
||||||
|
|
||||||
fn subscribe(&self) -> BufferController {
|
fn subscribe(&self) -> BufferController {
|
||||||
BufferController {
|
BufferController::new(
|
||||||
content: self.receiver.clone(),
|
self.receiver.clone(),
|
||||||
operations: self.sender.clone(),
|
self.sender.clone(),
|
||||||
stream: Mutex::new(self.stream.subscribe()),
|
Mutex::new(self.stream.subscribe()),
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn work(mut self, mut tx: Self::Tx, mut rx: Self::Rx) {
|
async fn work(mut self, mut tx: Self::Tx, mut rx: Self::Rx) {
|
||||||
|
|
|
@ -38,11 +38,11 @@ impl CodempClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_cursor(&self) -> Option<Arc<CursorController>> {
|
pub fn get_cursor(&self) -> Option<Arc<CursorController>> {
|
||||||
Some(self.workspace?.cursor.clone())
|
Some(self.workspace.as_ref()?.cursor.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_buffer(&self, path: &str) -> Option<Arc<BufferController>> {
|
pub fn get_buffer(&self, path: &str) -> Option<Arc<BufferController>> {
|
||||||
self.workspace?.buffers.get(path).cloned()
|
self.workspace.as_ref()?.buffers.get(path).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn join(&mut self, _session: &str) -> Result<Arc<CursorController>, CodempError> {
|
pub async fn join(&mut self, _session: &str) -> Result<Arc<CursorController>, CodempError> {
|
||||||
|
@ -72,7 +72,7 @@ impl CodempClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create(&mut self, path: &str, content: Option<&str>) -> Result<(), CodempError> {
|
pub async fn create(&mut self, path: &str, content: Option<&str>) -> Result<(), CodempError> {
|
||||||
if let Some(workspace) = &self.workspace {
|
if let Some(_workspace) = &self.workspace {
|
||||||
self.client.buffer
|
self.client.buffer
|
||||||
.create(BufferPayload {
|
.create(BufferPayload {
|
||||||
user: self.id.clone(),
|
user: self.id.clone(),
|
||||||
|
@ -86,7 +86,7 @@ impl CodempClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn attach(&mut self, path: &str, content: Option<&str>) -> Result<Arc<BufferController>, CodempError> {
|
pub async fn attach(&mut self, path: &str) -> Result<Arc<BufferController>, CodempError> {
|
||||||
if let Some(workspace) = &mut self.workspace {
|
if let Some(workspace) = &mut self.workspace {
|
||||||
let mut client = self.client.buffer.clone();
|
let mut client = self.client.buffer.clone();
|
||||||
let req = BufferPayload {
|
let req = BufferPayload {
|
||||||
|
|
|
@ -9,6 +9,16 @@ pub struct CursorController {
|
||||||
stream: Mutex<broadcast::Receiver<CursorEvent>>,
|
stream: Mutex<broadcast::Receiver<CursorEvent>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl CursorController {
|
||||||
|
pub(crate) fn new(
|
||||||
|
uid: String,
|
||||||
|
op: mpsc::Sender<CursorEvent>,
|
||||||
|
stream: Mutex<broadcast::Receiver<CursorEvent>>
|
||||||
|
) -> Self {
|
||||||
|
CursorController { uid, op, stream }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Controller<CursorEvent> for CursorController {
|
impl Controller<CursorEvent> for CursorController {
|
||||||
type Input = CursorPosition;
|
type Input = CursorPosition;
|
||||||
|
|
|
@ -34,11 +34,11 @@ impl ControllerWorker<CursorEvent> for CursorControllerWorker {
|
||||||
type Rx = Streaming<CursorEvent>;
|
type Rx = Streaming<CursorEvent>;
|
||||||
|
|
||||||
fn subscribe(&self) -> CursorController {
|
fn subscribe(&self) -> CursorController {
|
||||||
CursorController {
|
CursorController::new(
|
||||||
uid: self.uid.clone(),
|
self.uid.clone(),
|
||||||
op: self.producer.clone(),
|
self.producer.clone(),
|
||||||
stream: Mutex::new(self.channel.subscribe()),
|
Mutex::new(self.channel.subscribe())
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn work(mut self, mut tx: Self::Tx, mut rx: Self::Rx) {
|
async fn work(mut self, mut tx: Self::Tx, mut rx: Self::Rx) {
|
||||||
|
|
|
@ -10,8 +10,6 @@ use crate::{
|
||||||
|
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
|
|
||||||
const CODEMP_DEFAULT_HOST : &str = "http://alemi.dev:50051";
|
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref RUNTIME : Runtime = Runtime::new().expect("could not create tokio runtime");
|
static ref RUNTIME : Runtime = Runtime::new().expect("could not create tokio runtime");
|
||||||
static ref INSTANCE : Instance = Instance::default();
|
static ref INSTANCE : Instance = Instance::default();
|
||||||
|
|
Loading…
Reference in a new issue