|
|
@ -23,12 +23,19 @@ impl Default for ConfigLoadError {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Default, Clone, PartialEq, Deserialize)]
|
|
|
|
|
|
|
|
#[serde(rename_all = "kebab-case")]
|
|
|
|
|
|
|
|
pub enum LoadWorkspaceConfig {
|
|
|
|
|
|
|
|
#[default]
|
|
|
|
|
|
|
|
Never,
|
|
|
|
|
|
|
|
Always,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Deserializable raw config struct
|
|
|
|
// Deserializable raw config struct
|
|
|
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
|
|
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
|
|
|
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
|
|
|
|
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
|
|
|
|
pub struct ConfigRaw {
|
|
|
|
pub struct ConfigRaw {
|
|
|
|
pub workspace_config: Option<bool>,
|
|
|
|
pub load_workspace_config: Option<LoadWorkspaceConfig>,
|
|
|
|
pub theme: Option<String>,
|
|
|
|
pub theme: Option<String>,
|
|
|
|
pub keys: Option<HashMap<Mode, KeyTrie>>,
|
|
|
|
pub keys: Option<HashMap<Mode, KeyTrie>>,
|
|
|
|
pub editor: Option<toml::Value>,
|
|
|
|
pub editor: Option<toml::Value>,
|
|
|
@ -37,7 +44,7 @@ pub struct ConfigRaw {
|
|
|
|
impl Default for ConfigRaw {
|
|
|
|
impl Default for ConfigRaw {
|
|
|
|
fn default() -> ConfigRaw {
|
|
|
|
fn default() -> ConfigRaw {
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
|
workspace_config: Some(false),
|
|
|
|
load_workspace_config: Some(LoadWorkspaceConfig::default()),
|
|
|
|
theme: None,
|
|
|
|
theme: None,
|
|
|
|
keys: Some(keymap::default()),
|
|
|
|
keys: Some(keymap::default()),
|
|
|
|
editor: None,
|
|
|
|
editor: None,
|
|
|
@ -53,9 +60,9 @@ impl ConfigRaw {
|
|
|
|
|
|
|
|
|
|
|
|
fn merge(self, other: ConfigRaw, trust: bool) -> Self {
|
|
|
|
fn merge(self, other: ConfigRaw, trust: bool) -> Self {
|
|
|
|
ConfigRaw {
|
|
|
|
ConfigRaw {
|
|
|
|
workspace_config: match trust {
|
|
|
|
load_workspace_config: match trust {
|
|
|
|
true => other.workspace_config.or(self.workspace_config),
|
|
|
|
true => other.load_workspace_config.or(self.load_workspace_config),
|
|
|
|
false => self.workspace_config,
|
|
|
|
false => self.load_workspace_config,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
theme: other.theme.or(self.theme),
|
|
|
|
theme: other.theme.or(self.theme),
|
|
|
|
keys: match (self.keys, other.keys) {
|
|
|
|
keys: match (self.keys, other.keys) {
|
|
|
@ -73,7 +80,7 @@ impl ConfigRaw {
|
|
|
|
// Final config struct
|
|
|
|
// Final config struct
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
|
pub struct Config {
|
|
|
|
pub struct Config {
|
|
|
|
pub workspace_config: bool,
|
|
|
|
pub load_workspace_config: LoadWorkspaceConfig,
|
|
|
|
pub theme: Option<String>,
|
|
|
|
pub theme: Option<String>,
|
|
|
|
pub keys: HashMap<Mode, KeyTrie>,
|
|
|
|
pub keys: HashMap<Mode, KeyTrie>,
|
|
|
|
pub editor: helix_view::editor::Config,
|
|
|
|
pub editor: helix_view::editor::Config,
|
|
|
@ -83,7 +90,7 @@ impl Default for Config {
|
|
|
|
fn default() -> Config {
|
|
|
|
fn default() -> Config {
|
|
|
|
let raw = ConfigRaw::default();
|
|
|
|
let raw = ConfigRaw::default();
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
|
workspace_config: raw.workspace_config.unwrap_or_default(),
|
|
|
|
load_workspace_config: raw.load_workspace_config.unwrap_or_default(),
|
|
|
|
theme: raw.theme,
|
|
|
|
theme: raw.theme,
|
|
|
|
keys: raw.keys.unwrap_or_else(|| keymap::default()),
|
|
|
|
keys: raw.keys.unwrap_or_else(|| keymap::default()),
|
|
|
|
editor: helix_view::editor::Config::default(),
|
|
|
|
editor: helix_view::editor::Config::default(),
|
|
|
@ -105,7 +112,7 @@ impl TryFrom<ConfigRaw> for Config {
|
|
|
|
|
|
|
|
|
|
|
|
fn try_from(config: ConfigRaw) -> Result<Self, Self::Error> {
|
|
|
|
fn try_from(config: ConfigRaw) -> Result<Self, Self::Error> {
|
|
|
|
Ok(Self {
|
|
|
|
Ok(Self {
|
|
|
|
workspace_config: config.workspace_config.unwrap_or_default(),
|
|
|
|
load_workspace_config: config.load_workspace_config.unwrap_or_default(),
|
|
|
|
theme: config.theme,
|
|
|
|
theme: config.theme,
|
|
|
|
keys: config.keys.unwrap_or_else(|| keymap::default()),
|
|
|
|
keys: config.keys.unwrap_or_else(|| keymap::default()),
|
|
|
|
editor: config.editor
|
|
|
|
editor: config.editor
|
|
|
@ -121,13 +128,15 @@ impl Config {
|
|
|
|
let default = ConfigRaw::default();
|
|
|
|
let default = ConfigRaw::default();
|
|
|
|
let global = default.merge(ConfigRaw::load(helix_loader::config_file())?, true);
|
|
|
|
let global = default.merge(ConfigRaw::load(helix_loader::config_file())?, true);
|
|
|
|
|
|
|
|
|
|
|
|
match global.workspace_config.unwrap_or_default() {
|
|
|
|
match global.load_workspace_config {
|
|
|
|
false => global,
|
|
|
|
Some(LoadWorkspaceConfig::Always) => {
|
|
|
|
true => match ConfigRaw::load(helix_loader::workspace_config_file()) {
|
|
|
|
match ConfigRaw::load(helix_loader::workspace_config_file()) {
|
|
|
|
Ok(workspace) => Ok(global.merge(workspace, false)),
|
|
|
|
Ok(workspace) => Ok(global.merge(workspace, false)),
|
|
|
|
Err(ConfigLoadError::Error(_)) => Ok(global),
|
|
|
|
Err(ConfigLoadError::Error(_)) => Ok(global),
|
|
|
|
error => error,
|
|
|
|
error => error,
|
|
|
|
}?,
|
|
|
|
}?
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
_ => global,
|
|
|
|
}.try_into()
|
|
|
|
}.try_into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|