Discard '\n' nodes in C and C++

These are from the preprocessor grammar rules, but they're not useful
for difftastic.

Reported upstream: https://github.com/tree-sitter/tree-sitter-c/issues/97

Closes #180
pull/185/head
Wilfred Hughes 2022-03-27 23:29:54 +07:00
parent a189f49a5e
commit f26ca24df7
5 changed files with 23 additions and 0 deletions

@ -10,6 +10,11 @@ When a file is entirely unchanged, difftastic now shows "no changes"
even if it successfully parsed. Previously it would only show "no
syntactic changes".
### Parsing
Fixed an issue in C and C++ where blank lines were highlighted after
novel preprocessor lines.
## 0.24 (release 26th March 2022)
### Diffing

@ -85,6 +85,9 @@ sample_files/ocaml_before.ml sample_files/ocaml_after.ml
sample_files/outer_delimiter_before.el sample_files/outer_delimiter_after.el
73130b8572a4f17fa6cf828f74e226ce -
sample_files/preprocesor_before.h sample_files/preprocesor_after.h
3e4331cb935cbe735a79ebc43786cd3a -
sample_files/ruby_before.rb sample_files/ruby_after.rb
4a9847a91e32ec6afdc2f0b01e28d2d6 -

@ -0,0 +1,4 @@
#include "foo.h"
#include "novel.h"
struct Bar {};

@ -0,0 +1,3 @@
#include "foo.h"
struct Bar {};

@ -857,6 +857,14 @@ fn atom_from_cursor<'a>(
let position = nl_pos.from_offsets(node.start_byte(), node.end_byte());
let mut content = &src[node.start_byte()..node.end_byte()];
// The C and C++ grammars have a '\n' node with the
// preprocessor. This isn't useful for difftastic, because it's
// not visible, but leads us to highlight unchanged lines that
// happen to have preceding newline node.
if node.kind() == "\n" {
return vec![];
}
// JSX trims whitespace at the beginning and end of text nodes.
// TODO: match the exact trimming behaviour used in React.
//