mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 07:14:50 +01:00
chore: moved stuff into a common library
This commit is contained in:
parent
e9500afd55
commit
f596df73c4
10 changed files with 44 additions and 34 deletions
|
@ -7,6 +7,10 @@ edition = "2021"
|
||||||
default = ["nvim"]
|
default = ["nvim"]
|
||||||
nvim = []
|
nvim = []
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "library"
|
||||||
|
path = "src/lib/lib.rs"
|
||||||
|
|
||||||
[[bin]] # Bin to run the CodeMP gRPC server
|
[[bin]] # Bin to run the CodeMP gRPC server
|
||||||
name = "server"
|
name = "server"
|
||||||
path = "src/server/main.rs"
|
path = "src/server/main.rs"
|
||||||
|
@ -27,6 +31,7 @@ rmpv = "1"
|
||||||
operational-transform = "0.6"
|
operational-transform = "0.6"
|
||||||
nvim-rs = { version = "0.4", features = ["use_tokio"] } # TODO put this behind a conditional feature
|
nvim-rs = { version = "0.4", features = ["use_tokio"] } # TODO put this behind a conditional feature
|
||||||
uuid = { version = "1", features = ["v4", "fast-rng", "macro-diagnostics"] }
|
uuid = { version = "1", features = ["v4", "fast-rng", "macro-diagnostics"] }
|
||||||
|
rand = "0.8.5"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
tonic-build = "0.7"
|
tonic-build = "0.7"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use crate::actor::state::User;
|
use crate::user::User;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Event {
|
pub enum Event {
|
2
src/lib/lib.rs
Normal file
2
src/lib/lib.rs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
pub mod events;
|
||||||
|
pub mod user;
|
27
src/lib/user.rs
Normal file
27
src/lib/user.rs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct UserCursor{
|
||||||
|
pub buffer: i64,
|
||||||
|
pub x: i64,
|
||||||
|
pub y: i64
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for UserCursor {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "Cursor(buffer:{}, x:{}, y:{})", self.buffer, self.x, self.y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct User {
|
||||||
|
pub name: String,
|
||||||
|
pub cursor: UserCursor,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for User {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "User(name:{}, cursor:{})", self.name, self.cursor)
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,7 @@ 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;
|
use library::events::Event;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
/// A view of a buffer, with references to access value and send operations
|
/// A view of a buffer, with references to access value and send operations
|
||||||
|
|
|
@ -5,32 +5,6 @@ use tracing::error;
|
||||||
|
|
||||||
use crate::actor::workspace::Workspace;
|
use crate::actor::workspace::Workspace;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct UserCursor{
|
|
||||||
pub buffer: i32,
|
|
||||||
pub x: i32,
|
|
||||||
pub y: i32
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for UserCursor {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
write!(f, "Cursor(buffer:{}, x:{}, y:{})", self.buffer, self.x, self.y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct User {
|
|
||||||
pub name: String,
|
|
||||||
pub cursor: UserCursor,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for User {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
write!(f, "User(name:{}, cursor:{})", self.name, self.cursor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum WorkspaceAction {
|
enum WorkspaceAction {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::collections::HashMap;
|
||||||
use tokio::sync::{broadcast, mpsc, watch::{self, Ref}};
|
use tokio::sync::{broadcast, mpsc, watch::{self, Ref}};
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
use crate::{events::Event, service::workspace::proto::CursorUpdate};
|
use library::{events::Event, user::{User, UserCursor}};
|
||||||
|
|
||||||
use super::{buffer::{BufferView, Buffer}, state::{User, UserCursor}};
|
use super::{buffer::{BufferView, Buffer}, state::{User, UserCursor}};
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
//!
|
//!
|
||||||
|
|
||||||
pub mod actor;
|
pub mod actor;
|
||||||
pub mod events;
|
|
||||||
pub mod service;
|
pub mod service;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
|
@ -11,6 +11,8 @@ pub mod proto {
|
||||||
tonic::include_proto!("buffer");
|
tonic::include_proto!("buffer");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use library::events::Event;
|
||||||
|
|
||||||
use tokio::sync::{broadcast, mpsc};
|
use tokio::sync::{broadcast, mpsc};
|
||||||
use tokio_stream::{Stream, StreamExt}; // TODO example used this?
|
use tokio_stream::{Stream, StreamExt}; // TODO example used this?
|
||||||
|
|
||||||
|
@ -21,7 +23,6 @@ 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!
|
||||||
|
|
||||||
|
|
|
@ -12,13 +12,15 @@ pub mod proto {
|
||||||
tonic::include_proto!("workspace");
|
tonic::include_proto!("workspace");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use library::user::User;
|
||||||
|
|
||||||
use tokio_stream::{Stream, StreamExt}; // TODO example used this?
|
use tokio_stream::{Stream, StreamExt}; // TODO example used this?
|
||||||
|
|
||||||
use proto::workspace_server::{Workspace, WorkspaceServer};
|
use proto::workspace_server::{Workspace, WorkspaceServer};
|
||||||
use proto::{BufferList, WorkspaceEvent, WorkspaceRequest, WorkspaceResponse, UsersList, BufferRequest, CursorUpdate, JoinRequest};
|
use proto::{BufferList, WorkspaceEvent, WorkspaceRequest, WorkspaceResponse, UsersList, BufferRequest, CursorUpdate, JoinRequest};
|
||||||
|
|
||||||
use crate::actor::state::UserCursor;
|
use library::user::UserCursor;
|
||||||
use crate::actor::{buffer::Buffer, state::StateManager, workspace::Workspace as WorkspaceInstance}; // TODO fuck x2!
|
use crate::actor::{buffer::Buffer, state::StateManager}; // TODO fuck x2!
|
||||||
|
|
||||||
pub struct WorkspaceExtension {
|
pub struct WorkspaceExtension {
|
||||||
pub id: String
|
pub id: String
|
||||||
|
@ -86,7 +88,7 @@ impl Workspace for WorkspaceService {
|
||||||
let mut event_receiver = w.bus.subscribe();
|
let mut event_receiver = w.bus.subscribe();
|
||||||
w.view().users.add(
|
w.view().users.add(
|
||||||
crate::actor::state::User {
|
crate::actor::state::User {
|
||||||
name: r.name.clone(),
|
name: "some-name".to_string(), // get from request
|
||||||
cursor: UserCursor { buffer:0, x:0, y:0 }
|
cursor: UserCursor { buffer:0, x:0, y:0 }
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue