Skip to content

Commit

Permalink
Introduce a TreeSitterError atom kind
Browse files Browse the repository at this point in the history
Starting work on Wilfred#267
  • Loading branch information
Wilfred committed Sep 19, 2022
1 parent f71ce08 commit 662b837
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/display/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ pub fn color_positions(
AtomKind::Keyword | AtomKind::Type => {
style = style.bold();
}
AtomKind::TreeSitterError => {
style = style.purple()
}
AtomKind::Normal => {}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/parse/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ pub enum AtomKind {
Type,
Comment,
Keyword,
TreeSitterError,
}

/// Unlike atoms, tokens can be delimiters like `{`.
Expand Down
13 changes: 9 additions & 4 deletions src/parse/tree_sitter_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 662b837

Please sign in to comment.