chore: update glues

This commit is contained in:
əlemi 2024-10-15 21:46:22 +02:00
parent a9d17bf630
commit 14e10e1f7b
Signed by: alemi
GPG key ID: A4895B84D311642C
8 changed files with 67 additions and 67 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -7,9 +7,6 @@ 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) {
@ -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(

View file

@ -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<M: LuaUserDataMethods<Self>>(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<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
}
}

View file

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

View file

@ -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())
}
@ -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")]
@ -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")]