Skip to content

Commit

Permalink
Test load config
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchengxu committed Oct 31, 2023
1 parent d20b3c1 commit 5547fbc
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 19 deletions.
24 changes: 18 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 50 additions & 13 deletions crates/maple_core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn config_file() -> &'static PathBuf {
CONFIG_FILE.get().expect("Config file uninitialized")
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct MatcherConfig {
pub tiebreak: String,
Expand All @@ -78,7 +78,7 @@ impl MatcherConfig {
}
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct LogConfig {
pub log_file: Option<String>,
Expand All @@ -94,7 +94,7 @@ impl Default for LogConfig {
}
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct CursorWordConfig {
/// Whether to enable this plugin.
Expand All @@ -115,21 +115,21 @@ impl Default for CursorWordConfig {
}
}

#[derive(Serialize, Deserialize, Debug, Default)]
#[derive(Serialize, Deserialize, Debug, Default, Eq, PartialEq)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct MarkdownPluginConfig {
/// Whether to enable this plugin.
pub enable: bool,
}

#[derive(Serialize, Deserialize, Debug, Default)]
#[derive(Serialize, Deserialize, Debug, Default, Eq, PartialEq)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct CtagsPluginConfig {
/// Whether to enable this plugin.
pub enable: bool,
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct GitPluginConfig {
/// Whether to enable this plugin.
Expand All @@ -150,14 +150,14 @@ impl Default for GitPluginConfig {
}
}

#[derive(Serialize, Deserialize, Debug, Default)]
#[derive(Serialize, Deserialize, Debug, Default, Eq, PartialEq)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct LinterPluginConfig {
/// Whether to enable this plugin.
pub enable: bool,
}

#[derive(Serialize, Deserialize, Debug, Default)]
#[derive(Serialize, Deserialize, Debug, Default, Eq, PartialEq)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct PluginConfig {
pub cursorword: CursorWordConfig,
Expand All @@ -167,7 +167,7 @@ pub struct PluginConfig {
pub markdown: MarkdownPluginConfig,
}

#[derive(Serialize, Deserialize, Debug, Default)]
#[derive(Serialize, Deserialize, Debug, Default, Eq, PartialEq)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct IgnoreConfig {
/// Whether to ignore the comment line when it's possible.
Expand All @@ -180,7 +180,7 @@ pub struct IgnoreConfig {
pub ignore_file_path_pattern: Vec<String>,
}

#[derive(Serialize, Deserialize, Debug, Default)]
#[derive(Serialize, Deserialize, Debug, Default, Eq, PartialEq)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct ProviderConfig {
/// Delay in milliseconds before the user query will be handled actually.
Expand Down Expand Up @@ -217,7 +217,7 @@ pub struct ProviderConfig {
pub share_input_history: bool,
}

#[derive(Serialize, Deserialize, Debug, Default)]
#[derive(Serialize, Deserialize, Debug, Default, Eq, PartialEq)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct Config {
/// Log configuration.
Expand Down Expand Up @@ -299,7 +299,44 @@ mod tests {
"#;
let user_config: Config =
toml::from_str(toml_content).expect("Failed to deserialize config");
println!("{:#?}", user_config);
println!("{}", toml::to_string(&user_config).unwrap());

assert_eq!(
user_config,
Config {
log: LogConfig {
log_file: Some("/tmp/clap.log".to_string()),
max_level: "trace".to_string()
},
matcher: MatcherConfig {
tiebreak: "score,-begin,-end,-length".to_string()
},
plugin: PluginConfig {
cursorword: CursorWordConfig {
enable: true,
..Default::default()
},
..Default::default()
},
provider: ProviderConfig {
debounce: HashMap::from_iter([
("*".to_string(), 200),
("files".to_string(), 100)
]),
ignore: HashMap::from([(
"dumb_jump".to_string(),
IgnoreConfig {
ignore_comments: true,
..Default::default()
}
)]),
..Default::default()
},
global_ignore: IgnoreConfig {
ignore_file_path_pattern: vec!["test".to_string(), "build".to_string()],
..Default::default()
},
..Default::default()
}
);
}
}

0 comments on commit 5547fbc

Please sign in to comment.