2021-06-19 18:59:19 +04:00
|
|
|
use anyhow::{Error, Result};
|
2021-06-22 21:04:04 +04:00
|
|
|
use serde::Deserialize;
|
2021-06-20 23:31:45 +04:00
|
|
|
use std::collections::HashMap;
|
2021-06-17 15:08:05 +04:00
|
|
|
|
2021-06-22 21:04:04 +04:00
|
|
|
use crate::commands::Command;
|
|
|
|
use crate::keymap::Keymaps;
|
2021-06-19 18:59:19 +04:00
|
|
|
|
2021-06-22 21:04:04 +04:00
|
|
|
#[derive(Debug, Default, Clone, PartialEq, Deserialize)]
|
2021-06-17 15:08:05 +04:00
|
|
|
pub struct Config {
|
2021-06-20 23:31:45 +04:00
|
|
|
pub theme: Option<String>,
|
2021-06-22 21:04:04 +04:00
|
|
|
#[serde(default)]
|
2021-06-20 23:31:45 +04:00
|
|
|
pub lsp: LspConfig,
|
2021-06-22 21:04:04 +04:00
|
|
|
#[serde(default)]
|
|
|
|
pub keys: Keymaps,
|
2021-06-17 15:08:05 +04:00
|
|
|
}
|
|
|
|
|
2021-06-22 21:04:04 +04:00
|
|
|
#[derive(Debug, Default, Clone, PartialEq, Deserialize)]
|
2021-06-24 00:33:28 +04:00
|
|
|
#[serde(rename_all = "kebab-case")]
|
2021-06-20 23:31:45 +04:00
|
|
|
pub struct LspConfig {
|
|
|
|
pub display_messages: bool,
|
|
|
|
}
|
|
|
|
|
2021-06-22 21:04:04 +04:00
|
|
|
#[test]
|
|
|
|
fn parsing_keymaps_config_file() {
|
|
|
|
use helix_core::hashmap;
|
2021-06-25 07:58:15 +04:00
|
|
|
use helix_view::{
|
|
|
|
document::Mode,
|
|
|
|
input::KeyEvent,
|
|
|
|
keyboard::{KeyCode, KeyModifiers},
|
|
|
|
};
|
2021-06-22 21:04:04 +04:00
|
|
|
|
|
|
|
let sample_keymaps = r#"
|
|
|
|
[keys.insert]
|
|
|
|
y = "move_line_down"
|
|
|
|
S-C-a = "delete_selection"
|
|
|
|
|
|
|
|
[keys.normal]
|
|
|
|
A-F12 = "move_next_word_end"
|
|
|
|
"#;
|
2021-06-17 20:52:41 +04:00
|
|
|
|
2021-06-22 21:04:04 +04:00
|
|
|
assert_eq!(
|
|
|
|
toml::from_str::<Config>(sample_keymaps).unwrap(),
|
|
|
|
Config {
|
|
|
|
keys: Keymaps(hashmap! {
|
|
|
|
Mode::Insert => hashmap! {
|
|
|
|
KeyEvent {
|
|
|
|
code: KeyCode::Char('y'),
|
|
|
|
modifiers: KeyModifiers::NONE,
|
|
|
|
} => Command::move_line_down,
|
|
|
|
KeyEvent {
|
|
|
|
code: KeyCode::Char('a'),
|
|
|
|
modifiers: KeyModifiers::SHIFT | KeyModifiers::CONTROL,
|
|
|
|
} => Command::delete_selection,
|
|
|
|
},
|
|
|
|
Mode::Normal => hashmap! {
|
|
|
|
KeyEvent {
|
|
|
|
code: KeyCode::F(12),
|
|
|
|
modifiers: KeyModifiers::ALT,
|
|
|
|
} => Command::move_next_word_end,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
);
|
2021-06-17 15:08:05 +04:00
|
|
|
}
|