Treat error nodes as atoms

Fixes #408
pull/402/head
Wilfred Hughes 2022-10-15 22:46:19 +07:00
parent 267b413f08
commit b9d44ae65f
5 changed files with 27 additions and 5 deletions

@ -1,5 +1,12 @@
## 0.38 (unreleased)
### Parsing
Syntax error nodes are now always treated as atoms. This produces
better results when difftastic doesn't fully support the syntax
(e.g. PostCSS is a superset of CSS) or when there are actual syntax
errors.
## 0.37 (released 14th October 2022)
### Manual

@ -47,7 +47,7 @@ sample_files/hack_before.php sample_files/hack_after.php
50babcb945cf3b3ba12d5481a1bf8ccf -
sample_files/hare_before.ha sample_files/hare_after.ha
8edc2f3ae2eaeba7bcf328ed00398767 -
5fee7a686838b20327ed135ae07db0c2 -
sample_files/haskell_before.hs sample_files/haskell_after.hs
324d1c9b2a04133a75b1975272ffb6ad -
@ -179,11 +179,14 @@ sample_files/swift_before.swift sample_files/swift_after.swift
eeab25a68552f051a6392b5e713fbd29 -
sample_files/syntax_error_before.js sample_files/syntax_error_after.js
fe636ad27b1aa75e0b153dfe248023bb -
5210fe27bf588a4a4a0ed826dfcac76b -
sample_files/tab_before.c sample_files/tab_after.c
36ba3231eeba6f0b67a6be9db454de19 -
sample_files/tailwind_before.css sample_files/tailwind_after.css
a0ba45ac66d0c0b97377821a872d83fc -
sample_files/text_before.txt sample_files/text_after.txt
dfc3495b8d5931029b479f0c878a3219 -

@ -0,0 +1,6 @@
select {
/* This isn't valid vanilla CSS, and tree-sitter-css produces an ERROR
node with children. Ensure the whole ERROR is treated as an
atom. */
@apply rounded-md bg-hss-dark-gray;
}

@ -0,0 +1,6 @@
select {
/* This isn't valid vanilla CSS, and tree-sitter-css produces an ERROR
node with children. Ensure the whole ERROR is treated as an
atom. */
@apply rounded-md bg-gray-600;
}

@ -1077,15 +1077,15 @@ fn syntax_from_cursor<'a>(
if node.is_error() {
let position = nl_pos.from_offsets(node.start_byte(), node.end_byte());
let content = &src[node.start_byte()..node.end_byte()];
debug!(
"Tree-sitter syntax error at {:?}: {}",
position.get(0),
content
);
}
if config.atom_nodes.contains(node.kind()) {
// Treat error nodes as atoms, even if they have children.
atom_from_cursor(arena, src, nl_pos, cursor, highlights)
} else if config.atom_nodes.contains(node.kind()) {
// Treat nodes like string literals as atoms, regardless
// of whether they have children.
atom_from_cursor(arena, src, nl_pos, cursor, highlights)