mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-26 11:23:31 +04:00
ed23057ff8
* Launch with defaults upon invalid config/theme * Startup message if there is a problematic config * Statusline error if trying to switch to an invalid theme * Use serde `deny_unknown_fields` for config
55 lines
1.4 KiB
Rust
55 lines
1.4 KiB
Rust
use serde::Deserialize;
|
|
|
|
use crate::keymap::Keymaps;
|
|
|
|
#[derive(Debug, Default, Clone, PartialEq, Deserialize)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct Config {
|
|
pub theme: Option<String>,
|
|
#[serde(default)]
|
|
pub lsp: LspConfig,
|
|
#[serde(default)]
|
|
pub keys: Keymaps,
|
|
#[serde(default)]
|
|
pub editor: helix_view::editor::Config,
|
|
}
|
|
|
|
#[derive(Debug, Default, Clone, PartialEq, Deserialize)]
|
|
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
|
|
pub struct LspConfig {
|
|
pub display_messages: bool,
|
|
}
|
|
|
|
#[test]
|
|
fn parsing_keymaps_config_file() {
|
|
use crate::keymap;
|
|
use crate::keymap::Keymap;
|
|
use helix_core::hashmap;
|
|
use helix_view::document::Mode;
|
|
|
|
let sample_keymaps = r#"
|
|
[keys.insert]
|
|
y = "move_line_down"
|
|
S-C-a = "delete_selection"
|
|
|
|
[keys.normal]
|
|
A-F12 = "move_next_word_end"
|
|
"#;
|
|
|
|
assert_eq!(
|
|
toml::from_str::<Config>(sample_keymaps).unwrap(),
|
|
Config {
|
|
keys: Keymaps(hashmap! {
|
|
Mode::Insert => Keymap::new(keymap!({ "Insert mode"
|
|
"y" => move_line_down,
|
|
"S-C-a" => delete_selection,
|
|
})),
|
|
Mode::Normal => Keymap::new(keymap!({ "Normal mode"
|
|
"A-F12" => move_next_word_end,
|
|
})),
|
|
}),
|
|
..Default::default()
|
|
}
|
|
);
|
|
}
|