diff options
-rw-r--r-- | helix-term/src/application.rs | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 5f013b9a..83e853b1 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -397,38 +397,49 @@ impl Application { self.editor.refresh_config(); } + /// refresh language config after config change + fn refresh_language_config(&mut self) -> Result<(), Error> { + let syntax_config = helix_core::config::user_syntax_loader() + .map_err(|err| anyhow::anyhow!("Failed to load language config: {}", err))?; + + self.syn_loader = std::sync::Arc::new(syntax::Loader::new(syntax_config)); + for document in self.editor.documents.values_mut() { + document.detect_language(self.syn_loader.clone()); + } + + Ok(()) + } + /// Refresh theme after config change - fn refresh_theme(&mut self, config: &Config) { + fn refresh_theme(&mut self, config: &Config) -> Result<(), Error> { if let Some(theme) = config.theme.clone() { let true_color = self.true_color(); - match self.theme_loader.load(&theme) { - Ok(theme) => { - if true_color || theme.is_16_color() { - self.editor.set_theme(theme); - } else { - self.editor - .set_error("theme requires truecolor support, which is not available"); - } - } - Err(err) => { - let err_string = format!("failed to load theme `{}` - {}", theme, err); - self.editor.set_error(err_string); - } + let theme = self + .theme_loader + .load(&theme) + .map_err(|err| anyhow::anyhow!("Failed to load theme `{}`: {}", theme, err))?; + + if true_color || theme.is_16_color() { + self.editor.set_theme(theme); + } else { + anyhow::bail!("theme requires truecolor support, which is not available") } } + + Ok(()) } fn refresh_config(&mut self) { - match Config::load_default() { - Ok(config) => { - self.refresh_theme(&config); + let mut refresh_config = || -> Result<(), Error> { + let default_config = Config::load_default() + .map_err(|err| anyhow::anyhow!("Failed to load config: {}", err))?; + self.refresh_language_config()?; + self.refresh_theme(&default_config)?; + Ok(()) + }; - // Store new config - self.config.store(Arc::new(config)); - } - Err(err) => { - self.editor.set_error(err.to_string()); - } + if let Err(err) = refresh_config() { + self.editor.set_error(err.to_string()); } } |