diff --git a/Cargo.toml b/Cargo.toml index 3f467df..ddaeb07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ lazy_static = { version = "1.4", optional = true } jni = { version = "0.21", features = ["invocation"], optional = true } # glue (lua) -mlua-codemp-patch = { version = "0.10.0-beta.2", features = ["module", "send"], optional = true } +mlua-codemp-patch = { version = "0.10.0-beta.2", features = ["module", "send", "serialize"], optional = true } # glue (js) napi = { version = "2.16", features = ["full"], optional = true } @@ -54,6 +54,7 @@ pyo3 = { version = "0.22", features = ["extension-module", "abi3-py38"], optiona # extra async-trait = { version = "0.1", optional = true } +serde = { version = "1.0", features = ["derive"], optional = true } [build-dependencies] # glue (js) @@ -65,12 +66,13 @@ pyo3-build-config = { version = "0.19", optional = true } default = [] # extra async-trait = ["dep:async-trait"] +serialize = ["dep:serde", "dep:uuid/serde"] # ffi rust = [] # used for ci matrix java = ["lazy_static", "jni", "tracing-subscriber"] js = ["napi-build", "tracing-subscriber", "napi", "napi-derive"] python = ["pyo3", "tracing-subscriber", "pyo3-build-config"] -lua = ["mlua-codemp-patch", "tracing-subscriber", "lazy_static"] +lua = ["mlua-codemp-patch", "tracing-subscriber", "lazy_static", "serialize"] lua54 = ["lua", "mlua-codemp-patch/lua54"] lua53 = ["lua", "mlua-codemp-patch/lua53"] lua52 = ["lua", "mlua-codemp-patch/lua52"] diff --git a/src/api/change.rs b/src/api/change.rs index 6fc8188..b7142e6 100644 --- a/src/api/change.rs +++ b/src/api/change.rs @@ -23,6 +23,7 @@ #[derive(Clone, Debug, Default)] #[cfg_attr(feature = "js", napi_derive::napi(object))] #[cfg_attr(feature = "python", pyo3::pyclass(get_all))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct TextChange { /// Range start of text change, as char indexes in buffer previous state. pub start: u32, diff --git a/src/api/config.rs b/src/api/config.rs index f0df96c..c5239be 100644 --- a/src/api/config.rs +++ b/src/api/config.rs @@ -3,7 +3,16 @@ /// Configuration struct for `codemp` client -#[derive(Debug, Clone)] +/// +/// username and password are required fields, while everything else is optional +/// +/// host, port and tls affect all connections to all grpc services +/// resulting endpoint is composed like this: +/// http{tls?'s':''}://{host}:{port} +#[derive(Clone, Debug)] +#[cfg_attr(feature = "js", napi_derive::napi(object))] +#[cfg_attr(feature = "python", pyo3::pyclass(get_all))] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct Config { /// user identifier used to register, possibly your email pub username: String, @@ -18,6 +27,11 @@ pub struct Config { } impl Config { + /// construct a new Config object, with given username and password + pub fn new(username: String, password: String) -> Self { + Self { username, password, host: None, port: None, tls: None } + } + #[inline] pub(crate) fn host(&self) -> &str { self.host.as_deref().unwrap_or("api.code.mp") diff --git a/src/api/cursor.rs b/src/api/cursor.rs index dc7467f..f68cdb4 100644 --- a/src/api/cursor.rs +++ b/src/api/cursor.rs @@ -7,6 +7,7 @@ use pyo3::prelude::*; /// User cursor position in a buffer #[derive(Clone, Debug, Default)] #[cfg_attr(feature = "python", pyclass)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] // #[cfg_attr(feature = "python", pyo3(crate = "reexported::pyo3"))] pub struct Cursor { /// Cursor start position in buffer, as 0-indexed row-column tuple. diff --git a/src/api/event.rs b/src/api/event.rs index c6159c4..23f2831 100644 --- a/src/api/event.rs +++ b/src/api/event.rs @@ -5,6 +5,7 @@ use codemp_proto::workspace::workspace_event::Event as WorkspaceEventInner; /// Event in a [crate::Workspace]. #[derive(Debug, Clone)] #[cfg_attr(feature = "python", pyo3::pyclass)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub enum Event { /// Fired when the file tree changes. /// Contains the modified buffer path (deleted, created or renamed). diff --git a/src/api/user.rs b/src/api/user.rs index a00ae3a..2b610f9 100644 --- a/src/api/user.rs +++ b/src/api/user.rs @@ -6,6 +6,7 @@ use uuid::Uuid; /// Represents a service user #[derive(Debug, Clone)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct User { /// User unique identifier, should never change. pub id: Uuid, diff --git a/src/prelude.rs b/src/prelude.rs index 834bc36..a2fd045 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -7,6 +7,7 @@ pub use crate::api::{ Cursor as CodempCursor, User as CodempUser, Event as CodempEvent, + Config as CodempConfig, }; pub use crate::{