Reload language config with :config-reload
(#5239)
This commit is contained in:
parent
3fe3f2c4ee
commit
9d15b85209
1 changed files with 34 additions and 23 deletions
|
@ -397,38 +397,49 @@ impl Application {
|
||||||
self.editor.refresh_config();
|
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
|
/// 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() {
|
if let Some(theme) = config.theme.clone() {
|
||||||
let true_color = self.true_color();
|
let true_color = self.true_color();
|
||||||
match self.theme_loader.load(&theme) {
|
let theme = self
|
||||||
Ok(theme) => {
|
.theme_loader
|
||||||
if true_color || theme.is_16_color() {
|
.load(&theme)
|
||||||
self.editor.set_theme(theme);
|
.map_err(|err| anyhow::anyhow!("Failed to load theme `{}`: {}", theme, err))?;
|
||||||
} else {
|
|
||||||
self.editor
|
if true_color || theme.is_16_color() {
|
||||||
.set_error("theme requires truecolor support, which is not available");
|
self.editor.set_theme(theme);
|
||||||
}
|
} else {
|
||||||
}
|
anyhow::bail!("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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn refresh_config(&mut self) {
|
fn refresh_config(&mut self) {
|
||||||
match Config::load_default() {
|
let mut refresh_config = || -> Result<(), Error> {
|
||||||
Ok(config) => {
|
let default_config = Config::load_default()
|
||||||
self.refresh_theme(&config);
|
.map_err(|err| anyhow::anyhow!("Failed to load config: {}", err))?;
|
||||||
|
self.refresh_language_config()?;
|
||||||
|
self.refresh_theme(&default_config)?;
|
||||||
|
Ok(())
|
||||||
|
};
|
||||||
|
|
||||||
// Store new config
|
if let Err(err) = refresh_config() {
|
||||||
self.config.store(Arc::new(config));
|
self.editor.set_error(err.to_string());
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
self.editor.set_error(err.to_string());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue