diff --git a/src/display/style.rs b/src/display/style.rs index 484b2e31ba..f738bd83df 100644 --- a/src/display/style.rs +++ b/src/display/style.rs @@ -299,6 +299,9 @@ pub fn color_positions( AtomKind::Keyword | AtomKind::Type => { style = style.bold(); } + AtomKind::TreeSitterError => { + style = style.purple() + } AtomKind::Normal => {} } } diff --git a/src/parse/syntax.rs b/src/parse/syntax.rs index d40892f296..bc5f8d7fc2 100644 --- a/src/parse/syntax.rs +++ b/src/parse/syntax.rs @@ -583,6 +583,7 @@ pub enum AtomKind { Type, Comment, Keyword, + TreeSitterError, } /// Unlike atoms, tokens can be delimiters like `{`. diff --git a/src/parse/tree_sitter_parser.rs b/src/parse/tree_sitter_parser.rs index b700587bd6..ecb8a5390a 100644 --- a/src/parse/tree_sitter_parser.rs +++ b/src/parse/tree_sitter_parser.rs @@ -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