From 53d881f17229e1fcda4f1e139258059b85e6beeb Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Mon, 3 Jan 2022 12:52:01 +0900 Subject: Store theme scopes on the loader, this way theme isn't passed around --- helix-core/src/syntax.rs | 53 +++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 30 deletions(-) (limited to 'helix-core') diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 858b9bdf..8a973569 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -8,7 +8,7 @@ use crate::{ pub use helix_syntax::get_language; -use arc_swap::ArcSwap; +use arc_swap::{ArcSwap, Guard}; use slotmap::{DefaultKey as LayerId, HopSlotMap}; use std::{ @@ -264,12 +264,16 @@ impl LanguageConfiguration { } } +// Expose loader as Lazy<> global since it's always static? + #[derive(Debug)] pub struct Loader { // highlight_names ? language_configs: Vec>, language_config_ids_by_file_type: HashMap, // Vec language_config_ids_by_shebang: HashMap, + + scopes: ArcSwap>, } impl Loader { @@ -278,6 +282,7 @@ impl Loader { language_configs: Vec::new(), language_config_ids_by_file_type: HashMap::new(), language_config_ids_by_shebang: HashMap::new(), + scopes: ArcSwap::from_pointee(Vec::new()), }; for config in config.language { @@ -363,8 +368,22 @@ impl Loader { } None } - pub fn language_configs_iter(&self) -> impl Iterator> { - self.language_configs.iter() + + pub fn set_scopes(&self, scopes: Vec) { + self.scopes.store(Arc::new(scopes)); + + // Reconfigure existing grammars + for config in self + .language_configs + .iter() + .filter(|cfg| cfg.is_highlight_initialized()) + { + config.reconfigure(&self.scopes()); + } + } + + pub fn scopes(&self) -> Guard>> { + self.scopes.load() } } @@ -447,33 +466,7 @@ impl Syntax { self.loader .language_configuration_for_injection_string(language) .and_then(|language_config| { - // TODO: get these theme.scopes from somewhere, probably make them settable on Loader - let scopes = &[ - "attribute", - "constant", - "function.builtin", - "function", - "keyword", - "operator", - "property", - "punctuation", - "punctuation.bracket", - "punctuation.delimiter", - "string", - "string.special", - "tag", - "type", - "type.builtin", - "variable", - "variable.builtin", - "variable.parameter", - ]; - language_config.highlight_config( - &scopes - .iter() - .map(|scope| scope.to_string()) - .collect::>(), - ) + language_config.highlight_config(&self.loader.scopes.load()) }) }; -- cgit v1.2.3-70-g09d2