mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-21 23:04:49 +01:00
Merge pull request #16 from hexedtech/feat/userlist
feat: add user_list, allow config::new with &str
This commit is contained in:
commit
21cf2a6445
5 changed files with 26 additions and 3 deletions
|
@ -30,10 +30,10 @@ pub struct Config {
|
|||
|
||||
impl Config {
|
||||
/// 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 {
|
||||
username,
|
||||
password,
|
||||
username: username.to_string(),
|
||||
password: password.to_string(),
|
||||
host: None,
|
||||
port: None,
|
||||
tls: None,
|
||||
|
|
|
@ -16,6 +16,11 @@ impl Workspace {
|
|||
self.filetree(filter, strict)
|
||||
}
|
||||
|
||||
#[napi(js_name = "user_list")]
|
||||
pub fn js_user_list(&self) -> Vec<String> {
|
||||
self.user_list()
|
||||
}
|
||||
|
||||
#[napi(js_name = "cursor")]
|
||||
pub fn js_cursor(&self) -> CursorController {
|
||||
self.cursor()
|
||||
|
|
|
@ -41,6 +41,10 @@ impl LuaUserData for CodempWorkspace {
|
|||
methods.add_method("filetree", |_, this, (filter, strict,):(Option<String>, Option<bool>,)|
|
||||
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) {
|
||||
|
|
|
@ -86,4 +86,9 @@ impl Workspace {
|
|||
fn pyfiletree(&self, filter: Option<&str>, strict: bool) -> Vec<String> {
|
||||
self.filetree(filter, strict)
|
||||
}
|
||||
|
||||
#[pyo3(name = "user_list")]
|
||||
fn pyuser_list(&self) -> Vec<String> {
|
||||
self.user_list()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -285,6 +285,15 @@ impl Workspace {
|
|||
.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.
|
||||
/// 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
|
||||
|
|
Loading…
Reference in a new issue