style(config): fix formatting
This commit is contained in:
parent
9202c1189c
commit
be68a1f8ff
|
@ -269,14 +269,15 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let parsed_config: ParsedConfig = config.try_into().unwrap();
|
let parsed_config: ParsedConfig = config.try_into().unwrap();
|
||||||
|
|
||||||
let keyboard_layout: BTreeMap<String, String> =
|
let keyboard_layout: BTreeMap<String, String> = vec![
|
||||||
vec![
|
("rules".to_string(), "test_rule".to_string()),
|
||||||
("rules".to_string(), "test_rule".to_string()),
|
("model".to_string(), "test_model".to_string()),
|
||||||
("model".to_string(), "test_model".to_string()),
|
("layout".to_string(), "test_layout".to_string()),
|
||||||
("layout".to_string(), "test_layout".to_string()),
|
("variant".to_string(), "test_variant".to_string()),
|
||||||
("variant".to_string(), "test_variant".to_string()),
|
("options".to_string(), "test_options".to_string()),
|
||||||
("options".to_string(), "test_options".to_string()),
|
]
|
||||||
].into_iter().collect();
|
.into_iter()
|
||||||
|
.collect();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parsed_config,
|
parsed_config,
|
||||||
|
|
|
@ -17,13 +17,22 @@
|
||||||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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 crate::{counter::next_id, merge};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use log::error;
|
use log::error;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
use std::path::PathBuf;
|
||||||
use std::{collections::HashSet, path::Path};
|
use std::{collections::HashSet, path::Path};
|
||||||
use std::{path::PathBuf};
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
const STANDARD_INCLUDES: &[&str] = &["../match/**/*.yml"];
|
const STANDARD_INCLUDES: &[&str] = &["../match/**/*.yml"];
|
||||||
|
@ -240,16 +249,18 @@ impl Config for ResolvedConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn word_separators(&self) -> Vec<String> {
|
fn word_separators(&self) -> Vec<String> {
|
||||||
self.parsed.word_separators.clone().unwrap_or_else(|| vec![
|
self.parsed.word_separators.clone().unwrap_or_else(|| {
|
||||||
" ".to_string(),
|
vec![
|
||||||
",".to_string(),
|
" ".to_string(),
|
||||||
".".to_string(),
|
",".to_string(),
|
||||||
"?".to_string(),
|
".".to_string(),
|
||||||
"!".to_string(),
|
"?".to_string(),
|
||||||
"\r".to_string(),
|
"!".to_string(),
|
||||||
"\n".to_string(),
|
"\r".to_string(),
|
||||||
(22u8 as char).to_string(),
|
"\n".to_string(),
|
||||||
])
|
(22u8 as char).to_string(),
|
||||||
|
]
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn backspace_limit(&self) -> usize {
|
fn backspace_limit(&self) -> usize {
|
||||||
|
@ -261,13 +272,17 @@ impl Config for ResolvedConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn keyboard_layout(&self) -> Option<RMLVOConfig> {
|
fn keyboard_layout(&self) -> Option<RMLVOConfig> {
|
||||||
self.parsed.keyboard_layout.as_ref().map(|layout| RMLVOConfig {
|
self
|
||||||
rules: layout.get("rules").map(String::from),
|
.parsed
|
||||||
model: layout.get("model").map(String::from),
|
.keyboard_layout
|
||||||
layout: layout.get("layout").map(String::from),
|
.as_ref()
|
||||||
variant: layout.get("variant").map(String::from),
|
.map(|layout| RMLVOConfig {
|
||||||
options: layout.get("options").map(String::from),
|
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<String> {
|
fn search_trigger(&self) -> Option<String> {
|
||||||
|
@ -459,7 +474,10 @@ impl ResolvedConfig {
|
||||||
let exclude_paths = calculate_paths(base_dir, excludes.iter());
|
let exclude_paths = calculate_paths(base_dir, excludes.iter());
|
||||||
let include_paths = calculate_paths(base_dir, includes.iter());
|
let include_paths = calculate_paths(base_dir, includes.iter());
|
||||||
|
|
||||||
include_paths.difference(&exclude_paths).cloned().collect::<HashSet<_>>()
|
include_paths
|
||||||
|
.difference(&exclude_paths)
|
||||||
|
.cloned()
|
||||||
|
.collect::<HashSet<_>>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -481,7 +499,10 @@ mod tests {
|
||||||
ResolvedConfig::aggregate_includes(&ParsedConfig {
|
ResolvedConfig::aggregate_includes(&ParsedConfig {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
vec!["../match/**/*.yml".to_string(),].iter().cloned().collect::<HashSet<_>>()
|
vec!["../match/**/*.yml".to_string(),]
|
||||||
|
.iter()
|
||||||
|
.cloned()
|
||||||
|
.collect::<HashSet<_>>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,8 +525,9 @@ mod tests {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
vec!["../match/**/*.yml".to_string(), "custom/*.yml".to_string()]
|
vec!["../match/**/*.yml".to_string(), "custom/*.yml".to_string()]
|
||||||
.iter()
|
.iter()
|
||||||
.cloned().collect::<HashSet<_>>()
|
.cloned()
|
||||||
|
.collect::<HashSet<_>>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,8 +539,9 @@ mod tests {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
vec!["../match/**/*.yml".to_string(), "custom/*.yml".to_string()]
|
vec!["../match/**/*.yml".to_string(), "custom/*.yml".to_string()]
|
||||||
.iter()
|
.iter()
|
||||||
.cloned().collect::<HashSet<_>>()
|
.cloned()
|
||||||
|
.collect::<HashSet<_>>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -531,12 +554,13 @@ mod tests {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
vec![
|
vec![
|
||||||
"../match/**/*.yml".to_string(),
|
"../match/**/*.yml".to_string(),
|
||||||
"custom/*.yml".to_string(),
|
"custom/*.yml".to_string(),
|
||||||
"sub/*.yml".to_string()
|
"sub/*.yml".to_string()
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.cloned().collect::<HashSet<_>>()
|
.cloned()
|
||||||
|
.collect::<HashSet<_>>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -546,7 +570,10 @@ mod tests {
|
||||||
ResolvedConfig::aggregate_excludes(&ParsedConfig {
|
ResolvedConfig::aggregate_excludes(&ParsedConfig {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
vec!["../match/**/_*.yml".to_string(),].iter().cloned().collect::<HashSet<_>>()
|
vec!["../match/**/_*.yml".to_string(),]
|
||||||
|
.iter()
|
||||||
|
.cloned()
|
||||||
|
.collect::<HashSet<_>>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -569,8 +596,9 @@ mod tests {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
vec!["../match/**/_*.yml".to_string(), "custom/*.yml".to_string()]
|
vec!["../match/**/_*.yml".to_string(), "custom/*.yml".to_string()]
|
||||||
.iter()
|
.iter()
|
||||||
.cloned().collect::<HashSet<_>>()
|
.cloned()
|
||||||
|
.collect::<HashSet<_>>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -582,8 +610,9 @@ mod tests {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
vec!["../match/**/_*.yml".to_string(), "custom/*.yml".to_string()]
|
vec!["../match/**/_*.yml".to_string(), "custom/*.yml".to_string()]
|
||||||
.iter()
|
.iter()
|
||||||
.cloned().collect::<HashSet<_>>()
|
.cloned()
|
||||||
|
.collect::<HashSet<_>>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,12 +625,13 @@ mod tests {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
vec![
|
vec![
|
||||||
"../match/**/_*.yml".to_string(),
|
"../match/**/_*.yml".to_string(),
|
||||||
"custom/*.yml".to_string(),
|
"custom/*.yml".to_string(),
|
||||||
"sub/*.yml".to_string()
|
"sub/*.yml".to_string()
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.cloned().collect::<HashSet<_>>()
|
.cloned()
|
||||||
|
.collect::<HashSet<_>>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::path::{Path, PathBuf};
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct NonFatalErrorSet {
|
pub struct NonFatalErrorSet {
|
||||||
|
|
|
@ -976,8 +976,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_config_set_load_fail_bad_directory() {
|
fn test_config_set_load_fail_bad_directory() {
|
||||||
let config_set =
|
let config_set = LegacyConfigSet::load(Path::new("invalid/path"), Path::new("invalid/path"));
|
||||||
LegacyConfigSet::load(Path::new("invalid/path"), Path::new("invalid/path"));
|
|
||||||
assert!(config_set.is_err());
|
assert!(config_set.is_err());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
config_set.unwrap_err(),
|
config_set.unwrap_err(),
|
||||||
|
@ -1606,9 +1605,10 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_list_has_conflict_no_conflict() {
|
fn test_list_has_conflict_no_conflict() {
|
||||||
assert!(
|
assert!(!LegacyConfigSet::list_has_conflicts(&[
|
||||||
!LegacyConfigSet::list_has_conflicts(&[":ab".to_owned(), ":bc".to_owned()])
|
":ab".to_owned(),
|
||||||
);
|
":bc".to_owned()
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1643,9 +1643,10 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let config_set = LegacyConfigSet::load(data_dir.path(), package_dir.path()).unwrap();
|
let config_set = LegacyConfigSet::load(data_dir.path(), package_dir.path()).unwrap();
|
||||||
assert!(
|
assert!(!LegacyConfigSet::has_conflicts(
|
||||||
!LegacyConfigSet::has_conflicts(&config_set.default, &config_set.specific),
|
&config_set.default,
|
||||||
);
|
&config_set.specific
|
||||||
|
),);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1675,9 +1676,10 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let config_set = LegacyConfigSet::load(data_dir.path(), package_dir.path()).unwrap();
|
let config_set = LegacyConfigSet::load(data_dir.path(), package_dir.path()).unwrap();
|
||||||
assert!(
|
assert!(LegacyConfigSet::has_conflicts(
|
||||||
LegacyConfigSet::has_conflicts(&config_set.default, &config_set.specific),
|
&config_set.default,
|
||||||
);
|
&config_set.specific
|
||||||
|
),);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1705,9 +1707,10 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let config_set = LegacyConfigSet::load(data_dir.path(), package_dir.path()).unwrap();
|
let config_set = LegacyConfigSet::load(data_dir.path(), package_dir.path()).unwrap();
|
||||||
assert!(
|
assert!(LegacyConfigSet::has_conflicts(
|
||||||
LegacyConfigSet::has_conflicts(&config_set.default, &config_set.specific),
|
&config_set.default,
|
||||||
);
|
&config_set.specific
|
||||||
|
),);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1746,9 +1749,10 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let config_set = LegacyConfigSet::load(data_dir.path(), package_dir.path()).unwrap();
|
let config_set = LegacyConfigSet::load(data_dir.path(), package_dir.path()).unwrap();
|
||||||
assert!(
|
assert!(!LegacyConfigSet::has_conflicts(
|
||||||
!LegacyConfigSet::has_conflicts(&config_set.default, &config_set.specific),
|
&config_set.default,
|
||||||
);
|
&config_set.specific
|
||||||
|
),);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -34,7 +34,13 @@ pub mod matches;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
pub fn load(base_path: &Path) -> Result<(Box<dyn ConfigStore>, Box<dyn MatchStore>, Vec<error::NonFatalErrorSet>)> {
|
pub fn load(
|
||||||
|
base_path: &Path,
|
||||||
|
) -> Result<(
|
||||||
|
Box<dyn ConfigStore>,
|
||||||
|
Box<dyn MatchStore>,
|
||||||
|
Vec<error::NonFatalErrorSet>,
|
||||||
|
)> {
|
||||||
let config_dir = base_path.join("config");
|
let config_dir = base_path.join("config");
|
||||||
if !config_dir.exists() || !config_dir.is_dir() {
|
if !config_dir.exists() || !config_dir.is_dir() {
|
||||||
return Err(ConfigError::MissingConfigDir().into());
|
return Err(ConfigError::MissingConfigDir().into());
|
||||||
|
@ -43,16 +49,24 @@ pub fn load(base_path: &Path) -> Result<(Box<dyn ConfigStore>, Box<dyn MatchStor
|
||||||
let (config_store, non_fatal_config_errors) = config::load_store(&config_dir)?;
|
let (config_store, non_fatal_config_errors) = config::load_store(&config_dir)?;
|
||||||
let root_paths = config_store.get_all_match_paths();
|
let root_paths = config_store.get_all_match_paths();
|
||||||
|
|
||||||
let (match_store, non_fatal_match_errors) = matches::store::load(&root_paths.into_iter().collect::<Vec<String>>());
|
let (match_store, non_fatal_match_errors) =
|
||||||
|
matches::store::load(&root_paths.into_iter().collect::<Vec<String>>());
|
||||||
|
|
||||||
let mut non_fatal_errors = Vec::new();
|
let mut non_fatal_errors = Vec::new();
|
||||||
non_fatal_errors.extend(non_fatal_config_errors.into_iter());
|
non_fatal_errors.extend(non_fatal_config_errors.into_iter());
|
||||||
non_fatal_errors.extend(non_fatal_match_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<dyn ConfigStore>, Box<dyn MatchStore>)> {
|
pub fn load_legacy(
|
||||||
|
config_dir: &Path,
|
||||||
|
package_dir: &Path,
|
||||||
|
) -> Result<(Box<dyn ConfigStore>, Box<dyn MatchStore>)> {
|
||||||
legacy::load(config_dir, package_dir)
|
legacy::load(config_dir, package_dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +84,7 @@ pub enum ConfigError {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::util::tests::use_test_directory;
|
use crate::util::tests::use_test_directory;
|
||||||
use config::{AppProperties};
|
use config::AppProperties;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn load_works_correctly() {
|
fn load_works_correctly() {
|
||||||
|
@ -280,11 +294,15 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let config_file = config_dir.join("default.yml");
|
let config_file = config_dir.join("default.yml");
|
||||||
std::fs::write(&config_file, r#"
|
std::fs::write(
|
||||||
|
&config_file,
|
||||||
|
r#"
|
||||||
invalid
|
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());
|
assert!(load(base).is_err());
|
||||||
|
|
|
@ -17,11 +17,11 @@
|
||||||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::{path::Path};
|
use std::path::Path;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_yaml::{Mapping};
|
use serde_yaml::Mapping;
|
||||||
|
|
||||||
use crate::util::is_yaml_empty;
|
use crate::util::is_yaml_empty;
|
||||||
|
|
||||||
|
|
|
@ -140,17 +140,26 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn convert_value_params() {
|
fn convert_value_params() {
|
||||||
let mut mapping = serde_yaml::Mapping::new();
|
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();
|
let mut expected = Params::new();
|
||||||
expected.insert("test".to_string(), Value::Null);
|
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]
|
#[test]
|
||||||
fn convert_params_works_correctly() {
|
fn convert_params_works_correctly() {
|
||||||
let mut mapping = serde_yaml::Mapping::new();
|
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();
|
let mut expected = Params::new();
|
||||||
expected.insert("test".to_string(), Value::Null);
|
expected.insert("test".to_string(), Value::Null);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user