ivy.nvim/rust/matcher.rs

25 lines
574 B
Rust
Raw Normal View History

use fuzzy_matcher::skim::SkimMatcherV2;
2022-08-26 09:25:05 +00:00
use fuzzy_matcher::FuzzyMatcher;
pub struct Matcher {
/// The search pattern that we want to match against some text
pub pattern: String,
matcher: SkimMatcherV2,
}
impl Matcher {
pub fn new(pattern: String) -> Self {
2022-08-26 09:25:05 +00:00
Self {
pattern,
matcher: SkimMatcherV2::default(),
}
}
pub fn score(&self, text: &str) -> i64 {
2022-08-26 09:25:05 +00:00
self.matcher
.fuzzy_indices(text, &self.pattern)
2022-08-26 09:25:05 +00:00
.map(|(score, _indices)| score)
.unwrap_or_default()
}
}