feat(service): Plugins may define a priority for their results

Adds an additional parameter for prioritizing the search results from a
specific plugin. The plugin may define a priority which will sort
results after the initial pattern search. The web plugin will be the
first plugin to utilize this feature
This commit is contained in:
Michael Aaron Murphy 2021-08-23 19:54:04 +02:00
parent 454ce19f08
commit 8987565a2a
4 changed files with 36 additions and 1 deletions

View file

@ -52,6 +52,9 @@ pub struct PluginQuery {
#[serde(default)]
pub persistent: bool,
#[serde(default)]
pub priority: PluginPriority,
#[serde(
default,
skip_serializing_if = "Option::is_none",
@ -60,6 +63,19 @@ pub struct PluginQuery {
pub regex: Option<Cow<'static, str>>,
}
#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub enum PluginPriority {
High = 0,
Default = 1,
Low = 2,
}
impl Default for PluginPriority {
fn default() -> Self {
Self::Default
}
}
pub fn load(source: &Path, config_path: &Path) -> Option<(PathBuf, PluginConfig, Option<Regex>)> {
if let Ok(config_bytes) = std::fs::read_to_string(&config_path) {
let config = match ron::from_str::<PluginConfig>(&config_bytes) {