on master help sign in
Launch with defaults upon invalid config/theme (#982)
ed23057Omnikar
helix-term/src/config.rs+2−1
@@ -3,6 +3,7 @@ use serde::Deserialize;
3use crate::keymap::Keymaps;
3use crate::keymap::Keymaps;
4
4
5#[derive(Debug, Default, Clone, PartialEq, Deserialize)]
5#[derive(Debug, Default, Clone, PartialEq, Deserialize)]
6+#[serde(deny_unknown_fields)]
6pub struct Config {
7pub struct Config {
7 pub theme: Option<String>,
8 pub theme: Option<String>,
8 #[serde(default)]
9 #[serde(default)]
@@ -14,7 +15,7 @@ pub struct Config {
14}
15}
15
16
16#[derive(Debug, Default, Clone, PartialEq, Deserialize)]
17#[derive(Debug, Default, Clone, PartialEq, Deserialize)]
17−#[serde(rename_all = "kebab-case")]
18+#[serde(rename_all = "kebab-case", deny_unknown_fields)]
18pub struct LspConfig {
19pub struct LspConfig {
19 pub display_messages: bool,
20 pub display_messages: bool,
20}
21}
helix-term/src/main.rs+10−1
@@ -91,7 +91,16 @@ FLAGS:
91 }
91 }
92
92
93 let config = match std::fs::read_to_string(conf_dir.join("config.toml")) {
93 let config = match std::fs::read_to_string(conf_dir.join("config.toml")) {
94− Ok(config) => merge_keys(toml::from_str(&config)?),
94+ Ok(config) => toml::from_str(&config)
95+ .map(merge_keys)
96+ .unwrap_or_else(|err| {
97+ eprintln!("Bad config: {}", err);
98+ eprintln!("Press <ENTER> to continue with default config");
99+ use std::io::Read;
100+ // This waits for an enter press.
101+ let _ = std::io::stdin().read(&mut []);
102+ Config::default()
103+ }),
95 Err(err) if err.kind() == std::io::ErrorKind::NotFound => Config::default(),
104 Err(err) if err.kind() == std::io::ErrorKind::NotFound => Config::default(),
96 Err(err) => return Err(Error::new(err)),
105 Err(err) => return Err(Error::new(err)),
97 };
106 };
helix-view/src/editor.rs+7−1
@@ -34,7 +34,7 @@ where
34}
34}
35
35
36#[derive(Debug, Clone, PartialEq, Deserialize)]
36#[derive(Debug, Clone, PartialEq, Deserialize)]
37−#[serde(rename_all = "kebab-case", default)]
37+#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
38pub struct Config {
38pub struct Config {
39 /// Padding to keep between the edge of the screen and the cursor when scrolling. Defaults to 5.
39 /// Padding to keep between the edge of the screen and the cursor when scrolling. Defaults to 5.
40 pub scrolloff: usize,
40 pub scrolloff: usize,
@@ -195,6 +195,12 @@ impl Editor {
195 }
195 }
196
196
197 pub fn set_theme(&mut self, theme: Theme) {
197 pub fn set_theme(&mut self, theme: Theme) {
198+ // `ui.selection` is the only scope required to be able to render a theme.
199+ if theme.find_scope_index("ui.selection").is_none() {
200+ self.set_error("Invalid theme: `ui.selection` required".to_owned());
201+ return;
202+ }
203+
198 let scopes = theme.scopes();
204 let scopes = theme.scopes();
199 for config in self
205 for config in self
200 .syn_loader
206 .syn_loader