mirror of https://github.com/helix-editor/helix
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.pull/12982/merge
parent
b75e95862c
commit
633c5fbf0f
|
@ -384,14 +384,22 @@ impl Application {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// refresh language config after config change
|
fn refresh_config(&mut self) {
|
||||||
fn refresh_language_config(&mut self) -> Result<(), Error> {
|
let mut refresh_config = || -> Result<(), Error> {
|
||||||
let lang_loader = helix_core::config::user_lang_loader()?;
|
let default_config = Config::load_default()
|
||||||
|
.map_err(|err| anyhow::anyhow!("Failed to load config: {}", err))?;
|
||||||
|
|
||||||
|
// 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.editor.syn_loader.store(Arc::new(lang_loader));
|
||||||
let loader = self.editor.syn_loader.load();
|
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() {
|
for document in self.editor.documents.values_mut() {
|
||||||
document.detect_language(&loader);
|
document.detect_language(&lang_loader);
|
||||||
let diagnostics = Editor::doc_diagnostics(
|
let diagnostics = Editor::doc_diagnostics(
|
||||||
&self.editor.language_servers,
|
&self.editor.language_servers,
|
||||||
&self.editor.diagnostics,
|
&self.editor.diagnostics,
|
||||||
|
@ -400,16 +408,6 @@ impl Application {
|
||||||
document.replace_diagnostics(diagnostics, &[], None);
|
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
|
|
||||||
Self::load_configured_theme(&mut self.editor, &default_config);
|
|
||||||
self.terminal
|
self.terminal
|
||||||
.reconfigure(default_config.editor.clone().into())?;
|
.reconfigure(default_config.editor.clone().into())?;
|
||||||
// Store new config
|
// Store new config
|
||||||
|
|
Loading…
Reference in New Issue