Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/ui/picker.rs')
| -rw-r--r-- | helix-term/src/ui/picker.rs | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 7abdfce8..3f3aaba2 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -585,8 +585,7 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> { // retrieve the `Arc<Path>` key. The `path` in scope here is a `&Path` and // we can cheaply clone the key for the preview highlight handler. let (path, preview) = self.preview_cache.get_key_value(path).unwrap(); - if matches!(preview, CachedPreview::Document(doc) if doc.language_config().is_none()) - { + if matches!(preview, CachedPreview::Document(doc) if doc.syntax().is_none()) { helix_event::send_blocking(&self.preview_highlight_handler, path.clone()); } return Some((Preview::Cached(preview), range)); @@ -624,27 +623,27 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> { if content_type.is_binary() { return Ok(CachedPreview::Binary); } - Document::open( + let mut doc = Document::open( &path, None, false, editor.config.clone(), editor.syn_loader.clone(), ) - .map_or( - Err(std::io::Error::new( - std::io::ErrorKind::NotFound, - "Cannot open document", - )), - |doc| { - // Asynchronously highlight the new document - helix_event::send_blocking( - &self.preview_highlight_handler, - path.clone(), - ); - Ok(CachedPreview::Document(Box::new(doc))) - }, - ) + .or(Err(std::io::Error::new( + std::io::ErrorKind::NotFound, + "Cannot open document", + )))?; + let loader = editor.syn_loader.load(); + if let Some(language_config) = doc.detect_language_config(&loader) { + doc.language = Some(language_config); + // Asynchronously highlight the new document + helix_event::send_blocking( + &self.preview_highlight_handler, + path.clone(), + ); + } + Ok(CachedPreview::Document(Box::new(doc))) } else { Err(std::io::Error::new( std::io::ErrorKind::NotFound, |