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"]
|
||||
global = ["client", "dep:lazy_static"]
|
||||
sync = ["client"]
|
||||
backport = [] # TODO remove!
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
//!
|
||||
//! codemp client manager, containing grpc services
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::mpsc;
|
||||
use tonic::service::interceptor::InterceptedService;
|
||||
|
@ -25,7 +26,7 @@ use crate::workspace::Workspace;
|
|||
pub struct Client {
|
||||
user_id: Uuid,
|
||||
token_tx: Arc<tokio::sync::watch::Sender<Token>>,
|
||||
workspace: Option<Workspace>,
|
||||
pub workspaces: BTreeMap<String, Workspace>,
|
||||
services: Arc<Services>
|
||||
}
|
||||
|
||||
|
@ -83,7 +84,7 @@ impl Client {
|
|||
Ok(Client {
|
||||
user_id,
|
||||
token_tx: Arc::new(token_tx),
|
||||
workspace: None,
|
||||
workspaces: BTreeMap::new(),
|
||||
services: Arc::new(Services { workspace, buffer, cursor })
|
||||
})
|
||||
}
|
||||
|
@ -111,7 +112,7 @@ impl Client {
|
|||
tracing::debug!("controller worker stopped");
|
||||
});
|
||||
|
||||
self.workspace = Some(Workspace::new(
|
||||
self.workspaces.insert(workspace_id.to_string(), Workspace::new(
|
||||
workspace_id.to_string(),
|
||||
self.user_id,
|
||||
self.token_tx.clone(),
|
||||
|
@ -121,4 +122,8 @@ impl Client {
|
|||
|
||||
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
|
||||
/// will automatically invert cursor start/end if they are inverted
|
||||
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);
|
||||
}
|
||||
Ok(self.op.send(CursorEvent {
|
||||
|
|
|
@ -12,7 +12,7 @@ pub mod controller;
|
|||
|
||||
pub use controller::CursorController as Controller;
|
||||
|
||||
use crate::proto::cursor::{RowCol, CursorPosition};
|
||||
use crate::proto::cursor::RowCol;
|
||||
|
||||
impl From::<RowCol> for (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 {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
match self.row.partial_cmp(&other.row) {
|
||||
|
|
17
src/lib.rs
17
src/lib.rs
|
@ -148,12 +148,11 @@ pub mod errors;
|
|||
#[cfg(feature = "client")]
|
||||
pub mod client;
|
||||
|
||||
/// assorted helpers
|
||||
pub mod tools;
|
||||
|
||||
/// client wrapper to handle memory persistence
|
||||
#[cfg(feature = "backport")]
|
||||
pub mod instance;
|
||||
|
||||
/// workspace operations
|
||||
#[cfg(feature = "client")]
|
||||
pub mod workspace;
|
||||
|
||||
/// all-in-one imports : `use codemp::prelude::*;`
|
||||
|
@ -176,13 +175,5 @@ pub mod proto {
|
|||
pub mod workspace_service { tonic::include_proto!("workspace_service"); }
|
||||
}
|
||||
|
||||
|
||||
pub use errors::Error;
|
||||
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;
|
||||
|
||||
pub use errors::Result;
|
|
@ -20,16 +20,15 @@ pub use crate::api::{
|
|||
pub use crate::{
|
||||
// Instance as CodempInstance,
|
||||
client::Client as CodempClient,
|
||||
workspace::Workspace as CodempWorkspace,
|
||||
workspace::UserInfo as CodempUserInfo,
|
||||
cursor::Controller as CodempCursorController,
|
||||
// buffer::Controller as CodempBufferController,
|
||||
buffer::Controller as CodempBufferController,
|
||||
};
|
||||
|
||||
#[cfg(feature = "proto")]
|
||||
#[cfg(feature = "transport")]
|
||||
pub use crate::{
|
||||
proto::CursorPosition as CodempCursorPosition,
|
||||
proto::CursorEvent as CodempCursorEvent,
|
||||
proto::RowCol as CodempRowCol,
|
||||
};
|
||||
|
||||
#[cfg(feature = "global")]
|
||||
pub use crate::instance::global::INSTANCE as CODEMP_INSTANCE;
|
||||
proto::cursor::CursorPosition as CodempCursorPosition,
|
||||
proto::cursor::CursorEvent as CodempCursorEvent,
|
||||
proto::cursor::RowCol as CodempRowCol,
|
||||
};
|
Loading…
Reference in a new issue