feat: add serialize feature for api structs

This commit is contained in:
əlemi 2024-09-11 15:45:35 +02:00
parent d57fb2c4b6
commit e91a504588
Signed by: alemi
GPG key ID: A4895B84D311642C
7 changed files with 24 additions and 3 deletions

View file

@ -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"]

View file

@ -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,

View file

@ -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")

View file

@ -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.

View file

@ -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).

View file

@ -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,

View file

@ -7,6 +7,7 @@ pub use crate::api::{
Cursor as CodempCursor,
User as CodempUser,
Event as CodempEvent,
Config as CodempConfig,
};
pub use crate::{