Commit Graph

717 Commits (711d39975806233ce505abcea45998170d402579)

Author SHA1 Message Date
Wilfred Hughes febfbcea3e Make word diffs more granular
Fixes #39
2021-10-03 16:43:08 +07:00
Wilfred Hughes 98ca8ea106 Ensure that single-item tree-sitter lists are difftastic lists
This is important when executing tree-sitter queries, as highlighting
queries tend to target leaf nodes. Flattening the tree loses that.

This may also lead to more accurate diffing logic in some examples,
but I haven't found any obvious cases.
2021-10-01 23:57:15 +07:00
Wilfred Hughes 67916d260d Dim unchanged comments as a crude syntax highlighting technique 2021-09-30 00:07:37 +07:00
Wilfred Hughes b747cdcb01 Make bad position data more obvious (use purple) 2021-09-29 23:57:44 +07:00
Wilfred Hughes d37c87a1a5 Update changelog for patch release 2021-09-28 09:50:02 +07:00
Wilfred Hughes 9409e4fb4e Clarify platform in changelog 2021-09-28 09:41:08 +07:00
Wilfred Hughes ec37c5bef1 Add full Mercurial extdiff support 2021-09-26 21:23:22 +07:00
Wilfred Hughes 6ac01365c6 Update changelog for build fix 2021-09-26 21:21:02 +07:00
Wilfred Hughes 4e09fd0507 Match delimiters when converting from tree-sitter to syntax
Previously, we only handled simple cases like `(x)` where the first
and last token were the delimiter tokens. We now allow arbitrary
tokens before and after the delimiter, and wrap them in an additional
list.

This was more common in the C family parsers, but it's a general
problem. It also helps with robustness of JSX/TSX delimiter parsing of
`<`, where we now require a close `>` at the same level.
2021-09-25 22:25:05 +07:00
Wilfred Hughes 48efe9d7c4 Roll version 2021-09-24 23:40:07 +07:00
Wilfred Hughes c9f85d806e Document the main tricky cases with tree diffs 2021-09-24 23:33:25 +07:00
Wilfred Hughes 3b36e6486d Add C# support
Closes #37.
2021-09-22 22:37:53 +07:00
Wilfred Hughes f6ada434fe Add Haskell support
Fixes #36
2021-09-22 10:18:48 +07:00
Wilfred Hughes a0388c7d8b Optimise equal_content by checking num_descendants first
Traversing children is costly so we avoid it where possible. This
saves a further ~5% runtime on slow_before.rs/slow_after.rs.
2021-09-19 23:57:14 +07:00
Wilfred Hughes d7b0c917c1 Remove regex parser 2021-09-19 12:17:25 +07:00
Wilfred Hughes 6c08507b0d Add C++ support 2021-09-17 22:37:41 +07:00
Wilfred Hughes fb96b0a78d Add C support 2021-09-14 23:25:22 +07:00
Wilfred Hughes 31572a83a9 Roll version following release 2021-09-14 00:34:38 +07:00
Wilfred Hughes 7fa9b29e4d Factor out a lib.rs
This makes it easier for us to use tools that require a library, such
as criterion.
2021-09-13 00:41:58 +07:00
Wilfred Hughes 2da9747e26 Add more Rust delimiter tokens 2021-09-12 00:36:33 +07:00
Wilfred Hughes 9e9f7aff78 Update changelog for Rust parsing improvements 2021-09-11 21:11:41 +07:00
Wilfred Hughes eed16fc6d7 Simplify Dijkstra implementation
This is faster than the previous approach, and also less code.
2021-09-11 15:26:59 +07:00
Wilfred Hughes fd0dd8e75d Always use the full width for LHS column in side-by-side display 2021-09-06 15:21:20 +07:00
Wilfred Hughes 2ac459918a Add support for Elixir 2021-09-06 15:09:44 +07:00
Wilfred Hughes a39d4b3bb7 Use word-level diffs for text content too
We already do word-level diffs for comments, so use comment atoms in
the line-based parser.

Fixes #33
2021-09-06 12:47:20 +07:00
Wilfred Hughes d29bd46969 Associate more file extensions with Clojure
Fixes #31
2021-09-05 19:43:47 +07:00
Wilfred Hughes 34a5bd768d TSX is now supported 2021-09-05 19:37:28 +07:00
Wilfred Hughes 6d98fd86ab Configure typescript parser 2021-09-05 19:26:44 +07:00
Wilfred Hughes b6b0f8057b Treat integer values as atoms in CSS 2021-09-05 11:39:49 +07:00
Wilfred Hughes e3b2994aa9 Java parser was added in 0.7 too 2021-09-05 11:23:21 +07:00
Wilfred Hughes 0f042fb160 Roll version 2021-09-05 11:23:00 +07:00
Wilfred Hughes d99ada1573 Preserve leading whitespace when constructing comment nodes
Display relies on accurate content values. If we transform comment
contents, we would colour the wrong part of the source code when
displaying. See before/after.java sample files.
2021-09-05 11:13:05 +07:00
Wilfred Hughes e4b5bd4e19 Remove Scheme support
There's no tree-sitter parser available sadly, and I eventually plan
to drop the regex parser.
2021-09-04 18:30:17 +07:00
Wilfred Hughes 809d6383ad Document Python support 2021-09-04 17:05:11 +07:00
Wilfred Hughes 86a330c44e Add debug logging and log stats on shortest path found 2021-09-04 10:46:51 +07:00
Wilfred Hughes d1354c7174 Use a single-column display when whole files are added or removed 2021-08-29 23:42:59 +07:00
Wilfred Hughes cc93976969 Handle SIGPIPE
Based on the sample code in
https://stackoverflow.com/a/65760807/509706

Closes #28
2021-08-29 16:50:05 +07:00
Wilfred Hughes c662181cd6 Make tree-sitter the default parser 2021-08-29 15:17:40 +07:00
Wilfred Hughes 1dfedc6534 Ensure we use codepoints when slicing strings to avoid crashes
Rust will panic if we try to slice on a boundary that isn't a char
boundary. Count unicode codepoints and slice to the relevant byte.

Added a test file that was crashing before due to the use of curly
quotes.
2021-08-29 15:10:01 +07:00
Wilfred Hughes 32c3e9d0ca Fix another crash when removing a whole file in git 2021-08-28 12:53:55 +07:00
Wilfred Hughes 7f021e147d Improve handling of delimiters in all supported tree-sitter languages 2021-08-28 12:00:06 +07:00
Wilfred Hughes 2eb2f8b67d Add a --dump-ts debug option 2021-08-28 11:24:29 +07:00
Wilfred Hughes 1d0b1ad6b6 Add --dump-syntax for debugging the syntax tree 2021-08-27 22:32:48 +07:00
Wilfred Hughes 35779dde2e Remove unused --lang argument 2021-08-27 22:11:30 +07:00
Wilfred Hughes 309e4bc02c Match delimiter tokens based on their content 2021-08-26 23:51:06 +07:00
Wilfred Hughes bda2ce7d11 Improve string literals in tree-sitter parsers 2021-08-26 23:35:19 +07:00
Wilfred Hughes d5ce3e626f Fix missing string pattern for JSON parser 2021-08-24 01:12:11 +07:00
Wilfred Hughes 5d67ad3bea Merge display sections in changelog 2021-08-24 00:23:32 +07:00
Wilfred Hughes f17e0a5e0a Support colour when using git with a pager
Closes #29
2021-08-24 00:20:34 +07:00
Wilfred Hughes fad0775315 Fix crash on renaming files 2021-08-22 23:51:41 +07:00
Wilfred Hughes 6f1a069a75 Document usage of tree-sitter 2021-08-16 22:30:12 +07:00
Wilfred Hughes 414182c9dd Only show a single column in side-by-side when adding a whole file 2021-08-08 23:25:26 +07:00
Wilfred Hughes 09a80150df Fix adding/removing whole files
The 'remove unaligned lines at beginning of hunk' logic meant we just
discarded the whole hunk.

This breaks alignment again (previously fixed in 3ebbf268fd), but that
should be fixed properly in the padding logic.
2021-08-08 23:15:23 +07:00
Wilfred Hughes 3ae0b7df84 Allow RHS to be arbitrarily long in a pager
If stdout is not a TTY, assume it's a pager and don't truncate the
RHS.
2021-08-08 17:35:31 +07:00
Wilfred Hughes 857cb77d8f Ensure LHS and RHS source code are the same width 2021-08-08 17:31:18 +07:00
Wilfred Hughes 83b8c843cb Use .. for column numbers on blank lines used to align 2021-08-08 11:26:17 +07:00
Wilfred Hughes 1ceaecfa25 Remove --width from CLI parameters
This is the first step in refactoring for inline diffs.
2021-08-01 15:30:12 +07:00
Wilfred Hughes 2e6666041f Contiguous novel atoms are always better than changing depth of novel lists 2021-07-31 23:32:23 +07:00
Wilfred Hughes 34f084d8f1 Calculate content width based on visible lines 2021-07-31 17:21:55 +07:00
Wilfred Hughes e67732bab9 Improve contiguous novel logic
Inspect the previous syntactic node, then get the atom position, open
delimiter position or close delimiter position depending on the
context.
2021-07-31 16:54:14 +07:00
Wilfred Hughes a4751b98f1 Fix a parsing issue with -> in Rust 2021-07-31 01:25:16 +07:00
Wilfred Hughes 573cd32a01 Prefer matching comments that are similar
Previously, we'd match up any pair of comments with a levenstein
distance of 0.4 or more. This was reasonably effective, but misssed
opportunities even more precise diffs.

Instead, prefer the comment matching with the highest levenshtein
distance.

We still only highlight word-level changes for comments with a
levenshtein of 0.4 or more.

Closes #27
2021-07-30 22:54:30 +07:00
Wilfred Hughes da63704675 Roll version 2021-07-28 00:04:47 +07:00
Wilfred Hughes 6f2140e901 Replace tabs with spaces before parsing
Difftastic uses offsets to store the positions of AST nodes, so we
cannot replace tabs after parsing.

A string literal with a tab character "	" being replaced by a four
space string literal "    " is now ignored by difftastic. This is
wrong: difftastic should only ignore whitespace between atoms.

This is still an improvement for source code that uses tab characters,
which is common in Go. The above case should be rare until we have a
full solution.

Fixes #24
2021-07-27 23:36:20 +07:00
Wilfred Hughes a7f688ee82 Put a spacer between LHS and RHS lines printed
Width calculations already consider the spacer, but it was lost in a
refactor.
2021-07-27 22:02:48 +07:00
Wilfred Hughes f24c4954bc Update changelog for previous commit 2021-07-27 22:01:38 +07:00
Wilfred Hughes 7701e38510 Add a basic Go parser 2021-07-25 23:46:33 +07:00
Wilfred Hughes e36a2e8c96 Don't crash on binary files 2021-07-25 12:50:42 +07:00
Wilfred Hughes c8481775e2 Remove --context CLI argument 2021-07-25 12:34:50 +07:00
Wilfred Hughes 04214ef1ef Ignore indentation changes on multiline comments 2021-07-25 12:27:24 +07:00
Wilfred Hughes 3ebbf268fd Improve alignment when LHS and RHS have different numbers of lines 2021-07-24 18:01:12 +07:00
Wilfred Hughes 928584676a Only highlight individual comment words for comments that are similar 2021-07-24 17:01:30 +07:00
Wilfred Hughes 3f8e41d862 Parse @ in elisp 2021-07-24 16:50:53 +07:00
Wilfred Hughes 45af6b4534 Parse < and > as symbols in elisp 2021-07-24 16:45:06 +07:00
Wilfred Hughes 2da5181ffb Prefer replacing comments over novel atoms
This was broken in 4c33f34.
2021-07-24 16:36:36 +07:00
Wilfred Hughes 6d7e155cc6 Remove unused CLI parameter 2021-07-24 16:27:33 +07:00
Wilfred Hughes b81312e88b Roll version 2021-07-22 00:09:13 +07:00
Wilfred Hughes 5d2c14a3f9 Entering a list should set the prev_novel state to the open delimiter 2021-07-22 00:07:09 +07:00
Wilfred Hughes 61446c916a Prefer marking large subtrees as novel rather than largely novel
This solves the "replace function A with completely different function
B" problem, even if they start with the same function keyword.
2021-07-21 01:05:01 +07:00
Wilfred Hughes c48e8e2977 Improve JS and JSON parsing 2021-07-20 01:18:39 +07:00
Wilfred Hughes 7bd8afc439 Improve handling of = and & in lisps 2021-07-20 01:09:29 +07:00
Wilfred Hughes aa28b26f48 Basic support for non-UTF8 source files 2021-07-20 00:46:12 +07:00
Wilfred Hughes 2d9efe15a0 Fix another crash on empty files
Git history with file additions/removals should now work.
2021-07-20 00:22:01 +07:00
Wilfred Hughes 6bec8b7e2c Don't crash on files without an extension 2021-07-20 00:10:58 +07:00
Wilfred Hughes 49ec9d68cc Improve OCaml parsing for := and !
Fixes #20
2021-07-19 23:04:03 +07:00
Wilfred Hughes 6fb01cf7d3 Lex string literals with escaped delimiters 2021-07-18 23:42:36 +07:00
Wilfred Hughes ad81a86419 + is a legal symbol constituent in elisp 2021-07-18 23:40:46 +07:00
Wilfred Hughes 88b0ec2283 & is legal in elisp
It's used for variadic functions.
2021-07-18 23:25:56 +07:00
Wilfred Hughes 75839a1185 Support # and . in lisps
Elisp uses # for sharp-quoting, and some Schemes use # for vector
literals.

. is used for dotted pair notation.
2021-07-18 23:18:55 +07:00
Wilfred Hughes 28d5e51911 Fix crash on multibyte characters
Previously parsing would proceed byte at a time, which would crash if
the source contained multibyte characters. Instead, try all the
regular expression patterns, and jump to the next nearest match.
2021-07-18 22:34:52 +07:00
Wilfred Hughes 5f4ab7c292 Support using difftastic with built-in git commands 2021-07-18 15:01:32 +07:00
Wilfred Hughes abddca0b46 Dijkstra visits nodes in distance order, so we only need predecessors
The first time we see a node, we've found the shortest path to it. Add
it to the predecessors then, and don't visit it again.
2021-07-17 17:53:59 +07:00
Wilfred Hughes 1c9ece441a Improve --help 2021-07-17 14:18:40 +07:00
Wilfred Hughes cdc70dd784 Add ReplaceComment edge and display a word diff between the comments 2021-07-17 13:55:41 +07:00
Wilfred Hughes 00fcd4652a Recognise # and <- as OCaml punctuation
Fixes #18
2021-07-15 23:54:53 +07:00
Wilfred Hughes a2e36cac46 Add more two-character lexems to Rust parser 2021-07-13 23:36:52 +07:00
Wilfred Hughes 4c79267602 Roll version 2021-07-13 23:27:17 +07:00
Wilfred Hughes 8b382e4356 Improved OCaml handling
Fixes #17
Fixes #15
2021-07-13 22:52:13 +07:00
Wilfred Hughes 74c2b8e901 Clarify slider and performance status 2021-07-13 22:31:13 +07:00
Wilfred Hughes fbb2dffd4a Store an ID on Syntax values and use it for vertex equality 2021-07-13 21:49:40 +07:00
Wilfred Hughes b2d9035774 Consider nesting depth when comparing nodes 2021-07-10 17:42:02 +07:00
Wilfred Hughes 5c644baf7c Treat .. as a single atom in Rust 2021-07-10 17:13:07 +07:00
Wilfred Hughes 4cf2a24997 Fixed crash on multibyte characters that include '\n'
Fixes #13
2021-07-09 23:37:04 +07:00
Wilfred Hughes bbc77b8cbc Organise changelog by area 2021-07-09 23:35:53 +07:00
Wilfred Hughes ce35a5cc3a Support $( ... ) and $foo in Rust
Closes #14
2021-07-09 22:54:11 +07:00
Wilfred Hughes 1dc6ab3977 Fix crash when diff touches first line 2021-07-08 01:10:37 +07:00
Wilfred Hughes 094133fe10 Ensure that we display all context lines, even if matched pairs are unordered 2021-07-07 23:45:22 +07:00
Wilfred Hughes 9e821956a5 Roll version 2021-07-07 22:25:03 +07:00
Wilfred Hughes 6f87140703 Don't crash if file is unchanged
Fixes #4
2021-07-07 22:19:46 +07:00
Wilfred Hughes c43e724caf Ensure :: is treated as a single token in Rust 2021-07-07 22:02:20 +07:00
Wilfred Hughes da8a4c1ee1 Line up visible lines and include gaps if necessary 2021-07-07 22:01:19 +07:00
Wilfred Hughes 5463c120f4 Better punctuation parsing for JS and OCaml
Closes #7
2021-07-07 19:53:45 +07:00
Wilfred Hughes ccaca6f6a6 Rust: Consider , as separate punctuation
Closes #8
2021-07-07 19:51:49 +07:00
Wilfred Hughes 483fe8ca51 Ensure we always find the shortest route
Previously we would ignore shorter routes if we'd already found a
route to the node.
2021-07-04 22:38:17 +07:00
Wilfred Hughes 76ef7c510c Teach syntax about Rust lifetimes 2021-07-04 12:59:17 +07:00
Wilfred Hughes 64bfc73a6c Roll version for next release 2021-07-04 11:42:59 +07:00
Wilfred Hughes 9cd63c972d Adding a changelog 2021-07-04 11:40:31 +07:00