diff --git a/src/config.rs b/src/config.rs index 848c856..a7e2ea8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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 @@ -69,6 +72,8 @@ pub struct Settings { pub long_filter_text: Option, /// if showing filter_text in label pub show_filter_text_in_label: Option, + /// if showing order in label + pub show_order_in_label: Option, } macro_rules! apply_setting { @@ -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(), } } } @@ -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(); @@ -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()]; @@ -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); @@ -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()]); } diff --git a/src/lsp.rs b/src/lsp.rs index bdbe21a..6bf657b 100644 --- a/src/lsp.rs +++ b/src/lsp.rs @@ -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 { @@ -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, ) @@ -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);