mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-25 08:34:47 +01:00
chore: merge branch 'config'
This commit is contained in:
commit
5701a0c49e
8 changed files with 27 additions and 18 deletions
6
dist/java/src/mp/code/Workspace.java
vendored
6
dist/java/src/mp/code/Workspace.java
vendored
|
@ -30,9 +30,9 @@ public class Workspace {
|
|||
return Optional.ofNullable(get_buffer(this.ptr, path));
|
||||
}
|
||||
|
||||
private static native String[] get_file_tree(long self, String filter);
|
||||
public String[] getFileTree(Optional<String> filter) {
|
||||
return get_file_tree(this.ptr, filter.orElse(null));
|
||||
private static native String[] get_file_tree(long self, String filter, boolean strict);
|
||||
public String[] getFileTree(Optional<String> filter, boolean strict) {
|
||||
return get_file_tree(this.ptr, filter.orElse(null), strict);
|
||||
}
|
||||
|
||||
private static native void create_buffer(String path) throws ConnectionRemoteException;
|
||||
|
|
5
dist/lua/annotations.lua
vendored
5
dist/lua/annotations.lua
vendored
|
@ -147,10 +147,11 @@ function Workspace:attach_buffer(path) end
|
|||
---detach from an active buffer, closing all streams. returns false if buffer was no longer active
|
||||
function Workspace:detach_buffer(path) end
|
||||
|
||||
---@param filter? string only return elements starting with given filter
|
||||
---@param filter? string apply a filter to the return elements
|
||||
---@param strict boolean whether to strictly match or just check whether it starts with it
|
||||
---@return string[]
|
||||
---return the list of available buffers in this workspace, as relative paths from workspace root
|
||||
function Workspace:filetree(filter) end
|
||||
function Workspace:filetree(filter, strict) end
|
||||
|
||||
---@return NilPromise
|
||||
---@async
|
||||
|
|
2
dist/py/src/codemp/codemp.pyi
vendored
2
dist/py/src/codemp/codemp.pyi
vendored
|
@ -66,7 +66,7 @@ class Workspace:
|
|||
def cursor(self) -> CursorController: ...
|
||||
def buffer_by_name(self, path: str) -> Optional[BufferController]: ...
|
||||
def buffer_list(self) -> list[str]: ...
|
||||
def filetree(self, filter: Optional[str]) -> list[str]: ...
|
||||
def filetree(self, filter: Optional[str], strict: bool) -> list[str]: ...
|
||||
|
||||
class TextChange:
|
||||
"""
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use jni::{objects::{JClass, JObject, JString, JValueGen}, sys::{jlong, jobject, jobjectArray, jstring}, JNIEnv};
|
||||
use jni::{objects::{JClass, JObject, JString, JValueGen}, sys::{jboolean, jlong, jobject, jobjectArray, jstring}, JNIEnv};
|
||||
use crate::Workspace;
|
||||
|
||||
use super::{JExceptable, JObjectify, RT};
|
||||
|
@ -69,7 +69,8 @@ pub extern "system" fn Java_mp_code_Workspace_get_1file_1tree(
|
|||
mut env: JNIEnv,
|
||||
_class: JClass,
|
||||
self_ptr: jlong,
|
||||
filter: JString
|
||||
filter: JString,
|
||||
strict: jboolean
|
||||
) -> jobjectArray {
|
||||
let workspace = unsafe { Box::leak(Box::from_raw(self_ptr as *mut Workspace)) };
|
||||
let filter: Option<String> = if filter.is_null() {
|
||||
|
@ -82,7 +83,7 @@ pub extern "system" fn Java_mp_code_Workspace_get_1file_1tree(
|
|||
)
|
||||
};
|
||||
|
||||
let file_tree = workspace.filetree(filter.as_deref());
|
||||
let file_tree = workspace.filetree(filter.as_deref(), strict != 0);
|
||||
env.find_class("java/lang/String")
|
||||
.and_then(|class| env.new_object_array(file_tree.len() as i32, class, JObject::null()))
|
||||
.inspect(|arr| {
|
||||
|
|
|
@ -12,8 +12,8 @@ impl Workspace {
|
|||
}
|
||||
|
||||
#[napi(js_name = "filetree")]
|
||||
pub fn js_filetree(&self, filter: Option<&str>) -> Vec<String> {
|
||||
self.filetree(filter)
|
||||
pub fn js_filetree(&self, filter: Option<&str>, strict: bool) -> Vec<String> {
|
||||
self.filetree(filter, strict)
|
||||
}
|
||||
|
||||
#[napi(js_name = "cursor")]
|
||||
|
|
|
@ -294,8 +294,8 @@ impl LuaUserData for CodempWorkspace {
|
|||
// Ok(())
|
||||
// });
|
||||
|
||||
methods.add_method("filetree", |_, this, (filter,):(Option<String>,)|
|
||||
Ok(this.filetree(filter.as_deref()))
|
||||
methods.add_method("filetree", |_, this, (filter, strict,):(Option<String>, bool,)|
|
||||
Ok(this.filetree(filter.as_deref(), strict))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -82,8 +82,8 @@ impl Workspace {
|
|||
}
|
||||
|
||||
#[pyo3(name = "filetree")]
|
||||
#[pyo3(signature = (filter=None))]
|
||||
fn pyfiletree(&self, filter: Option<&str>) -> Vec<String> {
|
||||
self.filetree(filter)
|
||||
#[pyo3(signature = (filter=None, strict=false))]
|
||||
fn pyfiletree(&self, filter: Option<&str>, strict: bool) -> Vec<String> {
|
||||
self.filetree(filter, strict)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -279,10 +279,17 @@ impl Workspace {
|
|||
}
|
||||
|
||||
/// Get the filetree as it is currently cached.
|
||||
/// A filter may be applied, and it may be strict (equality check) or not (starts_with check).
|
||||
// #[cfg_attr(feature = "js", napi)] // https://github.com/napi-rs/napi-rs/issues/1120
|
||||
pub fn filetree(&self, filter: Option<&str>) -> Vec<String> {
|
||||
pub fn filetree(&self, filter: Option<&str>, strict: bool) -> Vec<String> {
|
||||
self.0.filetree.iter()
|
||||
.filter(|f| filter.map_or(true, |flt| f.starts_with(flt)))
|
||||
.filter(|f| filter.map_or(true, |flt| {
|
||||
if strict {
|
||||
f.eq(flt)
|
||||
} else {
|
||||
f.starts_with(flt)
|
||||
}
|
||||
}))
|
||||
.map(|f| f.clone())
|
||||
.collect()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue