Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/// Represents a service buffer
#[derive(Debug, Clone)]
#[cfg_attr(feature = "py", pyo3::pyclass)]
#[cfg_attr(feature = "py", pyo3::pyclass(from_py_object))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
pub struct BufferNode {
/// Buffer path, sort of like a UNIX path.
Expand Down
4 changes: 2 additions & 2 deletions src/api/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// be provided every time.
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "js", napi_derive::napi(object))]
#[cfg_attr(feature = "py", pyo3::pyclass(get_all))]
#[cfg_attr(feature = "py", pyo3::pyclass(get_all, from_py_object))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
pub struct BufferUpdate {
/// Optional content hash after applying this change.
Expand Down Expand Up @@ -52,7 +52,7 @@ pub struct BufferUpdate {
/// ```
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "js", napi_derive::napi(object))]
#[cfg_attr(feature = "py", pyo3::pyclass(get_all))]
#[cfg_attr(feature = "py", pyo3::pyclass(get_all, from_py_object))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
pub struct TextChange {
/// Range start of text change, as char indexes in buffer previous state.
Expand Down
2 changes: 1 addition & 1 deletion src/api/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/// http{tls?'s':''}://{host}:{port}
#[derive(Clone, Default)]
#[cfg_attr(feature = "js", napi_derive::napi(object))]
#[cfg_attr(feature = "py", pyo3::pyclass(get_all, set_all))]
#[cfg_attr(feature = "py", pyo3::pyclass(get_all, set_all, from_py_object))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
pub struct Config {
/// User identifier used to register, possibly your email.
Expand Down
7 changes: 3 additions & 4 deletions src/api/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use pyo3::prelude::*;
/// An event that occurred about a user's cursor.
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "js", napi_derive::napi(object))]
#[cfg_attr(feature = "py", pyclass(get_all))]
#[cfg_attr(feature = "py", pyclass(get_all, from_py_object))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
// #[cfg_attr(feature = "py", pyo3(crate = "reexported::pyo3"))]
pub struct CursorEvent {
Expand All @@ -17,11 +17,10 @@ pub struct CursorEvent {
pub cursor: Cursor,
}


/// An event that occurred about a user's cursor.
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "js", napi_derive::napi(object))]
#[cfg_attr(feature = "py", pyclass(get_all))]
#[cfg_attr(feature = "py", pyclass(get_all, from_py_object))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
// #[cfg_attr(feature = "py", pyo3(crate = "reexported::pyo3"))]
pub struct Cursor {
Expand All @@ -34,7 +33,7 @@ pub struct Cursor {
/// A cursor selection span.
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "js", napi_derive::napi(object))]
#[cfg_attr(feature = "py", pyclass(get_all))]
#[cfg_attr(feature = "py", pyclass(get_all, from_py_object))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
// #[cfg_attr(feature = "py", pyo3(crate = "reexported::pyo3"))]
pub struct Selection {
Expand Down
12 changes: 9 additions & 3 deletions src/api/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use codemp_proto::workspace::workspace_event::Event as WorkspaceEventInner;

/// Event in a [crate::Workspace].
#[derive(Debug, Clone)]
#[cfg_attr(feature = "py", pyo3::pyclass)]
#[cfg_attr(feature = "py", pyo3::pyclass(from_py_object))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serialize", serde(tag = "type"))]
pub enum Event {
Expand All @@ -31,8 +31,14 @@ impl From<WorkspaceEventInner> for Event {
WorkspaceEventInner::Create(e) => Self::FileTreeUpdated { path: e.path },
WorkspaceEventInner::Delete(e) => Self::FileTreeUpdated { path: e.path },
WorkspaceEventInner::Rename(e) => Self::FileTreeUpdated { path: e.after },
WorkspaceEventInner::BufferJoin(e) => Self::UserJoinBuffer { name: e.user.name, buffer: e.buffer },
WorkspaceEventInner::BufferLeave(e) => Self::UserLeaveBuffer { name: e.user.name, buffer: e.buffer },
WorkspaceEventInner::BufferJoin(e) => Self::UserJoinBuffer {
name: e.user.name,
buffer: e.buffer,
},
WorkspaceEventInner::BufferLeave(e) => Self::UserLeaveBuffer {
name: e.user.name,
buffer: e.buffer,
},
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use uuid::Uuid;

/// Represents a service user
#[derive(Debug, Clone)]
#[cfg_attr(feature = "py", pyo3::pyclass)]
#[cfg_attr(feature = "py", pyo3::pyclass(from_py_object))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
pub struct User {
/// User unique identifier, should never change.
Expand Down
2 changes: 1 addition & 1 deletion src/api/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use uuid::Uuid;

/// Represents a service workspace
#[derive(Debug, Clone)]
#[cfg_attr(feature = "py", pyo3::pyclass)]
#[cfg_attr(feature = "py", pyo3::pyclass(from_py_object))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
pub struct WorkspaceInfo {
/// Workspace unique identifier, should never change.
Expand Down
2 changes: 1 addition & 1 deletion src/buffer/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::ext::IgnorableError;
/// Each buffer controller internally tracks the last acknowledged state, remaining always in sync
/// with the server while allowing to procedurally receive changes while still sending new ones.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "py", pyo3::pyclass)]
#[cfg_attr(feature = "py", pyo3::pyclass(from_py_object))]
#[cfg_attr(feature = "js", napi_derive::napi)]
pub struct BufferController(pub(crate) Arc<BufferControllerInner>);

Expand Down
23 changes: 12 additions & 11 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use pyo3::prelude::*;
/// A new [`Client`] can be obtained with [`Client::connect`].
#[derive(Debug, Clone)]
#[cfg_attr(feature = "js", napi_derive::napi)]
#[cfg_attr(feature = "py", pyclass)]
#[cfg_attr(feature = "py", pyclass(from_py_object))]
pub struct Client(Arc<ClientInner>);

#[derive(Debug)]
Expand Down Expand Up @@ -198,14 +198,19 @@ impl Client {
loop {
// TODO either configurable token refresh time or calculate depending on token lifetime
tokio::time::sleep(std::time::Duration::from_secs(240)).await;
if weak.upgrade().is_none() { break };
let new_credentials = session_client.get_workspace_token(
tonic::Request::new(WorkspaceRequest { id: Identifier::from(workspace) })
)
if weak.upgrade().is_none() {
break;
};
let new_credentials = session_client
.get_workspace_token(tonic::Request::new(WorkspaceRequest {
id: Identifier::from(workspace),
}))
.await?
.into_inner();
workspace_claims.set(new_credentials);
workspace_client.keep_alive(tonic::Request::new(Empty {})).await?;
workspace_client
.keep_alive(tonic::Request::new(Empty {}))
.await?;
}
Ok::<(), tonic::Status>(())
};
Expand Down Expand Up @@ -233,11 +238,7 @@ impl Client {

/// Get the names of all active [`Workspace`]s.
pub fn active_workspaces(&self) -> Vec<uuid::Uuid> {
self.0
.workspaces
.iter()
.map(|x| *x.key())
.collect()
self.0.workspaces.iter().map(|x| *x.key()).collect()
}

/// Get the currently logged in user.
Expand Down
13 changes: 8 additions & 5 deletions src/cursor/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use tokio::sync::{mpsc, oneshot, watch};

use crate::{
api::{
controller::{AsyncReceiver, AsyncSender, ControllerCallback}, cursor::CursorEvent, Controller, Cursor
Controller, Cursor,
controller::{AsyncReceiver, AsyncSender, ControllerCallback},
cursor::CursorEvent,
},
errors::ControllerResult,
};
Expand All @@ -17,7 +19,7 @@ use codemp_proto::cursor::{CursorPosition, CursorUpdate, RowCol};
///
/// An unique [CursorController] exists for each active [crate::Workspace].
#[derive(Debug, Clone)]
#[cfg_attr(feature = "py", pyo3::pyclass)]
#[cfg_attr(feature = "py", pyo3::pyclass(from_py_object))]
#[cfg_attr(feature = "js", napi_derive::napi)]
pub struct CursorController(pub(crate) Arc<CursorControllerInner>);

Expand Down Expand Up @@ -53,7 +55,8 @@ impl AsyncSender<Cursor> for CursorController {

Ok(self.0.op.send(CursorUpdate {
buffer: cursor.buffer,
cursors: cursor.sel
cursors: cursor
.sel
.into_iter()
.map(|x| CursorPosition {
start: RowCol {
Expand All @@ -63,9 +66,9 @@ impl AsyncSender<Cursor> for CursorController {
end: RowCol {
row: x.end_row,
col: x.end_col,
}
},
})
.collect()
.collect(),
})?)
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/ffi/python/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::Client;
use super::a_sync_allow_threads;
use super::a_sync_detach;
use crate::api::User;
use crate::workspace::Workspace;
use pyo3::prelude::*;
Expand All @@ -20,28 +20,28 @@ impl Client {
fn pyattach_workspace(&self, py: Python<'_>, workspace: Uuid) -> PyResult<super::Promise> {
tracing::info!("attempting to join the workspace {}", workspace);
let this = self.clone();
a_sync_allow_threads!(py, this.attach_workspace(workspace).await)
a_sync_detach!(py, this.attach_workspace(workspace).await)
// let this = self.clone();
// Ok(super::Promise(Some(tokio().spawn(async move {
// Ok(this
// .join_workspace(workspace)
// .await
// .map(|f| Python::with_gil(|py| f.into_py(py)))?)
// .map(|f| Python::attach(|py| f.into_py(py)))?)
// }))))
}

#[pyo3(name = "create_workspace")]
fn pycreate_workspace(&self, py: Python<'_>, workspace: String) -> PyResult<super::Promise> {
tracing::info!("creating workspace {}", workspace);
let this = self.clone();
a_sync_allow_threads!(py, this.create_workspace(workspace).await)
a_sync_detach!(py, this.create_workspace(workspace).await)
}

#[pyo3(name = "delete_workspace")]
fn pydelete_workspace(&self, py: Python<'_>, workspace: String) -> PyResult<super::Promise> {
tracing::info!("deleting workspace {}", workspace);
let this = self.clone();
a_sync_allow_threads!(py, this.delete_workspace(workspace).await)
a_sync_detach!(py, this.delete_workspace(workspace).await)
}

#[pyo3(name = "invite_to_workspace")]
Expand All @@ -53,21 +53,21 @@ impl Client {
) -> PyResult<super::Promise> {
tracing::info!("inviting {user} to workspace {workspace}");
let this = self.clone();
a_sync_allow_threads!(py, this.invite_to_workspace(workspace, user).await)
a_sync_detach!(py, this.invite_to_workspace(workspace, user).await)
}

#[pyo3(name = "fetch_owned_workspaces")]
fn pyfetch_owned_workspaces(&self, py: Python<'_>) -> PyResult<super::Promise> {
tracing::info!("fetching owned workspaces");
let this = self.clone();
a_sync_allow_threads!(py, this.fetch_owned_workspaces().await)
a_sync_detach!(py, this.fetch_owned_workspaces().await)
}

#[pyo3(name = "fetch_joined_workspaces")]
fn pyfetch_joined_workspaces(&self, py: Python<'_>) -> PyResult<super::Promise> {
tracing::info!("fetching joined workspaces");
let this = self.clone();
a_sync_allow_threads!(py, this.fetch_joined_workspaces().await)
a_sync_detach!(py, this.fetch_joined_workspaces().await)
}

#[pyo3(name = "leave_workspace")]
Expand Down Expand Up @@ -95,6 +95,6 @@ impl Client {
fn pyrefresh(&self, py: Python<'_>) -> PyResult<super::Promise> {
tracing::info!("attempting to refresh token");
let this = self.clone();
a_sync_allow_threads!(py, this.refresh().await)
a_sync_detach!(py, this.refresh().await)
}
}
Loading
Loading