Merge pull request #16 from hexedtech/feat/userlist

feat: add user_list, allow config::new with &str
This commit is contained in:
əlemi 2024-09-24 20:36:19 +02:00 committed by GitHub
commit 21cf2a6445
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 26 additions and 3 deletions

View file

@ -30,10 +30,10 @@ pub struct Config {
impl Config { impl Config {
/// construct a new Config object, with given username and password /// construct a new Config object, with given username and password
pub fn new(username: String, password: String) -> Self { pub fn new(username: impl ToString, password: impl ToString) -> Self {
Self { Self {
username, username: username.to_string(),
password, password: password.to_string(),
host: None, host: None,
port: None, port: None,
tls: None, tls: None,

View file

@ -16,6 +16,11 @@ impl Workspace {
self.filetree(filter, strict) self.filetree(filter, strict)
} }
#[napi(js_name = "user_list")]
pub fn js_user_list(&self) -> Vec<String> {
self.user_list()
}
#[napi(js_name = "cursor")] #[napi(js_name = "cursor")]
pub fn js_cursor(&self) -> CursorController { pub fn js_cursor(&self) -> CursorController {
self.cursor() self.cursor()

View file

@ -41,6 +41,10 @@ impl LuaUserData for CodempWorkspace {
methods.add_method("filetree", |_, this, (filter, strict,):(Option<String>, Option<bool>,)| methods.add_method("filetree", |_, this, (filter, strict,):(Option<String>, Option<bool>,)|
Ok(this.filetree(filter.as_deref(), strict.unwrap_or(false))) Ok(this.filetree(filter.as_deref(), strict.unwrap_or(false)))
); );
methods.add_method("user_list", |_, this, ()|
Ok(this.user_list())
);
} }
fn add_fields<F: LuaUserDataFields<Self>>(fields: &mut F) { fn add_fields<F: LuaUserDataFields<Self>>(fields: &mut F) {

View file

@ -86,4 +86,9 @@ impl Workspace {
fn pyfiletree(&self, filter: Option<&str>, strict: bool) -> Vec<String> { fn pyfiletree(&self, filter: Option<&str>, strict: bool) -> Vec<String> {
self.filetree(filter, strict) self.filetree(filter, strict)
} }
#[pyo3(name = "user_list")]
fn pyuser_list(&self) -> Vec<String> {
self.user_list()
}
} }

View file

@ -285,6 +285,15 @@ impl Workspace {
.collect() .collect()
} }
/// Get all names of users currently in this workspace
pub fn user_list(&self) -> Vec<String> {
self.0
.users
.iter()
.map(|elem| elem.value().name.clone())
.collect()
}
/// Get the filetree as it is currently cached. /// 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). /// 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 // #[cfg_attr(feature = "js", napi)] // https://github.com/napi-rs/napi-rs/issues/1120