mirror of
https://github.com/helix-editor/helix.git
synced 2025-01-19 13:37:06 +04:00
Reload language config with :config-reload
(#5239)
This commit is contained in:
parent
3fe3f2c4ee
commit
9d15b85209
@ -397,38 +397,49 @@ pub fn handle_config_events(&mut self, config_event: ConfigEvent) {
|
||||
self.editor.refresh_config();
|
||||
}
|
||||
|
||||
/// refresh language config after config change
|
||||
fn refresh_language_config(&mut self) -> Result<(), Error> {
|
||||
let syntax_config = helix_core::config::user_syntax_loader()
|
||||
.map_err(|err| anyhow::anyhow!("Failed to load language config: {}", err))?;
|
||||
|
||||
self.syn_loader = std::sync::Arc::new(syntax::Loader::new(syntax_config));
|
||||
for document in self.editor.documents.values_mut() {
|
||||
document.detect_language(self.syn_loader.clone());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Refresh theme after config change
|
||||
fn refresh_theme(&mut self, config: &Config) {
|
||||
fn refresh_theme(&mut self, config: &Config) -> Result<(), Error> {
|
||||
if let Some(theme) = config.theme.clone() {
|
||||
let true_color = self.true_color();
|
||||
match self.theme_loader.load(&theme) {
|
||||
Ok(theme) => {
|
||||
if true_color || theme.is_16_color() {
|
||||
self.editor.set_theme(theme);
|
||||
} else {
|
||||
self.editor
|
||||
.set_error("theme requires truecolor support, which is not available");
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
let err_string = format!("failed to load theme `{}` - {}", theme, err);
|
||||
self.editor.set_error(err_string);
|
||||
}
|
||||
let theme = self
|
||||
.theme_loader
|
||||
.load(&theme)
|
||||
.map_err(|err| anyhow::anyhow!("Failed to load theme `{}`: {}", theme, err))?;
|
||||
|
||||
if true_color || theme.is_16_color() {
|
||||
self.editor.set_theme(theme);
|
||||
} else {
|
||||
anyhow::bail!("theme requires truecolor support, which is not available")
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn refresh_config(&mut self) {
|
||||
match Config::load_default() {
|
||||
Ok(config) => {
|
||||
self.refresh_theme(&config);
|
||||
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()?;
|
||||
self.refresh_theme(&default_config)?;
|
||||
Ok(())
|
||||
};
|
||||
|
||||
// Store new config
|
||||
self.config.store(Arc::new(config));
|
||||
}
|
||||
Err(err) => {
|
||||
self.editor.set_error(err.to_string());
|
||||
}
|
||||
if let Err(err) = refresh_config() {
|
||||
self.editor.set_error(err.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user