mirror of
https://github.com/hexedtech/codemp.git
synced 2024-12-23 05:14:54 +01:00
feat: strict filetree()
This commit is contained in:
parent
c0b8906043
commit
92d181246e
6 changed files with 23 additions and 15 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;
|
||||
|
|
|
@ -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