mirror of https://github.com/helix-editor/helix
application: Eliminate duplicate theme and syntax loader clones
The application held onto these since their introduction in ce97a2f0
but
the Arcs are duplicated between Application and Editor - we can store it
only on Editor without issue.
pull/12910/head
parent
48194825b9
commit
e35d420199
|
@ -65,11 +65,6 @@ pub struct Application {
|
||||||
|
|
||||||
config: Arc<ArcSwap<Config>>,
|
config: Arc<ArcSwap<Config>>,
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
theme_loader: Arc<theme::Loader>,
|
|
||||||
#[allow(dead_code)]
|
|
||||||
syn_loader: Arc<ArcSwap<syntax::Loader>>,
|
|
||||||
|
|
||||||
signals: Signals,
|
signals: Signals,
|
||||||
jobs: Jobs,
|
jobs: Jobs,
|
||||||
lsp_progress: LspProgressMap,
|
lsp_progress: LspProgressMap,
|
||||||
|
@ -106,7 +101,7 @@ impl Application {
|
||||||
|
|
||||||
let mut theme_parent_dirs = vec![helix_loader::config_dir()];
|
let mut theme_parent_dirs = vec![helix_loader::config_dir()];
|
||||||
theme_parent_dirs.extend(helix_loader::runtime_dirs().iter().cloned());
|
theme_parent_dirs.extend(helix_loader::runtime_dirs().iter().cloned());
|
||||||
let theme_loader = std::sync::Arc::new(theme::Loader::new(&theme_parent_dirs));
|
let theme_loader = theme::Loader::new(&theme_parent_dirs);
|
||||||
|
|
||||||
let true_color = config.editor.true_color || crate::true_color();
|
let true_color = config.editor.true_color || crate::true_color();
|
||||||
let theme = config
|
let theme = config
|
||||||
|
@ -124,8 +119,6 @@ impl Application {
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| theme_loader.default_theme(true_color));
|
.unwrap_or_else(|| theme_loader.default_theme(true_color));
|
||||||
|
|
||||||
let syn_loader = Arc::new(ArcSwap::from_pointee(lang_loader));
|
|
||||||
|
|
||||||
#[cfg(not(feature = "integration"))]
|
#[cfg(not(feature = "integration"))]
|
||||||
let backend = CrosstermBackend::new(stdout(), &config.editor);
|
let backend = CrosstermBackend::new(stdout(), &config.editor);
|
||||||
|
|
||||||
|
@ -139,8 +132,8 @@ impl Application {
|
||||||
let handlers = handlers::setup(config.clone());
|
let handlers = handlers::setup(config.clone());
|
||||||
let mut editor = Editor::new(
|
let mut editor = Editor::new(
|
||||||
area,
|
area,
|
||||||
theme_loader.clone(),
|
Arc::new(theme_loader),
|
||||||
syn_loader.clone(),
|
Arc::new(ArcSwap::from_pointee(lang_loader)),
|
||||||
Arc::new(Map::new(Arc::clone(&config), |config: &Config| {
|
Arc::new(Map::new(Arc::clone(&config), |config: &Config| {
|
||||||
&config.editor
|
&config.editor
|
||||||
})),
|
})),
|
||||||
|
@ -262,12 +255,7 @@ impl Application {
|
||||||
compositor,
|
compositor,
|
||||||
terminal,
|
terminal,
|
||||||
editor,
|
editor,
|
||||||
|
|
||||||
config,
|
config,
|
||||||
|
|
||||||
theme_loader,
|
|
||||||
syn_loader,
|
|
||||||
|
|
||||||
signals,
|
signals,
|
||||||
jobs: Jobs::new(),
|
jobs: Jobs::new(),
|
||||||
lsp_progress: LspProgressMap::new(),
|
lsp_progress: LspProgressMap::new(),
|
||||||
|
@ -417,10 +405,9 @@ impl Application {
|
||||||
fn refresh_language_config(&mut self) -> Result<(), Error> {
|
fn refresh_language_config(&mut self) -> Result<(), Error> {
|
||||||
let lang_loader = helix_core::config::user_lang_loader()?;
|
let lang_loader = helix_core::config::user_lang_loader()?;
|
||||||
|
|
||||||
self.syn_loader.store(Arc::new(lang_loader));
|
self.editor.syn_loader.store(Arc::new(lang_loader));
|
||||||
self.editor.syn_loader = self.syn_loader.clone();
|
|
||||||
for document in self.editor.documents.values_mut() {
|
for document in self.editor.documents.values_mut() {
|
||||||
document.detect_language(self.syn_loader.clone());
|
document.detect_language(self.editor.syn_loader.clone());
|
||||||
let diagnostics = Editor::doc_diagnostics(
|
let diagnostics = Editor::doc_diagnostics(
|
||||||
&self.editor.language_servers,
|
&self.editor.language_servers,
|
||||||
&self.editor.diagnostics,
|
&self.editor.diagnostics,
|
||||||
|
@ -439,7 +426,8 @@ impl Application {
|
||||||
.theme
|
.theme
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|theme| {
|
.and_then(|theme| {
|
||||||
self.theme_loader
|
self.editor
|
||||||
|
.theme_loader
|
||||||
.load(theme)
|
.load(theme)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
log::warn!("failed to load theme `{}` - {}", theme, e);
|
log::warn!("failed to load theme `{}` - {}", theme, e);
|
||||||
|
@ -448,7 +436,7 @@ impl Application {
|
||||||
.ok()
|
.ok()
|
||||||
.filter(|theme| (true_color || theme.is_16_color()))
|
.filter(|theme| (true_color || theme.is_16_color()))
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| self.theme_loader.default_theme(true_color));
|
.unwrap_or_else(|| self.editor.theme_loader.default_theme(true_color));
|
||||||
|
|
||||||
self.editor.set_theme(theme);
|
self.editor.set_theme(theme);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue