From d733a0e4e2a439e495d7ef701cda18579e65ad67 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 26 Sep 2024 02:29:46 +0200 Subject: [PATCH] chore: update glue code to remove .stop() --- dist/java/src/mp/code/BufferController.java | 10 ---------- dist/java/src/mp/code/CursorController.java | 10 ---------- dist/java/src/mp/code/Workspace.java | 6 +++--- dist/lua/annotations.lua | 14 +++++--------- dist/py/src/codemp/codemp.pyi | 2 -- src/ffi/java/buffer.rs | 6 ------ src/ffi/java/cursor.rs | 6 ------ src/ffi/java/mod.rs | 20 -------------------- src/ffi/java/workspace.rs | 2 +- src/ffi/js/buffer.rs | 2 +- src/ffi/lua/buffer.rs | 2 -- src/ffi/lua/cursor.rs | 2 -- src/ffi/lua/workspace.rs | 3 +-- src/ffi/python/controllers.rs | 10 ---------- src/ffi/python/mod.rs | 6 +++--- src/ffi/python/workspace.rs | 6 +----- 16 files changed, 15 insertions(+), 92 deletions(-) diff --git a/dist/java/src/mp/code/BufferController.java b/dist/java/src/mp/code/BufferController.java index 0ae455f..66f4495 100644 --- a/dist/java/src/mp/code/BufferController.java +++ b/dist/java/src/mp/code/BufferController.java @@ -106,16 +106,6 @@ public final class BufferController { poll(this.ptr); } - private static native boolean stop(long self); - - /** - * Stops the controller. Any further calls to it will fail. - * @return true if it was stopped successfully - */ - public boolean stop() { - return stop(this.ptr); - } - private static native void free(long self); static { diff --git a/dist/java/src/mp/code/CursorController.java b/dist/java/src/mp/code/CursorController.java index ee3d238..159e548 100644 --- a/dist/java/src/mp/code/CursorController.java +++ b/dist/java/src/mp/code/CursorController.java @@ -83,16 +83,6 @@ public final class CursorController { poll(this.ptr); } - private static native boolean stop(long self); - - /** - * Stops the controller. Any further calls to it will fail. - * @return true if it was stopped successfully - */ - public boolean stop() { - return stop(this.ptr); - } - private static native void free(long self); static { diff --git a/dist/java/src/mp/code/Workspace.java b/dist/java/src/mp/code/Workspace.java index 62a6e49..31ee6e3 100644 --- a/dist/java/src/mp/code/Workspace.java +++ b/dist/java/src/mp/code/Workspace.java @@ -113,14 +113,14 @@ public final class Workspace { return attach_to_buffer(ptr, path); } - private static native DetachResult detach_from_buffer(long self, String path); + private static native boolean detach_from_buffer(long self, String path); /** * Detaches from a given buffer. * @param path the path of the buffer to detach from - * @return a {@link DetachResult} representing the outcome of the operation + * @return a boolean, true only if there are still dangling references preventing controller from stopping */ - public DetachResult detachFromBuffer(String path) { + public boolean detachFromBuffer(String path) { return detach_from_buffer(this.ptr, path); } diff --git a/dist/lua/annotations.lua b/dist/lua/annotations.lua index 9cce3a8..04055ba 100644 --- a/dist/lua/annotations.lua +++ b/dist/lua/annotations.lua @@ -223,7 +223,7 @@ function Workspace:attach(path) end ---@param path string relative path ("name") of buffer to detach from ---@return boolean success ----detach from an active buffer, closing all streams. returns false if buffer was no longer active +---detach from an active buffer, closing all streams. returns false if there are still dangling references function Workspace:detach(path) end ---@param filter? string apply a filter to the return elements @@ -232,6 +232,10 @@ function Workspace:detach(path) end ---return the list of available buffers in this workspace, as relative paths from workspace root function Workspace:filetree(filter, strict) end +---@return string[] +---return all names of users currently in this workspace +function Workspace:user_list() end + ---@return NilPromise ---@async ---@nodiscard @@ -297,10 +301,6 @@ function BufferController:recv() end ---block until next text change without returning it function BufferController:poll() end ----@return boolean success ----stop buffer worker and disconnect, returns false if was already stopped -function BufferController:stop() end - ---clears any previously registered buffer callback function BufferController:clear_callback() end @@ -354,10 +354,6 @@ function CursorController:recv() end ---block until next cursor event without returning it function CursorController:poll() end ----@return boolean success ----stop cursor worker and disconnect, returns false if was already stopped -function CursorController:stop() end - ---clears any previously registered cursor callback function CursorController:clear_callback() end diff --git a/dist/py/src/codemp/codemp.pyi b/dist/py/src/codemp/codemp.pyi index 3a93af0..4df875b 100644 --- a/dist/py/src/codemp/codemp.pyi +++ b/dist/py/src/codemp/codemp.pyi @@ -102,7 +102,6 @@ class BufferController: def callback(self, cb: Callable[[BufferController], None]) -> None: ... def clear_callback(self) -> None: ... - def stop(self) -> bool: ... @@ -131,5 +130,4 @@ class CursorController: def callback(self, cb: Callable[[CursorController], None]) -> None: ... def clear_callback(self) -> None: ... - def stop(self) -> bool: ... diff --git a/src/ffi/java/buffer.rs b/src/ffi/java/buffer.rs index 0857118..8cc1ce4 100644 --- a/src/ffi/java/buffer.rs +++ b/src/ffi/java/buffer.rs @@ -80,12 +80,6 @@ fn poll(controller: &mut crate::buffer::Controller) -> Result<(), ControllerErro super::tokio().block_on(controller.poll()) } -/// Stop the controller. -#[jni(package = "mp.code", class = "BufferController")] -fn stop(controller: &mut crate::buffer::Controller) -> bool { - controller.stop() -} - /// Called by the Java GC to drop a [crate::buffer::Controller]. #[jni(package = "mp.code", class = "BufferController")] fn free(input: jni::sys::jlong) { diff --git a/src/ffi/java/cursor.rs b/src/ffi/java/cursor.rs index 359ea2b..4cc1a4b 100644 --- a/src/ffi/java/cursor.rs +++ b/src/ffi/java/cursor.rs @@ -67,12 +67,6 @@ fn poll(controller: &mut crate::cursor::Controller) -> Result<(), ControllerErro super::tokio().block_on(controller.poll()) } -/// Stop the controller. -#[jni(package = "mp.code", class = "CursorController")] -fn stop(controller: &mut crate::cursor::Controller) -> bool { - controller.stop() -} - /// Called by the Java GC to drop a [crate::cursor::Controller]. #[jni(package = "mp.code", class = "CursorController")] fn free(input: jni::sys::jlong) { diff --git a/src/ffi/java/mod.rs b/src/ffi/java/mod.rs index 6e0515a..1c7ec45 100644 --- a/src/ffi/java/mod.rs +++ b/src/ffi/java/mod.rs @@ -170,26 +170,6 @@ impl<'j> jni_toolbox::IntoJavaObject<'j> for crate::api::Event { } } -impl<'j> jni_toolbox::IntoJavaObject<'j> for crate::workspace::DetachResult { - const CLASS: &'static str = "mp/code/data/DetachResult"; - fn into_java_object(self, env: &mut jni::JNIEnv<'j>) -> Result, jni::errors::Error> { - let ordinal = match self { - crate::workspace::DetachResult::NotAttached => 0, - crate::workspace::DetachResult::Detaching => 1, - crate::workspace::DetachResult::AlreadyDetached => 2 - }; - - let class = env.find_class(Self::CLASS)?; - let variants: jni::objects::JObjectArray = env.call_method( - class, - "getEnumConstants", - "()[Ljava/lang/Object;", - &[] - )?.l()?.into(); - env.get_object_array_element(variants, ordinal) - } -} - impl<'j> jni_toolbox::IntoJavaObject<'j> for crate::api::TextChange { const CLASS: &'static str = "mp/code/data/TextChange"; fn into_java_object(self, env: &mut jni::JNIEnv<'j>) -> Result, jni::errors::Error> { diff --git a/src/ffi/java/workspace.rs b/src/ffi/java/workspace.rs index 5732397..6fc38cd 100644 --- a/src/ffi/java/workspace.rs +++ b/src/ffi/java/workspace.rs @@ -51,7 +51,7 @@ fn attach_to_buffer(workspace: &mut Workspace, path: String) -> Result crate::workspace::DetachResult { +fn detach_from_buffer(workspace: &mut Workspace, path: String) -> bool { workspace.detach(&path) } diff --git a/src/ffi/js/buffer.rs b/src/ffi/js/buffer.rs index b93f3c7..a1a3727 100644 --- a/src/ffi/js/buffer.rs +++ b/src/ffi/js/buffer.rs @@ -27,7 +27,7 @@ impl BufferController { } #[napi(js_name = "clear_callback")] - pub fn js_clear_callback(&self) -> () { + pub fn js_clear_callback(&self) { self.clear_callback(); } diff --git a/src/ffi/lua/buffer.rs b/src/ffi/lua/buffer.rs index acf3d04..d2733c1 100644 --- a/src/ffi/lua/buffer.rs +++ b/src/ffi/lua/buffer.rs @@ -18,8 +18,6 @@ impl LuaUserData for CodempBufferController { methods.add_method("recv", |_, this, ()| a_sync! { this => this.recv().await? }); methods.add_method("poll", |_, this, ()| a_sync! { this => this.poll().await? }); - methods.add_method("stop", |_, this, ()| Ok(this.stop())); - methods.add_method("content", |_, this, ()| a_sync! { this => this.content().await? }); methods.add_method("clear_callback", |_, this, ()| { this.clear_callback(); Ok(()) }); diff --git a/src/ffi/lua/cursor.rs b/src/ffi/lua/cursor.rs index 46d4e29..98eca44 100644 --- a/src/ffi/lua/cursor.rs +++ b/src/ffi/lua/cursor.rs @@ -19,8 +19,6 @@ impl LuaUserData for CodempCursorController { methods.add_method("recv", |_, this, ()| a_sync! { this => this.recv().await? }); methods.add_method("poll", |_, this, ()| a_sync! { this => this.poll().await? }); - methods.add_method("stop", |_, this, ()| Ok(this.stop())); - methods.add_method("clear_callback", |_, this, ()| { this.clear_callback(); Ok(()) }); methods.add_method("callback", |_, this, (cb,):(LuaFunction,)| { this.callback(move |controller: CodempCursorController| super::ext::callback().invoke(cb.clone(), controller)); diff --git a/src/ffi/lua/workspace.rs b/src/ffi/lua/workspace.rs index caed60b..7868d0f 100644 --- a/src/ffi/lua/workspace.rs +++ b/src/ffi/lua/workspace.rs @@ -1,7 +1,6 @@ use mlua_codemp_patch as mlua; use mlua::prelude::*; use crate::prelude::*; -use crate::workspace::DetachResult; use super::ext::a_sync::a_sync; use super::ext::from_lua_serde; @@ -18,7 +17,7 @@ impl LuaUserData for CodempWorkspace { ); methods.add_method("detach", |_, this, (name,):(String,)| - Ok(matches!(this.detach(&name), DetachResult::Detaching | DetachResult::AlreadyDetached)) + Ok(this.detach(&name)) ); methods.add_method("delete", |_, this, (name,):(String,)| diff --git a/src/ffi/python/controllers.rs b/src/ffi/python/controllers.rs index 1bc4e63..b1f8c21 100644 --- a/src/ffi/python/controllers.rs +++ b/src/ffi/python/controllers.rs @@ -67,11 +67,6 @@ impl CursorController { fn pyclear_callback(&self) { self.clear_callback(); } - - #[pyo3(name = "stop")] - fn pystop(&self) -> bool { - self.stop() - } } // need to do manually since Controller is a trait implementation @@ -137,11 +132,6 @@ impl BufferController { fn pyclear_callback(&self) { self.clear_callback(); } - - #[pyo3(name = "stop")] - fn pystop(&self) -> bool { - self.stop() - } } // We have to write this manually since diff --git a/src/ffi/python/mod.rs b/src/ffi/python/mod.rs index 0956b8b..f703051 100644 --- a/src/ffi/python/mod.rs +++ b/src/ffi/python/mod.rs @@ -172,9 +172,9 @@ impl Config { kwds: Option>, ) -> PyResult { if let Some(kwgs) = kwds { - let host = kwgs.get_item("host")?.map(|e| e.extract().ok()).flatten(); - let port = kwgs.get_item("port")?.map(|e| e.extract().ok()).flatten(); - let tls = kwgs.get_item("tls")?.map(|e| e.extract().ok()).flatten(); + let host = kwgs.get_item("host")?.and_then(|e| e.extract().ok()); + let port = kwgs.get_item("port")?.and_then(|e| e.extract().ok()); + let tls = kwgs.get_item("tls")?.and_then(|e| e.extract().ok()); Ok(Config { username, diff --git a/src/ffi/python/workspace.rs b/src/ffi/python/workspace.rs index 79574b8..4615be5 100644 --- a/src/ffi/python/workspace.rs +++ b/src/ffi/python/workspace.rs @@ -23,11 +23,7 @@ impl Workspace { #[pyo3(name = "detach")] fn pydetach(&self, path: String) -> bool { - match self.detach(path.as_str()) { - crate::workspace::DetachResult::NotAttached => false, - crate::workspace::DetachResult::Detaching => true, - crate::workspace::DetachResult::AlreadyDetached => true, - } + self.detach(path.as_str()) } #[pyo3(name = "event")]