Skip to content

Commit

Permalink
chore: update glues
Browse files Browse the repository at this point in the history
  • Loading branch information
alemidev committed Oct 15, 2024
1 parent a9d17bf commit 14e10e1
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 67 deletions.
4 changes: 2 additions & 2 deletions src/ffi/java/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ fn get_user(client: &mut Client) -> crate::api::User {

/// Join a [Workspace] and return a pointer to it.
#[jni(package = "mp.code", class = "Client")]
fn join_workspace(client: &mut Client, workspace: String) -> Result<Workspace, ConnectionError> {
super::tokio().block_on(client.join_workspace(workspace))
fn attach_workspace(client: &mut Client, workspace: String) -> Result<Workspace, ConnectionError> {
super::tokio().block_on(client.attach_workspace(workspace))
}

/// Create a workspace on server, if allowed to.
Expand Down
14 changes: 7 additions & 7 deletions src/ffi/java/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn get_cursor(workspace: &mut Workspace) -> crate::cursor::Controller {
/// Get a buffer controller by name and returns a pointer to it.
#[jni(package = "mp.code", class = "Workspace")]
fn get_buffer(workspace: &mut Workspace, path: String) -> Option<crate::buffer::Controller> {
workspace.buffer_by_name(&path)
workspace.get_buffer(&path)
}

/// Get the filetree.
Expand All @@ -34,7 +34,7 @@ fn get_file_tree(workspace: &mut Workspace, filter: Option<String>, strict: bool
/// Gets a list of the active buffers.
#[jni(package = "mp.code", class = "Workspace")]
fn active_buffers(workspace: &mut Workspace) -> Vec<String> {
workspace.buffer_list()
workspace.active_buffers()
}

/// Gets a list of the active buffers.
Expand All @@ -46,7 +46,7 @@ fn user_list(workspace: &mut Workspace) -> Vec<String> {
/// Create a new buffer.
#[jni(package = "mp.code", class = "Workspace")]
fn create_buffer(workspace: &mut Workspace, path: String) -> Result<(), RemoteError> {
super::tokio().block_on(workspace.create(&path))
super::tokio().block_on(workspace.create_buffer(&path))
}

/// Attach to a buffer and return a pointer to its [crate::buffer::Controller].
Expand All @@ -55,13 +55,13 @@ fn attach_to_buffer(
workspace: &mut Workspace,
path: String,
) -> Result<crate::buffer::Controller, ConnectionError> {
super::tokio().block_on(workspace.attach(&path))
super::tokio().block_on(workspace.attach_buffer(&path))
}

/// Detach from a buffer.
#[jni(package = "mp.code", class = "Workspace")]
fn detach_from_buffer(workspace: &mut Workspace, path: String) -> bool {
workspace.detach(&path)
fn detach_buffer(workspace: &mut Workspace, path: String) -> bool {
workspace.detach_buffer(&path)
}

/// Update the local buffer list.
Expand All @@ -88,7 +88,7 @@ fn list_buffer_users(
/// Delete a buffer.
#[jni(package = "mp.code", class = "Workspace")]
fn delete_buffer(workspace: &mut Workspace, path: String) -> Result<(), RemoteError> {
super::tokio().block_on(workspace.delete(&path))
super::tokio().block_on(workspace.delete_buffer(&path))
}

/// Block and receive a workspace event.
Expand Down
6 changes: 3 additions & 3 deletions src/ffi/js/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ impl Client {
Ok(self.invite_to_workspace(workspace, user).await?)
}

#[napi(js_name = "join_workspace")]
#[napi(js_name = "attach_workspace")]
/// join workspace with given id (will start its cursor controller)
pub async fn js_join_workspace(&self, workspace: String) -> napi::Result<Workspace> {
Ok(self.join_workspace(workspace).await?)
pub async fn js_attach_workspace(&self, workspace: String) -> napi::Result<Workspace> {
Ok(self.attach_workspace(workspace).await?)
}

#[napi(js_name = "leave_workspace")]
Expand Down
36 changes: 18 additions & 18 deletions src/ffi/js/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ impl Workspace {
}

/// List all currently active buffers
#[napi(js_name = "buffer_list")]
pub fn js_buffer_list(&self) -> Vec<String> {
self.buffer_list()
#[napi(js_name = "active_buffers")]
pub fn js_active_buffers(&self) -> Vec<String> {
self.active_buffers()
}

/// Get workspace's Cursor Controller
Expand All @@ -66,27 +66,27 @@ impl Workspace {
}

/// Get a buffer controller by its name (path)
#[napi(js_name = "buffer_by_name")]
pub fn js_buffer_by_name(&self, path: String) -> Option<BufferController> {
self.buffer_by_name(&path)
#[napi(js_name = "get_buffer")]
pub fn js_get_buffer(&self, path: String) -> Option<BufferController> {
self.get_buffer(&path)
}

/// Create a new buffer in the current workspace
#[napi(js_name = "create")]
pub async fn js_create(&self, path: String) -> napi::Result<()> {
Ok(self.create(&path).await?)
#[napi(js_name = "create_buffer")]
pub async fn js_create_buffer(&self, path: String) -> napi::Result<()> {
Ok(self.create_buffer(&path).await?)
}

/// Attach to a workspace buffer, starting a BufferController
#[napi(js_name = "attach")]
pub async fn js_attach(&self, path: String) -> napi::Result<BufferController> {
Ok(self.attach(&path).await?)
#[napi(js_name = "attach_buffer")]
pub async fn js_attach_buffer(&self, path: String) -> napi::Result<BufferController> {
Ok(self.attach_buffer(&path).await?)
}

/// Delete a buffer from workspace
#[napi(js_name = "delete")]
pub async fn js_delete(&self, path: String) -> napi::Result<()> {
Ok(self.delete(&path).await?)
#[napi(js_name = "delete_buffer")]
pub async fn js_delete_buffer(&self, path: String) -> napi::Result<()> {
Ok(self.delete_buffer(&path).await?)
}

#[napi(js_name = "recv")]
Expand Down Expand Up @@ -128,9 +128,9 @@ impl Workspace {
/// Detach from an active buffer, stopping its underlying worker
/// this method returns true if no reference or last reference was held, false if there are still
/// dangling references to clear
#[napi(js_name = "detach")]
pub async fn js_detach(&self, path: String) -> bool {
self.detach(&path)
#[napi(js_name = "detach_buffer")]
pub async fn js_detach_buffer(&self, path: String) -> bool {
self.detach_buffer(&path)
}

/// Re-fetch remote buffer list
Expand Down
11 changes: 6 additions & 5 deletions src/ffi/lua/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@ use super::ext::from_lua_serde;

impl LuaUserData for CodempClient {
fn add_fields<F: LuaUserDataFields<Self>>(fields: &mut F) {
fields.add_field_method_get("id", |_, this| Ok(this.user().id.to_string()));
fields.add_field_method_get("username", |_, this| Ok(this.user().name.clone()));
fields.add_field_method_get("active_workspaces", |_, this| Ok(this.active_workspaces()));
}

fn add_methods<M: LuaUserDataMethods<Self>>(methods: &mut M) {
methods.add_meta_method(LuaMetaMethod::ToString, |_, this, ()| {
Ok(format!("{:?}", this))
});

fields.add_method("user", |_, this| Ok(this.user().id.to_string()));
fields.add_method("username", |_, this| Ok(this.my_user().name.clone()));
fields.add_method("active_workspaces", |_, this| Ok(this.active_workspaces()));

methods.add_method(
"refresh",
|_, this, ()| a_sync! { this => this.refresh().await? },
);

methods.add_method(
"join_workspace",
|_, this, (ws,): (String,)| a_sync! { this => this.join_workspace(ws).await? },
"attach_workspace",
|_, this, (ws,): (String,)| a_sync! { this => this.attach_workspace(ws).await? },
);

methods.add_method(
Expand Down
25 changes: 12 additions & 13 deletions src/ffi/lua/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,33 @@ use mlua::prelude::*;
use mlua_codemp_patch as mlua;

use super::ext::a_sync::a_sync;
use super::ext::from_lua_serde;

impl LuaUserData for CodempWorkspace {
fn add_methods<M: LuaUserDataMethods<Self>>(methods: &mut M) {
methods.add_meta_method(LuaMetaMethod::ToString, |_, this, ()| {
Ok(format!("{:?}", this))
});
methods.add_method(
"create",
|_, this, (name,): (String,)| a_sync! { this => this.create(&name).await? },
"create_buffer",
|_, this, (name,): (String,)| a_sync! { this => this.create_buffer(&name).await? },
);

methods.add_method(
"attach",
|_, this, (name,): (String,)| a_sync! { this => this.attach(&name).await? },
"attach_buffer",
|_, this, (name,): (String,)| a_sync! { this => this.attach_buffer(&name).await? },
);

methods.add_method("detach", |_, this, (name,): (String,)| {
Ok(this.detach(&name))
methods.add_method("detach_buffer", |_, this, (name,): (String,)| {
Ok(this.detach_buffer(&name))
});

methods.add_method(
"delete",
|_, this, (name,): (String,)| a_sync! { this => this.delete(&name).await? },
"delete_buffer",
|_, this, (name,): (String,)| a_sync! { this => this.delete_buffer(&name).await? },
);

methods.add_method("get_buffer", |_, this, (name,): (String,)| {
Ok(this.buffer_by_name(&name))
Ok(this.get_buffer(&name))
});

methods.add_method(
Expand All @@ -49,6 +48,9 @@ impl LuaUserData for CodempWorkspace {
},
);

fields.add_method("id", |_, this, ()| Ok(this.id()));
fields.add_method("cursor", |_, this, ()| Ok(this.cursor()));
fields.add_method("active_buffers", |_, this, ()| Ok(this.active_buffers()));
methods.add_method("user_list", |_, this, ()| Ok(this.user_list()));

methods.add_method("recv", |_, this, ()| a_sync! { this => this.recv().await? });
Expand All @@ -70,9 +72,6 @@ impl LuaUserData for CodempWorkspace {
}

fn add_fields<F: LuaUserDataFields<Self>>(fields: &mut F) {
fields.add_field_method_get("name", |_, this| Ok(this.id()));
fields.add_field_method_get("cursor", |_, this| Ok(this.cursor()));
fields.add_field_method_get("active_buffers", |_, this| Ok(this.buffer_list()));
// fields.add_field_method_get("users", |_, this| Ok(this.0.users())); // TODO
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/ffi/python/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ impl Client {
// super::tokio().block_on(Client::connect(host, username, password))
// }

#[pyo3(name = "join_workspace")]
fn pyjoin_workspace(&self, py: Python<'_>, workspace: String) -> PyResult<super::Promise> {
#[pyo3(name = "attach_workspace")]
fn pyattach_workspace(&self, py: Python<'_>, workspace: String) -> PyResult<super::Promise> {
tracing::info!("attempting to join the workspace {}", workspace);
let this = self.clone();
a_sync_allow_threads!(py, this.join_workspace(workspace).await)
a_sync_allow_threads!(py, this.attach_workspace(workspace).await)
// let this = self.clone();
// Ok(super::Promise(Some(tokio().spawn(async move {
// Ok(this
Expand Down Expand Up @@ -84,12 +84,12 @@ impl Client {

#[pyo3(name = "user_id")]
fn pyuser_id(&self) -> String {
self.user().id.to_string()
self.my_user().id.to_string()
}

#[pyo3(name = "user_name")]
fn pyuser_name(&self) -> String {
self.user().name.clone()
self.my_user().name.clone()
}

#[pyo3(name = "refresh")]
Expand Down
28 changes: 14 additions & 14 deletions src/ffi/python/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ use super::Promise;
#[pymethods]
impl Workspace {
// join a workspace
#[pyo3(name = "create")]
fn pycreate(&self, py: Python, path: String) -> PyResult<Promise> {
#[pyo3(name = "create_buffer")]
fn pycreate_buffer(&self, py: Python, path: String) -> PyResult<Promise> {
let this = self.clone();
a_sync_allow_threads!(py, this.create(path.as_str()).await)
a_sync_allow_threads!(py, this.create_buffer(path.as_str()).await)
}

#[pyo3(name = "attach")]
fn pyattach(&self, py: Python, path: String) -> PyResult<Promise> {
#[pyo3(name = "attach_buffer")]
fn pyattach_buffer(&self, py: Python, path: String) -> PyResult<Promise> {
let this = self.clone();
a_sync_allow_threads!(py, this.attach(path.as_str()).await)
a_sync_allow_threads!(py, this.attach_buffer(path.as_str()).await)
}

#[pyo3(name = "detach")]
fn pydetach(&self, path: String) -> bool {
#[pyo3(name = "detach_buffer")]
fn pydetach_buffer(&self, path: String) -> bool {
self.detach(path.as_str())
}

Expand All @@ -47,10 +47,10 @@ impl Workspace {
a_sync_allow_threads!(py, this.list_buffer_users(path.as_str()).await)
}

#[pyo3(name = "delete")]
fn pydelete(&self, py: Python, path: String) -> PyResult<Promise> {
#[pyo3(name = "delete_buffer")]
fn pydelete_buffer(&self, py: Python, path: String) -> PyResult<Promise> {
let this = self.clone();
a_sync_allow_threads!(py, this.delete(path.as_str()).await)
a_sync_allow_threads!(py, this.delete_buffer(path.as_str()).await)
}

#[pyo3(name = "id")]
Expand All @@ -68,9 +68,9 @@ impl Workspace {
self.buffer_by_name(path.as_str())
}

#[pyo3(name = "buffer_list")]
fn pybuffer_list(&self) -> Vec<String> {
self.buffer_list()
#[pyo3(name = "active_buffers")]
fn pyactive_buffers(&self) -> Vec<String> {
self.active_buffers()
}

#[pyo3(name = "filetree")]
Expand Down

0 comments on commit 14e10e1

Please sign in to comment.