diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index b4153b062..f759d591e 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -22,6 +22,7 @@ use crate::{ use log::{error, warn}; use std::{ + fmt::Debug, io::{stdin, stdout, Write}, sync::Arc, time::{Duration, Instant}, @@ -269,7 +270,12 @@ impl Application { } fn refresh_config(&mut self) { - let config = Config::load(helix_loader::config_file()).unwrap_or_default(); + let config = Config::load(helix_loader::config_file()) + .map_err(|err| { + self.editor.set_error(err.to_string()); + Config::default() + }) + .unwrap(); // Just an example to start; Some config properties like "theme" are a bit more involved and require a reload if let Some(theme) = config.theme.clone() { let true_color = self.true_color(); diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs index f665e72cb..94d5fc80d 100644 --- a/helix-term/src/config.rs +++ b/helix-term/src/config.rs @@ -1,5 +1,6 @@ use crate::keymap::{merge_keys, Keymaps}; use serde::Deserialize; +use std::fmt::Display; use std::io::Error as IOError; use std::path::PathBuf; use toml::de::Error as TomlError; @@ -22,6 +23,15 @@ pub enum ConfigLoadError { Error(IOError), } +impl Display for ConfigLoadError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + ConfigLoadError::BadConfig(err) => err.fmt(f), + ConfigLoadError::Error(err) => err.fmt(f), + } + } +} + #[derive(Debug, Default, Clone, PartialEq, Deserialize)] #[serde(rename_all = "kebab-case", deny_unknown_fields)] pub struct LspConfig { diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index 75a02f852..90ac6219e 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -1,4 +1,4 @@ -use anyhow::{Context, Result, Error}; +use anyhow::{Context, Error, Result}; use helix_term::application::Application; use helix_term::args::Args; use helix_term::config::{Config, ConfigLoadError};