diff --git a/espanso-config/src/config/default.rs b/espanso-config/src/config/default.rs index 8d308d3..09decba 100644 --- a/espanso-config/src/config/default.rs +++ b/espanso-config/src/config/default.rs @@ -20,4 +20,4 @@ pub(crate) const DEFAULT_CLIPBOARD_THRESHOLD: usize = 100; pub(crate) const DEFAULT_PRE_PASTE_DELAY: usize = 100; pub(crate) const DEFAULT_SHORTCUT_EVENT_DELAY: usize = 10; -pub(crate) const DEFAULT_RESTORE_CLIPBOARD_DELAY: usize = 300; \ No newline at end of file +pub(crate) const DEFAULT_RESTORE_CLIPBOARD_DELAY: usize = 300; diff --git a/espanso-config/src/config/parse/mod.rs b/espanso-config/src/config/parse/mod.rs index 00a21ab..134afc0 100644 --- a/espanso-config/src/config/parse/mod.rs +++ b/espanso-config/src/config/parse/mod.rs @@ -82,4 +82,4 @@ impl ParsedConfig { pub enum ParsedConfigError { #[error("can't load config `{0}`")] LoadFailed(#[from] anyhow::Error), -} \ No newline at end of file +} diff --git a/espanso-config/src/config/parse/yaml.rs b/espanso-config/src/config/parse/yaml.rs index 7d6234d..81e884d 100644 --- a/espanso-config/src/config/parse/yaml.rs +++ b/espanso-config/src/config/parse/yaml.rs @@ -269,14 +269,15 @@ mod tests { .unwrap(); let parsed_config: ParsedConfig = config.try_into().unwrap(); - let keyboard_layout: BTreeMap = - vec![ - ("rules".to_string(), "test_rule".to_string()), - ("model".to_string(), "test_model".to_string()), - ("layout".to_string(), "test_layout".to_string()), - ("variant".to_string(), "test_variant".to_string()), - ("options".to_string(), "test_options".to_string()), - ].into_iter().collect(); + let keyboard_layout: BTreeMap = vec![ + ("rules".to_string(), "test_rule".to_string()), + ("model".to_string(), "test_model".to_string()), + ("layout".to_string(), "test_layout".to_string()), + ("variant".to_string(), "test_variant".to_string()), + ("options".to_string(), "test_options".to_string()), + ] + .into_iter() + .collect(); assert_eq!( parsed_config, diff --git a/espanso-config/src/config/resolve.rs b/espanso-config/src/config/resolve.rs index e45f7cc..c147039 100644 --- a/espanso-config/src/config/resolve.rs +++ b/espanso-config/src/config/resolve.rs @@ -17,13 +17,22 @@ * along with espanso. If not, see . */ -use super::{AppProperties, Backend, Config, RMLVOConfig, ToggleKey, default::{DEFAULT_CLIPBOARD_THRESHOLD, DEFAULT_PRE_PASTE_DELAY, DEFAULT_RESTORE_CLIPBOARD_DELAY, DEFAULT_SHORTCUT_EVENT_DELAY}, parse::ParsedConfig, path::calculate_paths, util::os_matches}; +use super::{ + default::{ + DEFAULT_CLIPBOARD_THRESHOLD, DEFAULT_PRE_PASTE_DELAY, DEFAULT_RESTORE_CLIPBOARD_DELAY, + DEFAULT_SHORTCUT_EVENT_DELAY, + }, + parse::ParsedConfig, + path::calculate_paths, + util::os_matches, + AppProperties, Backend, Config, RMLVOConfig, ToggleKey, +}; use crate::{counter::next_id, merge}; use anyhow::Result; use log::error; use regex::Regex; +use std::path::PathBuf; use std::{collections::HashSet, path::Path}; -use std::{path::PathBuf}; use thiserror::Error; const STANDARD_INCLUDES: &[&str] = &["../match/**/*.yml"]; @@ -149,7 +158,7 @@ impl Config for ResolvedConfig { } } } - + fn enable(&self) -> bool { self.parsed.enable.unwrap_or(true) } @@ -240,16 +249,18 @@ impl Config for ResolvedConfig { } fn word_separators(&self) -> Vec { - self.parsed.word_separators.clone().unwrap_or_else(|| vec![ - " ".to_string(), - ",".to_string(), - ".".to_string(), - "?".to_string(), - "!".to_string(), - "\r".to_string(), - "\n".to_string(), - (22u8 as char).to_string(), - ]) + self.parsed.word_separators.clone().unwrap_or_else(|| { + vec![ + " ".to_string(), + ",".to_string(), + ".".to_string(), + "?".to_string(), + "!".to_string(), + "\r".to_string(), + "\n".to_string(), + (22u8 as char).to_string(), + ] + }) } fn backspace_limit(&self) -> usize { @@ -261,13 +272,17 @@ impl Config for ResolvedConfig { } fn keyboard_layout(&self) -> Option { - self.parsed.keyboard_layout.as_ref().map(|layout| RMLVOConfig { - rules: layout.get("rules").map(String::from), - model: layout.get("model").map(String::from), - layout: layout.get("layout").map(String::from), - variant: layout.get("variant").map(String::from), - options: layout.get("options").map(String::from), - }) + self + .parsed + .keyboard_layout + .as_ref() + .map(|layout| RMLVOConfig { + rules: layout.get("rules").map(String::from), + model: layout.get("model").map(String::from), + layout: layout.get("layout").map(String::from), + variant: layout.get("variant").map(String::from), + options: layout.get("options").map(String::from), + }) } fn search_trigger(&self) -> Option { @@ -459,7 +474,10 @@ impl ResolvedConfig { let exclude_paths = calculate_paths(base_dir, excludes.iter()); let include_paths = calculate_paths(base_dir, includes.iter()); - include_paths.difference(&exclude_paths).cloned().collect::>() + include_paths + .difference(&exclude_paths) + .cloned() + .collect::>() } } @@ -481,7 +499,10 @@ mod tests { ResolvedConfig::aggregate_includes(&ParsedConfig { ..Default::default() }), - vec!["../match/**/*.yml".to_string(),].iter().cloned().collect::>() + vec!["../match/**/*.yml".to_string(),] + .iter() + .cloned() + .collect::>() ); } @@ -504,8 +525,9 @@ mod tests { ..Default::default() }), vec!["../match/**/*.yml".to_string(), "custom/*.yml".to_string()] - .iter() - .cloned().collect::>() + .iter() + .cloned() + .collect::>() ); } @@ -517,8 +539,9 @@ mod tests { ..Default::default() }), vec!["../match/**/*.yml".to_string(), "custom/*.yml".to_string()] - .iter() - .cloned().collect::>() + .iter() + .cloned() + .collect::>() ); } @@ -531,12 +554,13 @@ mod tests { ..Default::default() }), vec![ - "../match/**/*.yml".to_string(), - "custom/*.yml".to_string(), - "sub/*.yml".to_string() - ] - .iter() - .cloned().collect::>() + "../match/**/*.yml".to_string(), + "custom/*.yml".to_string(), + "sub/*.yml".to_string() + ] + .iter() + .cloned() + .collect::>() ); } @@ -546,7 +570,10 @@ mod tests { ResolvedConfig::aggregate_excludes(&ParsedConfig { ..Default::default() }), - vec!["../match/**/_*.yml".to_string(),].iter().cloned().collect::>() + vec!["../match/**/_*.yml".to_string(),] + .iter() + .cloned() + .collect::>() ); } @@ -569,8 +596,9 @@ mod tests { ..Default::default() }), vec!["../match/**/_*.yml".to_string(), "custom/*.yml".to_string()] - .iter() - .cloned().collect::>() + .iter() + .cloned() + .collect::>() ); } @@ -582,8 +610,9 @@ mod tests { ..Default::default() }), vec!["../match/**/_*.yml".to_string(), "custom/*.yml".to_string()] - .iter() - .cloned().collect::>() + .iter() + .cloned() + .collect::>() ); } @@ -596,12 +625,13 @@ mod tests { ..Default::default() }), vec![ - "../match/**/_*.yml".to_string(), - "custom/*.yml".to_string(), - "sub/*.yml".to_string() - ] - .iter() - .cloned().collect::>() + "../match/**/_*.yml".to_string(), + "custom/*.yml".to_string(), + "sub/*.yml".to_string() + ] + .iter() + .cloned() + .collect::>() ); } diff --git a/espanso-config/src/error.rs b/espanso-config/src/error.rs index e55640d..d376013 100644 --- a/espanso-config/src/error.rs +++ b/espanso-config/src/error.rs @@ -17,8 +17,8 @@ * along with espanso. If not, see . */ -use std::path::{Path, PathBuf}; use anyhow::Error; +use std::path::{Path, PathBuf}; #[derive(Debug)] pub struct NonFatalErrorSet { @@ -68,4 +68,4 @@ impl ErrorRecord { pub enum ErrorLevel { Error, Warning, -} \ No newline at end of file +} diff --git a/espanso-config/src/legacy/config.rs b/espanso-config/src/legacy/config.rs index c3340b8..87ff50c 100644 --- a/espanso-config/src/legacy/config.rs +++ b/espanso-config/src/legacy/config.rs @@ -976,8 +976,7 @@ mod tests { #[test] fn test_config_set_load_fail_bad_directory() { - let config_set = - LegacyConfigSet::load(Path::new("invalid/path"), Path::new("invalid/path")); + let config_set = LegacyConfigSet::load(Path::new("invalid/path"), Path::new("invalid/path")); assert!(config_set.is_err()); assert_eq!( config_set.unwrap_err(), @@ -1606,9 +1605,10 @@ mod tests { #[test] fn test_list_has_conflict_no_conflict() { - assert!( - !LegacyConfigSet::list_has_conflicts(&[":ab".to_owned(), ":bc".to_owned()]) - ); + assert!(!LegacyConfigSet::list_has_conflicts(&[ + ":ab".to_owned(), + ":bc".to_owned() + ])); } #[test] @@ -1643,9 +1643,10 @@ mod tests { ); let config_set = LegacyConfigSet::load(data_dir.path(), package_dir.path()).unwrap(); - assert!( - !LegacyConfigSet::has_conflicts(&config_set.default, &config_set.specific), - ); + assert!(!LegacyConfigSet::has_conflicts( + &config_set.default, + &config_set.specific + ),); } #[test] @@ -1675,9 +1676,10 @@ mod tests { ); let config_set = LegacyConfigSet::load(data_dir.path(), package_dir.path()).unwrap(); - assert!( - LegacyConfigSet::has_conflicts(&config_set.default, &config_set.specific), - ); + assert!(LegacyConfigSet::has_conflicts( + &config_set.default, + &config_set.specific + ),); } #[test] @@ -1705,9 +1707,10 @@ mod tests { ); let config_set = LegacyConfigSet::load(data_dir.path(), package_dir.path()).unwrap(); - assert!( - LegacyConfigSet::has_conflicts(&config_set.default, &config_set.specific), - ); + assert!(LegacyConfigSet::has_conflicts( + &config_set.default, + &config_set.specific + ),); } #[test] @@ -1746,9 +1749,10 @@ mod tests { ); let config_set = LegacyConfigSet::load(data_dir.path(), package_dir.path()).unwrap(); - assert!( - !LegacyConfigSet::has_conflicts(&config_set.default, &config_set.specific), - ); + assert!(!LegacyConfigSet::has_conflicts( + &config_set.default, + &config_set.specific + ),); } #[test] diff --git a/espanso-config/src/legacy/mod.rs b/espanso-config/src/legacy/mod.rs index 8c75ce5..4efbb56 100644 --- a/espanso-config/src/legacy/mod.rs +++ b/espanso-config/src/legacy/mod.rs @@ -360,11 +360,11 @@ impl Config for LegacyInteropConfig { } fn search_trigger(&self) -> Option { - self.config.search_trigger.clone() + self.config.search_trigger.clone() } fn search_shortcut(&self) -> Option { - self.config.search_shortcut.clone() + self.config.search_shortcut.clone() } fn undo_backspace(&self) -> bool { @@ -390,7 +390,7 @@ impl Config for LegacyInteropConfig { fn win32_exclude_orphan_events(&self) -> bool { true } - + fn evdev_modifier_delay(&self) -> Option { Some(10) } diff --git a/espanso-config/src/lib.rs b/espanso-config/src/lib.rs index 5442a42..458d2d6 100644 --- a/espanso-config/src/lib.rs +++ b/espanso-config/src/lib.rs @@ -34,7 +34,13 @@ pub mod matches; mod util; #[allow(clippy::type_complexity)] -pub fn load(base_path: &Path) -> Result<(Box, Box, Vec)> { +pub fn load( + base_path: &Path, +) -> Result<( + Box, + Box, + Vec, +)> { let config_dir = base_path.join("config"); if !config_dir.exists() || !config_dir.is_dir() { return Err(ConfigError::MissingConfigDir().into()); @@ -43,16 +49,24 @@ pub fn load(base_path: &Path) -> Result<(Box, Box>()); + let (match_store, non_fatal_match_errors) = + matches::store::load(&root_paths.into_iter().collect::>()); let mut non_fatal_errors = Vec::new(); non_fatal_errors.extend(non_fatal_config_errors.into_iter()); non_fatal_errors.extend(non_fatal_match_errors.into_iter()); - Ok((Box::new(config_store), Box::new(match_store), non_fatal_errors)) + Ok(( + Box::new(config_store), + Box::new(match_store), + non_fatal_errors, + )) } -pub fn load_legacy(config_dir: &Path, package_dir: &Path) -> Result<(Box, Box)> { +pub fn load_legacy( + config_dir: &Path, + package_dir: &Path, +) -> Result<(Box, Box)> { legacy::load(config_dir, package_dir) } @@ -70,7 +84,7 @@ pub enum ConfigError { mod tests { use super::*; use crate::util::tests::use_test_directory; - use config::{AppProperties}; + use config::AppProperties; #[test] fn load_works_correctly() { @@ -222,12 +236,12 @@ mod tests { .unwrap(); let (config_store, match_store, errors) = load(base).unwrap(); - + assert_eq!(errors.len(), 3); // It shouldn't have loaded the "config.yml" one because of the YAML error assert_eq!(config_store.configs().len(), 1); // It shouldn't load "base.yml" and "_sub.yml" due to YAML errors - assert_eq!(match_store.loaded_paths().len(), 1); + assert_eq!(match_store.loaded_paths().len(), 1); }); } @@ -250,7 +264,7 @@ mod tests { std::fs::write(&config_file, r#""#).unwrap(); let (config_store, match_store, errors) = load(base).unwrap(); - + assert_eq!(errors.len(), 1); assert_eq!(errors[0].file, base_file); assert_eq!(errors[0].errors.len(), 1); @@ -280,13 +294,17 @@ mod tests { .unwrap(); let config_file = config_dir.join("default.yml"); - std::fs::write(&config_file, r#" + std::fs::write( + &config_file, + r#" invalid " - "#).unwrap(); + "#, + ) + .unwrap(); - // A syntax error in the default.yml file cannot be handled gracefully + // A syntax error in the default.yml file cannot be handled gracefully assert!(load(base).is_err()); }); } diff --git a/espanso-config/src/matches/group/loader/yaml/parse.rs b/espanso-config/src/matches/group/loader/yaml/parse.rs index 6e2b172..39a18fa 100644 --- a/espanso-config/src/matches/group/loader/yaml/parse.rs +++ b/espanso-config/src/matches/group/loader/yaml/parse.rs @@ -17,11 +17,11 @@ * along with espanso. If not, see . */ -use std::{path::Path}; +use std::path::Path; use anyhow::Result; use serde::{Deserialize, Serialize}; -use serde_yaml::{Mapping}; +use serde_yaml::Mapping; use crate::util::is_yaml_empty; diff --git a/espanso-config/src/matches/group/loader/yaml/util.rs b/espanso-config/src/matches/group/loader/yaml/util.rs index a8f67a5..88e5c81 100644 --- a/espanso-config/src/matches/group/loader/yaml/util.rs +++ b/espanso-config/src/matches/group/loader/yaml/util.rs @@ -140,17 +140,26 @@ mod tests { #[test] fn convert_value_params() { let mut mapping = serde_yaml::Mapping::new(); - mapping.insert(serde_yaml::Value::String("test".to_string()), serde_yaml::Value::Null); + mapping.insert( + serde_yaml::Value::String("test".to_string()), + serde_yaml::Value::Null, + ); let mut expected = Params::new(); expected.insert("test".to_string(), Value::Null); - assert_eq!(convert_value(serde_yaml::Value::Mapping(mapping)).unwrap(), Value::Object(expected)); + assert_eq!( + convert_value(serde_yaml::Value::Mapping(mapping)).unwrap(), + Value::Object(expected) + ); } #[test] fn convert_params_works_correctly() { let mut mapping = serde_yaml::Mapping::new(); - mapping.insert(serde_yaml::Value::String("test".to_string()), serde_yaml::Value::Null); + mapping.insert( + serde_yaml::Value::String("test".to_string()), + serde_yaml::Value::Null, + ); let mut expected = Params::new(); expected.insert("test".to_string(), Value::Null);