Introduce a TreeSitterError atom kind

Starting work on #267
pull/381/head
Wilfred Hughes 2022-09-19 09:47:55 +07:00
parent f71ce08407
commit 662b837ae3
3 changed files with 13 additions and 4 deletions

@ -299,6 +299,9 @@ pub fn color_positions(
AtomKind::Keyword | AtomKind::Type => {
style = style.bold();
}
AtomKind::TreeSitterError => {
style = style.purple()
}
AtomKind::Normal => {}
}
}

@ -583,6 +583,7 @@ pub enum AtomKind {
Type,
Comment,
Keyword,
TreeSitterError,
}
/// Unlike atoms, tokens can be delimiters like `{`.

@ -1238,13 +1238,18 @@ fn atom_from_cursor<'a>(
content = content.trim();
}
// 'extra' nodes in tree-sitter are comments. Most parsers use
// 'comment' as their comment node name, but if they don't we can
// still detect comments by looking at their syntax highlighting.
let highlight = if node.is_extra()
node.is_error();
let highlight = if node.is_error() {
AtomKind::TreeSitterError
} else if node.is_extra()
|| node.kind() == "comment"
|| highlights.comment_ids.contains(&node.id())
{
// 'extra' nodes in tree-sitter are comments. Most parsers use
// 'comment' as their comment node name, but if they don't we
// can still detect comments by looking at their syntax
// highlighting.
AtomKind::Comment
} else if highlights.keyword_ids.contains(&node.id()) {
AtomKind::Keyword