diff --git a/src/ffi/js/buffer.rs b/src/ffi/js/buffer.rs index 5fc72d3..9e141c7 100644 --- a/src/ffi/js/buffer.rs +++ b/src/ffi/js/buffer.rs @@ -7,8 +7,8 @@ use crate::buffer::controller::BufferController; #[napi] impl BufferController { - #[napi(ts_args_type = "fun: (event: TextChange) => void")] - pub fn callback(&self, fun: napi::JsFunction) -> napi::Result<()>{ + #[napi(js_name = "callback", ts_args_type = "fun: (event: TextChange) => void")] + pub fn jscallback(&self, fun: napi::JsFunction) -> napi::Result<()>{ let tsfn : ThreadsafeFunction = fun.create_threadsafe_function(0, |ctx : ThreadSafeCallContext| { @@ -41,4 +41,4 @@ impl BufferController { pub async fn js_send(&self, op: TextChange) -> napi::Result<()> { Ok(self.send(op).await?) } -} \ No newline at end of file +} diff --git a/src/ffi/js/cursor.rs b/src/ffi/js/cursor.rs index a0d4c28..c84d90d 100644 --- a/src/ffi/js/cursor.rs +++ b/src/ffi/js/cursor.rs @@ -42,8 +42,8 @@ impl From for JsCursor { #[napi] impl CursorController { - #[napi(ts_args_type = "fun: (event: Cursor) => void")] - pub fn callback(&self, fun: napi::JsFunction) -> napi::Result<()>{ + #[napi(js_name = "callback", ts_args_type = "fun: (event: Cursor) => void")] + pub fn jscallback(&self, fun: napi::JsFunction) -> napi::Result<()>{ let tsfn : ThreadsafeFunction = fun.create_threadsafe_function(0, |ctx : ThreadSafeCallContext| { diff --git a/src/ffi/js/workspace.rs b/src/ffi/js/workspace.rs index 3aa552e..0711beb 100644 --- a/src/ffi/js/workspace.rs +++ b/src/ffi/js/workspace.rs @@ -12,8 +12,8 @@ impl Workspace { } #[napi(js_name = "filetree")] - pub fn js_filetree(&self) -> Vec { - self.filetree() + pub fn js_filetree(&self, filter: Option<&str>) -> Vec { + self.filetree(filter) } #[napi(js_name = "cursor")] @@ -41,4 +41,4 @@ impl Workspace { Ok(self.delete(&path).await?) } -} \ No newline at end of file +} diff --git a/src/ffi/lua.rs b/src/ffi/lua.rs index d0967fd..da72d26 100644 --- a/src/ffi/lua.rs +++ b/src/ffi/lua.rs @@ -166,12 +166,15 @@ impl LuaUserData for CodempWorkspace { }); Ok(()) }); + + methods.add_method("filetree", |_, this, (filter,):(Option,)| + Ok(this.filetree(filter.as_deref())) + ); } fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) { fields.add_field_method_get("id", |_, this| Ok(this.id())); fields.add_field_method_get("cursor", |_, this| Ok(this.cursor())); - fields.add_field_method_get("filetree", |_, this| Ok(this.filetree())); 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/workspace.rs b/src/ffi/python/workspace.rs index 425301d..263704f 100644 --- a/src/ffi/python/workspace.rs +++ b/src/ffi/python/workspace.rs @@ -72,7 +72,7 @@ impl Workspace { .list_buffer_users(path.as_str()) .await? .into_iter() - .map(|e| e.id) + .map(|e| e.id.to_string()) .collect(); Ok(usrlist) @@ -118,8 +118,8 @@ impl Workspace { } #[pyo3(name = "filetree")] - fn pyfiletree(&self) -> Vec { - self.filetree() + fn pyfiletree(&self, filter: Option<&str>) -> Vec { + self.filetree(filter) } } diff --git a/src/workspace/worker.rs b/src/workspace/worker.rs index 7e83dd7..b3aa61c 100644 --- a/src/workspace/worker.rs +++ b/src/workspace/worker.rs @@ -332,8 +332,11 @@ impl Workspace { /// get the currently cached "filetree" // #[cfg_attr(feature = "js", napi)] // https://github.com/napi-rs/napi-rs/issues/1120 - pub fn filetree(&self) -> Vec { - self.0.filetree.iter().map(|f| f.clone()).collect() + pub fn filetree(&self, filter: Option<&str>) -> Vec { + self.0.filetree.iter() + .filter(|f| filter.map_or(true, |flt| f.starts_with(flt))) + .map(|f| f.clone()) + .collect() } }