mirror of https://github.com/helix-editor/helix
Picker: Detect language before rendering preview (#13761)
parent
b90d8960a8
commit
fba1a6188a
|
@ -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
|
// 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.
|
// we can cheaply clone the key for the preview highlight handler.
|
||||||
let (path, preview) = self.preview_cache.get_key_value(path).unwrap();
|
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());
|
helix_event::send_blocking(&self.preview_highlight_handler, path.clone());
|
||||||
}
|
}
|
||||||
return Some((Preview::Cached(preview), range));
|
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() {
|
if content_type.is_binary() {
|
||||||
return Ok(CachedPreview::Binary);
|
return Ok(CachedPreview::Binary);
|
||||||
}
|
}
|
||||||
Document::open(
|
let mut doc = Document::open(
|
||||||
&path,
|
&path,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
editor.config.clone(),
|
editor.config.clone(),
|
||||||
editor.syn_loader.clone(),
|
editor.syn_loader.clone(),
|
||||||
)
|
)
|
||||||
.map_or(
|
.or(Err(std::io::Error::new(
|
||||||
Err(std::io::Error::new(
|
|
||||||
std::io::ErrorKind::NotFound,
|
std::io::ErrorKind::NotFound,
|
||||||
"Cannot open document",
|
"Cannot open document",
|
||||||
)),
|
)))?;
|
||||||
|doc| {
|
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
|
// Asynchronously highlight the new document
|
||||||
helix_event::send_blocking(
|
helix_event::send_blocking(
|
||||||
&self.preview_highlight_handler,
|
&self.preview_highlight_handler,
|
||||||
path.clone(),
|
path.clone(),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
Ok(CachedPreview::Document(Box::new(doc)))
|
Ok(CachedPreview::Document(Box::new(doc)))
|
||||||
},
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
Err(std::io::Error::new(
|
Err(std::io::Error::new(
|
||||||
std::io::ErrorKind::NotFound,
|
std::io::ErrorKind::NotFound,
|
||||||
|
|
|
@ -66,16 +66,15 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> AsyncHook
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if doc.language_config().is_some() {
|
if doc.syntax().is_some() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let loader = editor.syn_loader.load();
|
let Some(language) = doc.language_config().map(|config| config.language()) else {
|
||||||
let Some(language_config) = doc.detect_language_config(&loader) else {
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let language = language_config.language();
|
|
||||||
doc.language = Some(language_config);
|
let loader = editor.syn_loader.load();
|
||||||
let text = doc.text().clone();
|
let text = doc.text().clone();
|
||||||
|
|
||||||
tokio::task::spawn_blocking(move || {
|
tokio::task::spawn_blocking(move || {
|
||||||
|
|
Loading…
Reference in New Issue