From 633c5fbf0fb95f68fa7f311d1920fc5babcc3785 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sun, 8 Jun 2025 14:46:17 -0400 Subject: [PATCH] Update language loader before refreshing theme in `:config-reload` Since locals are handled during parsing instead of highlighting with tree-house, we need to call `helix_core::syntax::Loader::set_scopes` before parsing any documents. During `:config-reload` we previously reloaded the `Loader` and re-parsed documents and _then_ updated the theme. So documents were parsed before `Loader::set_scopes` was called on the new loader. With this change the `refresh_language_config` helper is inlined into `refresh_config`. Updating the `Editor`'s `ArcSwap` of the loader is done before updating the theme so that the `load_configured_theme` helper can call `set_scopes` with on the new loader. --- helix-term/src/application.rs | 40 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 6f3485a87..eadda721d 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -384,32 +384,30 @@ impl Application { } } - /// refresh language config after config change - fn refresh_language_config(&mut self) -> Result<(), Error> { - let lang_loader = helix_core::config::user_lang_loader()?; - - self.editor.syn_loader.store(Arc::new(lang_loader)); - let loader = self.editor.syn_loader.load(); - for document in self.editor.documents.values_mut() { - document.detect_language(&loader); - let diagnostics = Editor::doc_diagnostics( - &self.editor.language_servers, - &self.editor.diagnostics, - document, - ); - document.replace_diagnostics(diagnostics, &[], None); - } - - Ok(()) - } - fn refresh_config(&mut self) { 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()?; - // Refresh theme after config change + + // Update the syntax language loader before setting the theme. Setting the theme will + // call `Loader::set_scopes` which must be done before the documents are re-parsed for + // the sake of locals highlighting. + let lang_loader = helix_core::config::user_lang_loader()?; + self.editor.syn_loader.store(Arc::new(lang_loader)); Self::load_configured_theme(&mut self.editor, &default_config); + + // Re-parse any open documents with the new language config. + let lang_loader = self.editor.syn_loader.load(); + for document in self.editor.documents.values_mut() { + document.detect_language(&lang_loader); + let diagnostics = Editor::doc_diagnostics( + &self.editor.language_servers, + &self.editor.diagnostics, + document, + ); + document.replace_diagnostics(diagnostics, &[], None); + } + self.terminal .reconfigure(default_config.editor.clone().into())?; // Store new config