Add the source to the closure

This commit is contained in:
Quentin Boyer 2026-01-22 01:21:20 +01:00
parent 1a54b1794d
commit c2e50ccd11
2 changed files with 10 additions and 9 deletions

View file

@ -297,7 +297,7 @@ impl TSHighlighter {
})
})
},
&|_, _| true,
&|_, _, _| true,
);
if let Ok(highlights) = highlights {

View file

@ -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<impl Iterator<Item = Result<HighlightEvent, Error>> + '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<dyn Iterator<Item = _>> = Box::new(
captures.filter(|(result, _): &(_, _)| query_filter(result, &config.query)),
);
let captures: Box<dyn Iterator<Item = _>> =
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<HighlightEvent, Error>;