mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 15:24:48 +01:00
fix: removed instance module, fixed prelude
This commit is contained in:
parent
4c738e726c
commit
f7bd5849be
6 changed files with 22 additions and 47 deletions
|
@ -40,4 +40,3 @@ client = ["transport", "api", "dep:tokio", "dep:tokio-stream", "dep:uuid", "d
|
||||||
server = ["transport"]
|
server = ["transport"]
|
||||||
global = ["client", "dep:lazy_static"]
|
global = ["client", "dep:lazy_static"]
|
||||||
sync = ["client"]
|
sync = ["client"]
|
||||||
backport = [] # TODO remove!
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
//!
|
//!
|
||||||
//! codemp client manager, containing grpc services
|
//! codemp client manager, containing grpc services
|
||||||
|
|
||||||
|
use std::collections::BTreeMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tonic::service::interceptor::InterceptedService;
|
use tonic::service::interceptor::InterceptedService;
|
||||||
|
@ -25,7 +26,7 @@ use crate::workspace::Workspace;
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
user_id: Uuid,
|
user_id: Uuid,
|
||||||
token_tx: Arc<tokio::sync::watch::Sender<Token>>,
|
token_tx: Arc<tokio::sync::watch::Sender<Token>>,
|
||||||
workspace: Option<Workspace>,
|
pub workspaces: BTreeMap<String, Workspace>,
|
||||||
services: Arc<Services>
|
services: Arc<Services>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +84,7 @@ impl Client {
|
||||||
Ok(Client {
|
Ok(Client {
|
||||||
user_id,
|
user_id,
|
||||||
token_tx: Arc::new(token_tx),
|
token_tx: Arc::new(token_tx),
|
||||||
workspace: None,
|
workspaces: BTreeMap::new(),
|
||||||
services: Arc::new(Services { workspace, buffer, cursor })
|
services: Arc::new(Services { workspace, buffer, cursor })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -111,7 +112,7 @@ impl Client {
|
||||||
tracing::debug!("controller worker stopped");
|
tracing::debug!("controller worker stopped");
|
||||||
});
|
});
|
||||||
|
|
||||||
self.workspace = Some(Workspace::new(
|
self.workspaces.insert(workspace_id.to_string(), Workspace::new(
|
||||||
workspace_id.to_string(),
|
workspace_id.to_string(),
|
||||||
self.user_id,
|
self.user_id,
|
||||||
self.token_tx.clone(),
|
self.token_tx.clone(),
|
||||||
|
@ -121,4 +122,8 @@ impl Client {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn user_id(&self) -> Uuid {
|
||||||
|
self.user_id.clone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ impl Controller<CursorEvent> for CursorController {
|
||||||
/// enqueue a cursor event to be broadcast to current workspace
|
/// enqueue a cursor event to be broadcast to current workspace
|
||||||
/// will automatically invert cursor start/end if they are inverted
|
/// will automatically invert cursor start/end if they are inverted
|
||||||
fn send(&self, mut cursor: CursorPosition) -> crate::Result<()> {
|
fn send(&self, mut cursor: CursorPosition) -> crate::Result<()> {
|
||||||
if cursor.start() > cursor.end() {
|
if cursor.start > cursor.end {
|
||||||
std::mem::swap(&mut cursor.start, &mut cursor.end);
|
std::mem::swap(&mut cursor.start, &mut cursor.end);
|
||||||
}
|
}
|
||||||
Ok(self.op.send(CursorEvent {
|
Ok(self.op.send(CursorEvent {
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub mod controller;
|
||||||
|
|
||||||
pub use controller::CursorController as Controller;
|
pub use controller::CursorController as Controller;
|
||||||
|
|
||||||
use crate::proto::cursor::{RowCol, CursorPosition};
|
use crate::proto::cursor::RowCol;
|
||||||
|
|
||||||
impl From::<RowCol> for (i32, i32) {
|
impl From::<RowCol> for (i32, i32) {
|
||||||
fn from(pos: RowCol) -> (i32, i32) {
|
fn from(pos: RowCol) -> (i32, i32) {
|
||||||
|
@ -26,25 +26,6 @@ impl From::<(i32, i32)> for RowCol {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RowCol {
|
|
||||||
/// create a RowCol and wrap into an Option, to help build protocol packets
|
|
||||||
pub fn wrap(row: i32, col: i32) -> Option<RowCol> {
|
|
||||||
Some(RowCol { row, col })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CursorPosition {
|
|
||||||
/// extract start position, defaulting to (0,0), to help build protocol packets
|
|
||||||
pub fn start(&self) -> RowCol {
|
|
||||||
self.start.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// extract end position, defaulting to (0,0), to help build protocol packets
|
|
||||||
pub fn end(&self) -> RowCol {
|
|
||||||
self.end.clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialOrd for RowCol {
|
impl PartialOrd for RowCol {
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||||
match self.row.partial_cmp(&other.row) {
|
match self.row.partial_cmp(&other.row) {
|
||||||
|
|
15
src/lib.rs
15
src/lib.rs
|
@ -148,12 +148,11 @@ pub mod errors;
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
pub mod client;
|
pub mod client;
|
||||||
|
|
||||||
|
/// assorted helpers
|
||||||
pub mod tools;
|
pub mod tools;
|
||||||
|
|
||||||
/// client wrapper to handle memory persistence
|
/// workspace operations
|
||||||
#[cfg(feature = "backport")]
|
#[cfg(feature = "client")]
|
||||||
pub mod instance;
|
|
||||||
|
|
||||||
pub mod workspace;
|
pub mod workspace;
|
||||||
|
|
||||||
/// all-in-one imports : `use codemp::prelude::*;`
|
/// all-in-one imports : `use codemp::prelude::*;`
|
||||||
|
@ -176,13 +175,5 @@ pub mod proto {
|
||||||
pub mod workspace_service { tonic::include_proto!("workspace_service"); }
|
pub mod workspace_service { tonic::include_proto!("workspace_service"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub use errors::Error;
|
pub use errors::Error;
|
||||||
pub use errors::Result;
|
pub use errors::Result;
|
||||||
|
|
||||||
#[cfg(all(feature = "client", feature = "sync"))]
|
|
||||||
pub use instance::sync::Instance;
|
|
||||||
|
|
||||||
#[cfg(all(feature = "backport", not(feature = "sync")))]
|
|
||||||
pub use instance::a_sync::Instance;
|
|
||||||
|
|
||||||
|
|
|
@ -20,16 +20,15 @@ pub use crate::api::{
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
// Instance as CodempInstance,
|
// Instance as CodempInstance,
|
||||||
client::Client as CodempClient,
|
client::Client as CodempClient,
|
||||||
|
workspace::Workspace as CodempWorkspace,
|
||||||
|
workspace::UserInfo as CodempUserInfo,
|
||||||
cursor::Controller as CodempCursorController,
|
cursor::Controller as CodempCursorController,
|
||||||
// buffer::Controller as CodempBufferController,
|
buffer::Controller as CodempBufferController,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "proto")]
|
#[cfg(feature = "transport")]
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
proto::CursorPosition as CodempCursorPosition,
|
proto::cursor::CursorPosition as CodempCursorPosition,
|
||||||
proto::CursorEvent as CodempCursorEvent,
|
proto::cursor::CursorEvent as CodempCursorEvent,
|
||||||
proto::RowCol as CodempRowCol,
|
proto::cursor::RowCol as CodempRowCol,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "global")]
|
|
||||||
pub use crate::instance::global::INSTANCE as CODEMP_INSTANCE;
|
|
||||||
|
|
Loading…
Reference in a new issue