Skip to content

Commit

Permalink
feat: add config for not showing order #28
Browse files Browse the repository at this point in the history
add config `show_order_in_label`, default true
  • Loading branch information
wlh320 committed Sep 12, 2024
1 parent 8c5ae91 commit 3b57baa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ pub struct Config {
/// if showing filter_text in label
#[serde(default = "default_show_filter_text_in_label")]
pub show_filter_text_in_label: bool,
/// if showing order in label
#[serde(default = "default_show_order_in_label")]
pub show_order_in_label: bool,
}

/// settings that can be tweaked during running
Expand All @@ -69,6 +72,8 @@ pub struct Settings {
pub long_filter_text: Option<bool>,
/// if showing filter_text in label
pub show_filter_text_in_label: Option<bool>,
/// if showing order in label
pub show_order_in_label: Option<bool>,
}

macro_rules! apply_setting {
Expand Down Expand Up @@ -102,6 +107,7 @@ impl Default for Config {
preselect_first: default_preselect_first(),
long_filter_text: default_long_filter_text(),
show_filter_text_in_label: default_show_filter_text_in_label(),
show_order_in_label: default_show_order_in_label(),
}
}
}
Expand Down Expand Up @@ -160,6 +166,10 @@ fn default_show_filter_text_in_label() -> bool {
false
}

fn default_show_order_in_label() -> bool {
true
}

#[test]
fn test_default_config() {
let config: Config = Default::default();
Expand Down Expand Up @@ -191,6 +201,7 @@ fn test_apply_settings() {
preselect_first: None,
long_filter_text: None,
show_filter_text_in_label: Some(true),
show_order_in_label: Some(false),
};
// apply settings with macro
let mut test_val = vec!["baz".to_string()];
Expand All @@ -202,6 +213,7 @@ fn test_apply_settings() {
});
apply_setting!(config <- settings.schema_trigger_character);
apply_setting!(config <- settings.show_filter_text_in_label);
apply_setting!(config <- settings.show_order_in_label);
// verify
assert_eq!(config.enabled, false);
assert_eq!(config.max_candidates, 100);
Expand All @@ -212,5 +224,6 @@ fn test_apply_settings() {
assert_eq!(config.trigger_characters, vec!["foo".to_string()]);
assert_eq!(config.schema_trigger_character, String::from("bar"));
assert_eq!(config.show_filter_text_in_label, true);
assert_eq!(config.show_order_in_label, false);
assert_eq!(test_val, vec!["foo".to_string()]);
}
7 changes: 5 additions & 2 deletions src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl Backend {
apply_setting!(config <- settings.preselect_first);
apply_setting!(config <- settings.long_filter_text);
apply_setting!(config <- settings.show_filter_text_in_label);
apply_setting!(config <- settings.show_order_in_label);
}

async fn create_work_done_progress(&self, token: NumberOrString) -> Result<NumberOrString> {
Expand Down Expand Up @@ -213,10 +214,11 @@ impl Backend {
drop(last_state);

// convert candidates to completions
let (show_filter_text_in_label, preselect_enabled, max_candidates) = {
let (show_filter_text_in_label, show_order_in_label, preselect_enabled, max_candidates) = {
let config = self.config.read().await;
(
config.show_filter_text_in_label,
config.show_order_in_label,
config.preselect_first,
config.max_candidates,
)
Expand All @@ -230,7 +232,8 @@ impl Backend {
};
let mut label = match c.order {
0 => text.clone(),
_ => format!("{}. {}", c.order, &text),
_ if show_order_in_label => format!("{}. {}", c.order, &text),
_ => text.clone(),
};
if show_filter_text_in_label {
label += &format!(" ({})", filter_text);
Expand Down

0 comments on commit 3b57baa

Please sign in to comment.