Added prefix to symbols plugin

This commit is contained in:
Kirottu
2023-06-27 23:57:53 +03:00
parent e37a97b468
commit 9ad3af89c0

View File

@@ -15,6 +15,7 @@ struct Symbol {
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
struct Config { struct Config {
prefix: String,
symbols: HashMap<String, String>, symbols: HashMap<String, String>,
max_entries: usize, max_entries: usize,
} }
@@ -22,6 +23,7 @@ struct Config {
impl Default for Config { impl Default for Config {
fn default() -> Self { fn default() -> Self {
Self { Self {
prefix: "".to_string(),
symbols: HashMap::new(), symbols: HashMap::new(),
max_entries: 3, max_entries: 3,
} }
@@ -62,13 +64,18 @@ fn info() -> PluginInfo {
#[get_matches] #[get_matches]
fn get_matches(input: RString, state: &State) -> RVec<Match> { fn get_matches(input: RString, state: &State) -> RVec<Match> {
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 matcher = fuzzy_matcher::skim::SkimMatcherV2::default().ignore_case();
let mut symbols = state let mut symbols = state
.symbols .symbols
.iter() .iter()
.filter_map(|symbol| { .filter_map(|symbol| {
matcher matcher
.fuzzy_match(&symbol.name, &input) .fuzzy_match(&symbol.name, input)
.map(|score| (symbol, score)) .map(|score| (symbol, score))
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();