From c2e50ccd112ab0ebf40a1a55ab972d964087dcf8 Mon Sep 17 00:00:00 2001 From: Quentin Boyer Date: Thu, 22 Jan 2026 01:21:20 +0100 Subject: [PATCH] Add the source to the closure --- crates/highlight/src/c_lib.rs | 2 +- crates/highlight/src/highlight.rs | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/crates/highlight/src/c_lib.rs b/crates/highlight/src/c_lib.rs index dd596ee2..e3a219fc 100644 --- a/crates/highlight/src/c_lib.rs +++ b/crates/highlight/src/c_lib.rs @@ -297,7 +297,7 @@ impl TSHighlighter { }) }) }, - &|_, _| true, + &|_, _, _| true, ); if let Ok(highlights) = highlights { diff --git a/crates/highlight/src/highlight.rs b/crates/highlight/src/highlight.rs index 892370d6..5794b5b0 100644 --- a/crates/highlight/src/highlight.rs +++ b/crates/highlight/src/highlight.rs @@ -165,7 +165,7 @@ struct LocalScope<'a> { struct HighlightIter<'a, F, G> where F: FnMut(&str) -> Option<&'a HighlightConfiguration> + 'a, - G: Fn(&QueryMatch, &Query) -> bool + 'a, + G: Fn(&QueryMatch, &Query, &[u8]) -> bool + 'a, { source: &'a [u8], language_name: &'a str, @@ -291,7 +291,7 @@ impl Highlighter { source: &'a [u8], cancellation_flag: Option<&'a AtomicUsize>, mut injection_callback: impl FnMut(&str) -> Option<&'a HighlightConfiguration> + 'a, - query_filter: &'a impl Fn(&QueryMatch, &Query) -> bool, + query_filter: &'a impl Fn(&QueryMatch, &Query, &[u8]) -> bool, ) -> Result> + 'a, Error> { let layers = HighlightIterLayer::new( source, @@ -518,7 +518,7 @@ impl<'a> HighlightIterLayer<'a> { #[allow(clippy::too_many_arguments)] fn new< F: FnMut(&str) -> Option<&'a HighlightConfiguration> + 'a, - G: Fn(&QueryMatch, &Query) -> bool, + G: Fn(&QueryMatch, &Query, &[u8]) -> bool, >( source: &'a [u8], parent_name: Option<&str>, @@ -624,9 +624,10 @@ impl<'a> HighlightIterLayer<'a> { )) }; - let captures: Box> = Box::new( - captures.filter(|(result, _): &(_, _)| query_filter(result, &config.query)), - ); + let captures: Box> = + Box::new(captures.filter(|(result, _): &(_, _)| { + query_filter(result, &config.query, source) + })); result.push(HighlightIterLayer { highlight_end_stack: Vec::new(), @@ -779,7 +780,7 @@ impl<'a> HighlightIterLayer<'a> { impl<'a, F, G> HighlightIter<'a, F, G> where F: FnMut(&str) -> Option<&'a HighlightConfiguration> + 'a, - G: Fn(&QueryMatch, &Query) -> bool, + G: Fn(&QueryMatch, &Query, &[u8]) -> bool, { fn emit_event( &mut self, @@ -846,7 +847,7 @@ where impl<'a, F, G> Iterator for HighlightIter<'a, F, G> where F: FnMut(&str) -> Option<&'a HighlightConfiguration> + 'a, - G: Fn(&QueryMatch, &Query) -> bool, + G: Fn(&QueryMatch, &Query, &[u8]) -> bool, { type Item = Result;