Skip to content

Commit

Permalink
Treat Makefile text as atoms
Browse files Browse the repository at this point in the history
Improves another case identified in #476
  • Loading branch information
Wilfred committed Mar 3, 2023
1 parent f8a7cce commit 0398506
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 0.45 (unreleased)

### Parsing

Improved parsing for Makefiles.

## 0.44 (released 2nd March 2023)

### Parsing
Expand Down
1 change: 1 addition & 0 deletions sample_files/cli_tests/makefile_after.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CCFLAGS+=-std=c99 -D_DEFAULT_SOURCE -DVERSION=\"$(VERS)\" -O2 -D_FORTIFY_SOURCE=2 -fstack-protector-all $(CFLAGS) -g
1 change: 1 addition & 0 deletions sample_files/cli_tests/makefile_before.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CCFLAGS+=-std=c99 -D_DEFAULT_SOURCE -DVERSION=\"$(VERS)\" -O2 -Wall -Werror -D_FORTIFY_SOURCE=2 -fstack-protector-all $(CFLAGS) -g
2 changes: 1 addition & 1 deletion src/parse/tree_sitter_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ pub fn from_language(language: guess::Language) -> TreeSitterConfig {
let language = unsafe { tree_sitter_make() };
TreeSitterConfig {
language,
atom_nodes: vec!["shell_text"].into_iter().collect(),
atom_nodes: vec!["shell_text", "text"].into_iter().collect(),
delimiter_tokens: vec![("(", ")")].into_iter().collect(),
highlight_query: ts::Query::new(
language,
Expand Down
13 changes: 13 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,16 @@ fn check_only_text_file() {
let predicate_fn = predicate::str::contains("Has changes");
cmd.assert().stdout(predicate_fn);
}

#[test]
fn makefile_text_as_atom() {
use predicates::prelude::*;

let mut cmd = Command::cargo_bin("difft").unwrap();

cmd.arg("sample_files/cli_tests/makefile_before.mk")
.arg("sample_files/cli_tests/makefile_after.mk");

let predicate_fn = predicate::str::contains("CCFLAGS");
cmd.assert().stdout(predicate_fn);
}

0 comments on commit 0398506

Please sign in to comment.