summaryrefslogtreecommitdiff
path: root/src/syntax/highlight.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-05-31 10:40:30 +0200
committerLaurenz <laurmaedje@gmail.com>2022-05-31 10:40:30 +0200
commit08a6188123ad0806986fa4f5477b728a07d081cc (patch)
tree3338f1d64ebdd6df734bcc9ae0172bda2e075a2a /src/syntax/highlight.rs
parent665ed12825918bd02a6d6dbcb67860a83dd41600 (diff)
Remove green/red distinction
Diffstat (limited to 'src/syntax/highlight.rs')
-rw-r--r--src/syntax/highlight.rs26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/syntax/highlight.rs b/src/syntax/highlight.rs
index 94abc238..1b84fdba 100644
--- a/src/syntax/highlight.rs
+++ b/src/syntax/highlight.rs
@@ -5,13 +5,12 @@ use std::sync::Arc;
use syntect::highlighting::{Color, FontStyle, Highlighter, Style, Theme};
use syntect::parsing::Scope;
-use super::{GreenNode, NodeKind, RedNode, RedRef};
+use super::{InnerNode, NodeKind, SyntaxNode};
use crate::parse::TokenMode;
-use crate::source::SourceId;
/// Provide highlighting categories for the descendants of a node that fall into
/// a range.
-pub fn highlight_node<F>(node: RedRef, range: Range<usize>, f: &mut F)
+pub fn highlight_node<F>(node: &SyntaxNode, range: Range<usize>, f: &mut F)
where
F: FnMut(Range<usize>, Category),
{
@@ -36,20 +35,21 @@ where
TokenMode::Markup => crate::parse::parse(text),
TokenMode::Code => {
let children = crate::parse::parse_code(text);
- Arc::new(GreenNode::with_children(NodeKind::CodeBlock, children))
+ SyntaxNode::Inner(Arc::new(InnerNode::with_children(
+ NodeKind::CodeBlock,
+ children,
+ )))
}
};
- let root = RedNode::from_root(root, SourceId::from_raw(0));
let highlighter = Highlighter::new(&theme);
-
- highlight_themed_impl(text, root.as_ref(), vec![], &highlighter, f);
+ highlight_themed_impl(text, &root, vec![], &highlighter, f);
}
/// Recursive implementation for returning syntect styles.
fn highlight_themed_impl<F>(
text: &str,
- node: RedRef,
+ node: &SyntaxNode,
scopes: Vec<Scope>,
highlighter: &Highlighter,
f: &mut F,
@@ -178,7 +178,11 @@ pub enum Category {
impl Category {
/// Determine the highlighting category of a node given its parent and its
/// index in its siblings.
- pub fn determine(child: RedRef, parent: RedRef, i: usize) -> Option<Category> {
+ pub fn determine(
+ child: &SyntaxNode,
+ parent: &SyntaxNode,
+ i: usize,
+ ) -> Option<Category> {
match child.kind() {
NodeKind::LeftBrace => Some(Category::Bracket),
NodeKind::RightBrace => Some(Category::Bracket),
@@ -262,7 +266,7 @@ impl Category {
if parent
.children()
.filter(|c| matches!(c.kind(), NodeKind::Ident(_)))
- .map(RedRef::span)
+ .map(SyntaxNode::span)
.nth(1)
.map_or(false, |span| span == child.span()) =>
{
@@ -359,7 +363,7 @@ mod tests {
let mut vec = vec![];
let source = SourceFile::detached(src);
let full = 0 .. src.len();
- highlight_node(source.red().as_ref(), full, &mut |range, category| {
+ highlight_node(source.root(), full, &mut |range, category| {
vec.push((range, category));
});
assert_eq!(vec, goal);