@@ -397,38 +397,49 @@ impl Application {
397397 self.editor.refresh_config();
398398 }
399399
400+ /// refresh language config after config change
401+ fn refresh_language_config(&mut self) -> Result<(), Error> {
402+ let syntax_config = helix_core::config::user_syntax_loader()
403+ .map_err(|err| anyhow::anyhow!("Failed to load language config: {}", err))?;
404+
405+ self.syn_loader = std::sync::Arc::new(syntax::Loader::new(syntax_config));
406+ for document in self.editor.documents.values_mut() {
407+ document.detect_language(self.syn_loader.clone());
408+ }
409+
410+ Ok(())
411+ }
412+
400413 /// Refresh theme after config change
401− fn refresh_theme(&mut self, config: &Config) {
414+ fn refresh_theme(&mut self, config: &Config) -> Result<(), Error> {
402415 if let Some(theme) = config.theme.clone() {
403416 let true_color = self.true_color();
404− match self.theme_loader.load(&theme) {
405− Ok(theme) => {
406− if true_color || theme.is_16_color() {
407− self.editor.set_theme(theme);
408− } else {
409− self.editor
410− .set_error("theme requires truecolor support, which is not available");
411− }
412− }
413− Err(err) => {
414− let err_string = format!("failed to load theme `{}` - {}", theme, err);
415− self.editor.set_error(err_string);
416− }
417+ let theme = self
418+ .theme_loader
419+ .load(&theme)
420+ .map_err(|err| anyhow::anyhow!("Failed to load theme `{}`: {}", theme, err))?;
421+
422+ if true_color || theme.is_16_color() {
423+ self.editor.set_theme(theme);
424+ } else {
425+ anyhow::bail!("theme requires truecolor support, which is not available")
417426 }
418427 }
428+
429+ Ok(())
419430 }
420431
421432 fn refresh_config(&mut self) {
422− match Config::load_default() {
423− Ok(config) => {
424− self.refresh_theme(&config);
433+ let mut refresh_config = || -> Result<(), Error> {
434+ let default_config = Config::load_default()
435+ .map_err(|err| anyhow::anyhow!("Failed to load config: {}", err))?;
436+ self.refresh_language_config()?;
437+ self.refresh_theme(&default_config)?;
438+ Ok(())
439+ };
425440
426− // Store new config
427− self.config.store(Arc::new(config));
428− }
429− Err(err) => {
430− self.editor.set_error(err.to_string());
431− }
441+ if let Err(err) = refresh_config() {
442+ self.editor.set_error(err.to_string());
432443 }
433444 }
434445