From 9ad3af89c0d92fbfdaa1f79bf7f93c60200f3831 Mon Sep 17 00:00:00 2001 From: Kirottu Date: Tue, 27 Jun 2023 23:57:53 +0300 Subject: [PATCH] Added prefix to symbols plugin --- plugins/symbols/src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/symbols/src/lib.rs b/plugins/symbols/src/lib.rs index 78e0e32..8a5e9be 100644 --- a/plugins/symbols/src/lib.rs +++ b/plugins/symbols/src/lib.rs @@ -15,6 +15,7 @@ struct Symbol { #[derive(Deserialize, Debug)] struct Config { + prefix: String, symbols: HashMap, max_entries: usize, } @@ -22,6 +23,7 @@ struct Config { impl Default for Config { fn default() -> Self { Self { + prefix: "".to_string(), symbols: HashMap::new(), max_entries: 3, } @@ -62,13 +64,18 @@ fn info() -> PluginInfo { #[get_matches] fn get_matches(input: RString, state: &State) -> RVec { + let input = if let Some(input) = input.strip_prefix(&state.config.prefix) { + input.trim() + } else { + return RVec::new(); + }; let matcher = fuzzy_matcher::skim::SkimMatcherV2::default().ignore_case(); let mut symbols = state .symbols .iter() .filter_map(|symbol| { matcher - .fuzzy_match(&symbol.name, &input) + .fuzzy_match(&symbol.name, input) .map(|score| (symbol, score)) }) .collect::>();