From 14e10e1f7bb148381d0554edd4e207f9a3c8efba Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 15 Oct 2024 21:46:22 +0200 Subject: [PATCH] chore: update glues --- src/ffi/java/client.rs | 4 ++-- src/ffi/java/workspace.rs | 14 +++++++------- src/ffi/js/client.rs | 6 +++--- src/ffi/js/workspace.rs | 36 ++++++++++++++++++------------------ src/ffi/lua/client.rs | 11 ++++++----- src/ffi/lua/workspace.rs | 25 ++++++++++++------------- src/ffi/python/client.rs | 10 +++++----- src/ffi/python/workspace.rs | 28 ++++++++++++++-------------- 8 files changed, 67 insertions(+), 67 deletions(-) diff --git a/src/ffi/java/client.rs b/src/ffi/java/client.rs index ff14472..d092999 100644 --- a/src/ffi/java/client.rs +++ b/src/ffi/java/client.rs @@ -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 { - super::tokio().block_on(client.join_workspace(workspace)) +fn attach_workspace(client: &mut Client, workspace: String) -> Result { + super::tokio().block_on(client.attach_workspace(workspace)) } /// Create a workspace on server, if allowed to. diff --git a/src/ffi/java/workspace.rs b/src/ffi/java/workspace.rs index acdc36f..9b5343e 100644 --- a/src/ffi/java/workspace.rs +++ b/src/ffi/java/workspace.rs @@ -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 { - workspace.buffer_by_name(&path) + workspace.get_buffer(&path) } /// Get the filetree. @@ -34,7 +34,7 @@ fn get_file_tree(workspace: &mut Workspace, filter: Option, strict: bool /// Gets a list of the active buffers. #[jni(package = "mp.code", class = "Workspace")] fn active_buffers(workspace: &mut Workspace) -> Vec { - workspace.buffer_list() + workspace.active_buffers() } /// Gets a list of the active buffers. @@ -46,7 +46,7 @@ fn user_list(workspace: &mut Workspace) -> Vec { /// 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]. @@ -55,13 +55,13 @@ fn attach_to_buffer( workspace: &mut Workspace, path: String, ) -> Result { - 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. @@ -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. diff --git a/src/ffi/js/client.rs b/src/ffi/js/client.rs index 8f63862..8089bc7 100644 --- a/src/ffi/js/client.rs +++ b/src/ffi/js/client.rs @@ -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 { - Ok(self.join_workspace(workspace).await?) + pub async fn js_attach_workspace(&self, workspace: String) -> napi::Result { + Ok(self.attach_workspace(workspace).await?) } #[napi(js_name = "leave_workspace")] diff --git a/src/ffi/js/workspace.rs b/src/ffi/js/workspace.rs index bacde0e..0358e2b 100644 --- a/src/ffi/js/workspace.rs +++ b/src/ffi/js/workspace.rs @@ -54,9 +54,9 @@ impl Workspace { } /// List all currently active buffers - #[napi(js_name = "buffer_list")] - pub fn js_buffer_list(&self) -> Vec { - self.buffer_list() + #[napi(js_name = "active_buffers")] + pub fn js_active_buffers(&self) -> Vec { + self.active_buffers() } /// Get workspace's Cursor Controller @@ -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 { - self.buffer_by_name(&path) + #[napi(js_name = "get_buffer")] + pub fn js_get_buffer(&self, path: String) -> Option { + 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 { - Ok(self.attach(&path).await?) + #[napi(js_name = "attach_buffer")] + pub async fn js_attach_buffer(&self, path: String) -> napi::Result { + 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")] @@ -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 diff --git a/src/ffi/lua/client.rs b/src/ffi/lua/client.rs index 6198671..520eaec 100644 --- a/src/ffi/lua/client.rs +++ b/src/ffi/lua/client.rs @@ -7,9 +7,6 @@ use super::ext::from_lua_serde; impl LuaUserData for CodempClient { fn add_fields>(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>(methods: &mut M) { @@ -17,14 +14,18 @@ impl LuaUserData for CodempClient { 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( diff --git a/src/ffi/lua/workspace.rs b/src/ffi/lua/workspace.rs index 3be3ec3..56769c7 100644 --- a/src/ffi/lua/workspace.rs +++ b/src/ffi/lua/workspace.rs @@ -3,7 +3,6 @@ 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>(methods: &mut M) { @@ -11,26 +10,26 @@ impl LuaUserData for CodempWorkspace { 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( @@ -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? }); @@ -70,9 +72,6 @@ impl LuaUserData for CodempWorkspace { } fn add_fields>(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 } } diff --git a/src/ffi/python/client.rs b/src/ffi/python/client.rs index ffeb3a6..4d12726 100644 --- a/src/ffi/python/client.rs +++ b/src/ffi/python/client.rs @@ -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 { + #[pyo3(name = "attach_workspace")] + fn pyattach_workspace(&self, py: Python<'_>, workspace: String) -> PyResult { 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 @@ -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")] diff --git a/src/ffi/python/workspace.rs b/src/ffi/python/workspace.rs index 3ceeebc..96e287c 100644 --- a/src/ffi/python/workspace.rs +++ b/src/ffi/python/workspace.rs @@ -11,20 +11,20 @@ use super::Promise; #[pymethods] impl Workspace { // join a workspace - #[pyo3(name = "create")] - fn pycreate(&self, py: Python, path: String) -> PyResult { + #[pyo3(name = "create_buffer")] + fn pycreate_buffer(&self, py: Python, path: String) -> PyResult { 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 { + #[pyo3(name = "attach_buffer")] + fn pyattach_buffer(&self, py: Python, path: String) -> PyResult { 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()) } @@ -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 { + #[pyo3(name = "delete_buffer")] + fn pydelete_buffer(&self, py: Python, path: String) -> PyResult { 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")] @@ -68,9 +68,9 @@ impl Workspace { self.buffer_by_name(path.as_str()) } - #[pyo3(name = "buffer_list")] - fn pybuffer_list(&self) -> Vec { - self.buffer_list() + #[pyo3(name = "active_buffers")] + fn pyactive_buffers(&self) -> Vec { + self.active_buffers() } #[pyo3(name = "filetree")]