Don't flatten error nodes

As of b9d44ae65f (released in 0.38), difftastic prefers a textual
diff if any parse errors are present. As a result, users have to
opt-in to allowing parse errors. We can now preserve structure to
produce diffs that are more granular, at the slight risk of changes
being missed if parsers discard tokens.

Fixes #703
pull/708/head
Wilfred Hughes 2024-04-28 17:28:34 +07:00
parent 7f5c11c075
commit 38f148df1f
3 changed files with 16 additions and 5 deletions

@ -1,5 +1,17 @@
## 0.58 (unreleased)
### Parsing
Difftastic now preserves tree-sitter parse tree structure on parse
error nodes. This reverts the flattening behaviour introduced in
0.38. Preserving structure tends to produce better diffs, although it
increases the risk that difftastic will show fewer changes in the
presence of parse errors.
Since difftastic is now conservative with parse errors
(DFT_PARSE_ERROR_LIMIT is 0 by default), this seems like a better
tradeoff.
### Diffing
`--strip-cr` now defaults to `on`, so comparing a file with CRLF

@ -134,7 +134,7 @@ sample_files/lua_before.lua sample_files/lua_after.lua
9f5c85cd6806c724c84afa805da76bb7 -
sample_files/makefile_before.mk sample_files/makefile_after.mk
7eea0d919b71161c72a4ef496fff749d -
20cf6b508d1707e41e5450572ee51838 -
sample_files/many_newlines_before.txt sample_files/many_newlines_after.txt
afc8628f89076423d1453d8e3c84ac92 -
@ -254,7 +254,7 @@ sample_files/tab_before.txt sample_files/tab_after.txt
c7fcee21dd5ebd251e2cf4cd7d4446d2 -
sample_files/tailwind_before.css sample_files/tailwind_after.css
db01dde1e8455a144e5bf0511273f674 -
be0cba204957b62a30e99fd03f945de5 -
sample_files/text_before.txt sample_files/text_after.txt
5fa6a472ccdeda0142eda3edcaeaa189 -

@ -1608,10 +1608,9 @@ fn syntax_from_cursor<'a>(
if node.is_error() {
*error_count += 1;
}
// Treat error nodes as atoms, even if they have children.
atom_from_cursor(arena, src, nl_pos, cursor, highlights, ignore_comments)
} else if config.atom_nodes.contains(node.kind()) {
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, ignore_comments)