feat(config): Add new file types

Fixes #220
This commit is contained in:
Ed Page 2021-04-06 21:14:35 -05:00
parent c71c9f4f84
commit 2a7bd5b046
3 changed files with 25 additions and 4 deletions

View file

@ -31,4 +31,5 @@ Configuration is read from the following (in precedence order)
| default.locale | --locale | en, en-us, en-gb, en-ca, en-au | English dialect to correct to. |
| default.extend-identifiers | \- | table of strings | Corrections for identifiers. When the correction is blank, the word is never valid. When the correction is the key, the word is always valid. |
| default.extend-words | \- | table of strings | Corrections for identifiers. When the correction is blank, the word is never valid. When the correction is the key, the word is always valid. |
| type.<name>.binary | <varied> | <varied> | See `default.` for child keys. Run with `--type-list` to see available `<name>`s |
| type.<name>.<field> | <varied> | <varied> | See `default.` for child keys. Run with `--type-list` to see available `<name>`s |
| type.<name>.extend_globs | \- | list of strings | File globs for matching `<name>` |

View file

@ -7,7 +7,7 @@ pub struct Config {
pub files: Walk,
pub default: EngineConfig,
#[serde(rename = "type")]
pub type_: std::collections::HashMap<kstring::KString, EngineConfig>,
pub type_: std::collections::HashMap<kstring::KString, TypeEngineConfig>,
#[serde(skip)]
pub overrides: EngineConfig,
}
@ -49,7 +49,7 @@ impl Config {
for (type_name, engine) in source.type_.iter() {
self.type_
.entry(type_name.to_owned())
.or_insert_with(EngineConfig::default)
.or_insert_with(TypeEngineConfig::default)
.update(engine);
}
self.overrides.update(&source.overrides);
@ -137,6 +137,22 @@ impl Walk {
}
}
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
#[serde(deny_unknown_fields, default)]
#[serde(rename_all = "kebab-case")]
pub struct TypeEngineConfig {
pub extend_glob: Vec<kstring::KString>,
#[serde(flatten)]
pub engine: EngineConfig,
}
impl TypeEngineConfig {
pub fn update(&mut self, source: &TypeEngineConfig) {
self.extend_glob.extend(source.extend_glob.iter().cloned());
self.engine.update(&source.engine);
}
}
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
#[serde(deny_unknown_fields, default)]
#[serde(rename_all = "kebab-case")]

View file

@ -153,8 +153,12 @@ impl<'s> ConfigEngine<'s> {
type_matcher.add_defaults();
let mut types: std::collections::HashMap<_, _> = Default::default();
for (type_name, type_engine) in type_.into_iter() {
for glob in type_engine.extend_glob.iter() {
type_matcher.add(type_name.as_str(), glob.as_str())?;
}
let mut new_type_engine = default.clone();
new_type_engine.update(&type_engine);
new_type_engine.update(&type_engine.engine);
new_type_engine.update(&overrides);
let type_config = self.init_file_config(new_type_engine);
types.insert(type_name, type_config);