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,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
|
||||
|
|
Loading…
Reference in New Issue