diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-01-27 23:07:10 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-01-27 23:07:10 +0100 |
| commit | c183ed3c15110e11bffd40fad5c5fdfb4d1a5814 (patch) | |
| tree | 3deea994c8e1b44fc3a0644eca10162c46b9b3fc /src/syntax | |
| parent | 4f66907d08a8ed18b41e70188b112d7c915aa0bc (diff) | |
Mutex comes from tex and we don't want any
Diffstat (limited to 'src/syntax')
| -rw-r--r-- | src/syntax/highlight.rs | 24 |
1 files changed, 8 insertions, 16 deletions
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<F>( - node: RedRef, - text: &str, - highlighter: &Highlighter, - f: &mut F, -) where - F: FnMut(Style, &str), +pub fn highlight_syntect<F>(node: RedRef, highlighter: &Highlighter, f: &mut F) +where + F: FnMut(Range<usize>, 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<F>( node: RedRef, - text: &str, scopes: Vec<Scope>, highlighter: &Highlighter, f: &mut F, ) where - F: FnMut(Style, &str), + F: FnMut(Range<usize>, 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<F>( 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", |
