diff options
Diffstat (limited to 'helix-view/src')
-rw-r--r-- | helix-view/src/document.rs | 20 | ||||
-rw-r--r-- | helix-view/src/editor.rs | 11 |
2 files changed, 19 insertions, 12 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 33137c6c..4e7b1de9 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -681,7 +681,7 @@ impl Document { pub fn open( path: &Path, encoding: Option<&'static Encoding>, - config_loader: Option<Arc<syntax::Loader>>, + config_loader: Option<Arc<ArcSwap<syntax::Loader>>>, config: Arc<dyn DynAccess<Config>>, ) -> Result<Self, Error> { // Open the file if it exists, otherwise assume it is a new file (and thus empty). @@ -922,10 +922,11 @@ impl Document { } /// Detect the programming language based on the file type. - pub fn detect_language(&mut self, config_loader: Arc<syntax::Loader>) { + pub fn detect_language(&mut self, config_loader: Arc<ArcSwap<syntax::Loader>>) { + let loader = config_loader.load(); self.set_language( - self.detect_language_config(&config_loader), - Some(config_loader), + self.detect_language_config(&loader), + Some(Arc::clone(&config_loader)), ); } @@ -1059,10 +1060,12 @@ impl Document { pub fn set_language( &mut self, language_config: Option<Arc<helix_core::syntax::LanguageConfiguration>>, - loader: Option<Arc<helix_core::syntax::Loader>>, + loader: Option<Arc<ArcSwap<helix_core::syntax::Loader>>>, ) { if let (Some(language_config), Some(loader)) = (language_config, loader) { - if let Some(highlight_config) = language_config.highlight_config(&loader.scopes()) { + if let Some(highlight_config) = + language_config.highlight_config(&(*loader).load().scopes()) + { self.syntax = Syntax::new(self.text.slice(..), highlight_config, loader); } @@ -1078,9 +1081,10 @@ impl Document { pub fn set_language_by_language_id( &mut self, language_id: &str, - config_loader: Arc<syntax::Loader>, + config_loader: Arc<ArcSwap<syntax::Loader>>, ) -> anyhow::Result<()> { - let language_config = config_loader + let language_config = (*config_loader) + .load() .language_config_for_language_id(language_id) .ok_or_else(|| anyhow!("invalid language id: {}", language_id))?; self.set_language(Some(language_config), Some(config_loader)); diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 0fa6d67c..68b74cf0 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -50,7 +50,10 @@ use helix_stdx::path::canonicalize; use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer}; -use arc_swap::access::{DynAccess, DynGuard}; +use arc_swap::{ + access::{DynAccess, DynGuard}, + ArcSwap, +}; fn deserialize_duration_millis<'de, D>(deserializer: D) -> Result<Duration, D::Error> where @@ -918,7 +921,7 @@ pub struct Editor { pub debugger_events: SelectAll<UnboundedReceiverStream<dap::Payload>>, pub breakpoints: HashMap<PathBuf, Vec<Breakpoint>>, - pub syn_loader: Arc<syntax::Loader>, + pub syn_loader: Arc<ArcSwap<syntax::Loader>>, pub theme_loader: Arc<theme::Loader>, /// last_theme is used for theme previews. We store the current theme here, /// and if previewing is cancelled, we can return to it. @@ -1029,7 +1032,7 @@ impl Editor { pub fn new( mut area: Rect, theme_loader: Arc<theme::Loader>, - syn_loader: Arc<syntax::Loader>, + syn_loader: Arc<ArcSwap<syntax::Loader>>, config: Arc<dyn DynAccess<Config>>, handlers: Handlers, ) -> Self { @@ -1190,7 +1193,7 @@ impl Editor { } let scopes = theme.scopes(); - self.syn_loader.set_scopes(scopes.to_vec()); + (*self.syn_loader).load().set_scopes(scopes.to_vec()); match preview { ThemeAction::Preview => { |