Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/ui/picker/handlers.rs')
-rw-r--r--helix-term/src/ui/picker/handlers.rs45
1 files changed, 21 insertions, 24 deletions
diff --git a/helix-term/src/ui/picker/handlers.rs b/helix-term/src/ui/picker/handlers.rs
index eabfac0c..ac34e893 100644
--- a/helix-term/src/ui/picker/handlers.rs
+++ b/helix-term/src/ui/picker/handlers.rs
@@ -66,24 +66,32 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> AsyncHook
return;
};
- if doc.syntax().is_some() {
+ if doc.language_config().is_some() {
return;
}
- let Some(language) = doc.language_config().map(|config| config.language()) else {
+ let Some(language_config) = doc.detect_language_config(&editor.syn_loader.load())
+ else {
return;
};
-
- let loader = editor.syn_loader.load();
+ doc.language = Some(language_config.clone());
let text = doc.text().clone();
+ let loader = editor.syn_loader.clone();
tokio::task::spawn_blocking(move || {
- let syntax = match helix_core::Syntax::new(text.slice(..), language, &loader) {
- Ok(syntax) => syntax,
- Err(err) => {
- log::info!("highlighting picker preview failed: {err}");
- return;
- }
+ let Some(syntax) = language_config
+ .highlight_config(&loader.load().scopes())
+ .and_then(|highlight_config| {
+ helix_core::Syntax::new(text.slice(..), highlight_config, |injection| {
+ loader
+ .load()
+ .language_configuration_for_injection_string(injection)
+ .and_then(|config| config.get_highlight_config())
+ })
+ })
+ else {
+ log::info!("highlighting picker item failed");
+ return;
};
job::dispatch_blocking(move |editor, compositor| {
@@ -112,11 +120,6 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> AsyncHook
}
}
-pub(super) struct DynamicQueryChange {
- pub query: Arc<str>,
- pub is_paste: bool,
-}
-
pub(super) struct DynamicQueryHandler<T: 'static + Send + Sync, D: 'static + Send + Sync> {
callback: Arc<DynQueryCallback<T, D>>,
// Duration used as a debounce.
@@ -139,10 +142,9 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> DynamicQueryHandler<T,
}
impl<T: 'static + Send + Sync, D: 'static + Send + Sync> AsyncHook for DynamicQueryHandler<T, D> {
- type Event = DynamicQueryChange;
+ type Event = Arc<str>;
- fn handle_event(&mut self, change: Self::Event, _timeout: Option<Instant>) -> Option<Instant> {
- let DynamicQueryChange { query, is_paste } = change;
+ fn handle_event(&mut self, query: Self::Event, _timeout: Option<Instant>) -> Option<Instant> {
if query == self.last_query {
// If the search query reverts to the last one we requested, no need to
// make a new request.
@@ -150,12 +152,7 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> AsyncHook for DynamicQu
None
} else {
self.query = Some(query);
- if is_paste {
- self.finish_debounce();
- None
- } else {
- Some(Instant::now() + self.debounce)
- }
+ Some(Instant::now() + self.debounce)
}
}