on master help sign in
Reload language config with `:config-reload` (#5239)
9d15b85willful759
helix-term/src/application.rs+34−23
@@ -397,38 +397,49 @@ impl Application {
397 self.editor.refresh_config();
397 self.editor.refresh_config();
398 }
398 }
399
399
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+
400 /// Refresh theme after config change
413 /// Refresh theme after config change
401− fn refresh_theme(&mut self, config: &Config) {
414+ fn refresh_theme(&mut self, config: &Config) -> Result<(), Error> {
402 if let Some(theme) = config.theme.clone() {
415 if let Some(theme) = config.theme.clone() {
403 let true_color = self.true_color();
416 let true_color = self.true_color();
417+ let theme = self
404− match self.theme_loader.load(&theme) {
418+ .theme_loader
405− Ok(theme) => {
419+ .load(&theme)
420+ .map_err(|err| anyhow::anyhow!("Failed to load theme `{}`: {}", theme, err))?;
421+
406− if true_color || theme.is_16_color() {
422+ if true_color || theme.is_16_color() {
407− self.editor.set_theme(theme);
423+ self.editor.set_theme(theme);
408− } else {
424+ } else {
409− self.editor
410− .set_error("theme requires truecolor support, which is not available");
425+ anyhow::bail!("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 }
426 }
418 }
427 }
428+
429+ Ok(())
419 }
430 }
420
431
421 fn refresh_config(&mut self) {
432 fn refresh_config(&mut self) {
433+ let mut refresh_config = || -> Result<(), Error> {
422− match Config::load_default() {
434+ let default_config = Config::load_default()
423− Ok(config) => {
435+ .map_err(|err| anyhow::anyhow!("Failed to load config: {}", err))?;
436+ self.refresh_language_config()?;
424− self.refresh_theme(&config);
437+ self.refresh_theme(&default_config)?;
438+ Ok(())
439+ };
425
440
426− // Store new config
441+ if let Err(err) = refresh_config() {
427− self.config.store(Arc::new(config));
428− }
429− Err(err) => {
430− self.editor.set_error(err.to_string());
442+ self.editor.set_error(err.to_string());
431− }
432 }
443 }
433 }
444 }
434
445