impl display for ConfigLoadError

pull/1803/head
Joseph Harrison-Lim 3 years ago
parent 6e4da9405d
commit d7e552b510
No known key found for this signature in database
GPG Key ID: 5DAB214D5E62987D

@ -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();

@ -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 {

@ -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};

Loading…
Cancel
Save