From c183ed3c15110e11bffd40fad5c5fdfb4d1a5814 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 27 Jan 2022 23:07:10 +0100 Subject: Mutex comes from tex and we don't want any --- src/syntax/highlight.rs | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'src/syntax') diff --git a/src/syntax/highlight.rs b/src/syntax/highlight.rs index 001b28b3..0f1ee89d 100644 --- a/src/syntax/highlight.rs +++ b/src/syntax/highlight.rs @@ -23,32 +23,24 @@ where } /// Provide syntect highlighting styles for the children of a node. -pub fn highlight_syntect( - node: RedRef, - text: &str, - highlighter: &Highlighter, - f: &mut F, -) where - F: FnMut(Style, &str), +pub fn highlight_syntect(node: RedRef, highlighter: &Highlighter, f: &mut F) +where + F: FnMut(Range, Style), { - highlight_syntect_impl(node, text, vec![], highlighter, f) + highlight_syntect_impl(node, vec![], highlighter, f) } /// Recursive implementation for returning syntect styles. fn highlight_syntect_impl( node: RedRef, - text: &str, scopes: Vec, highlighter: &Highlighter, f: &mut F, ) where - F: FnMut(Style, &str), + F: FnMut(Range, Style), { if node.children().size_hint().0 == 0 { - f( - highlighter.style_for_stack(&scopes), - &text[node.span().to_range()], - ); + f(node.span().to_range(), highlighter.style_for_stack(&scopes)); return; } @@ -57,7 +49,7 @@ fn highlight_syntect_impl( if let Some(category) = Category::determine(child, node) { scopes.push(Scope::new(category.tm_scope()).unwrap()) } - highlight_syntect_impl(child, text, scopes, highlighter, f); + highlight_syntect_impl(child, scopes, highlighter, f); } } @@ -230,7 +222,7 @@ impl Category { } /// Return the TextMate grammar scope for the given highlighting category. - pub const fn tm_scope(&self) -> &'static str { + pub fn tm_scope(&self) -> &'static str { match self { Self::Bracket => "punctuation.definition.typst", Self::Punctuation => "punctuation.typst", -- cgit v1.2.3