summaryrefslogtreecommitdiff
path: root/src/align.rs
AgeCommit message (Collapse)Author
2023-05-24Clean upDan Davison
2023-04-26Fix some typos (#1379)Alexander Seiler
Signed-off-by: Alexander Seiler <seileralex@gmail.com>
2023-02-28Fix clippy warnings (#1298)nickelc
* Fix clippy warnings - `clippy::uninlined_format_args` * Fix clippy warnings - `clippy::clone_on_copy` - `clippy::explicit_auto_deref` - `clippy::iter_cloned_collect` - `clippy::map_clone` - `clippy::needless_borrow` - `clippy::needless_lifetimes` - `clippy::needless_return` - `clippy::redundant_clone` - `clippy::redundant_field_names` - `clippy::seek_to_start_instead_of_rewind` - `clippy::unnecessary_cast` - `clippy::unused_unit`
2022-11-29Highlighting improvements (#1244)Phillip Wood
* Stop ignoring a passing test edits::tests::test_infer_edits_12 passes so there is no need to ignore it. * Refactor Levenshtein tests Reduce the amount of repetition and specify the Levenshtein distance explicitly in preparation for changing the Levenshtein calculation and adding more tests in a future commit. As there are quite a few inputs to each test use a struct rather than a plain function for the tests as this effectively provides named parameters for the inputs. * Highlight deletions before insertions When a token has moved within a line try to highlight it as a deletion followed by an insertion. Currently -'b ' +' b' is highlighted as -'b[ ]' +'[ ]b' as if the space has moved to the left, instead highlight it as -'[b] ' +' [b]' as if the "b" has moved to the right. As the changes to the tests show this also tends to favor a longer match at the start of the line. * Don't highlight an unchanged trailing space Only unchanged space between changed tokens should be highlighted, if the line ends with an unchanged space then the space should not be highlighted. * Try to group highlighted changes together Sometimes the highlighting of a change is not as clear as it could be. For example the change -printf "%s\n" s y y ... +test_write_lines s y n ... is highlighted as -[printf "%]s[\n"] [s ]y y ... +[test_write_lines ]s y y ... rather than -[printf "%s\n"] s y n ... +[test_write_lines] s y y ... This is because the Levenshtein distance calculation only checks if the current tokens match without considering if the previous tokens matched or not. Adding a small penalty for starting a run of changed tokens forces the changes to be grouped together whenever possible. A knock on effect of adding the penalty is that the cost a substitution needs to be increased relative to the cost of an insertion/deletion otherwise the lowest cost for "ab" -> "ba" is two substitutions rather than an insertion, match and deletion. There are several changes to the tests - the Levenshtein distance is updated to reflect the new calculation in tests::align::* - several new tests are added to tests::align to check the grouping of different combinations of insertions and deletions - tests::edits::test_infer_edits_10 shows an improvement in the highlighting as the unchanged space at the end of the changed tokens is no longer highlighted. This is because it is no longer considered to be deleted by the Levenshtein matching as deleting the space between the deleted words now has a lower cost. - there is a new test in tests::edits using the example in this message. * Stop using substitutions in Levenshtein calculation Now that the lowest cost edit path groups deletions and insertions together there seems to be little point in keeping substitutions. Indeed the lower cost of substitutions compared to a deletion followed by an insertion can adversely affect the highlighting. If the length of the line does not change delta will prefer to use substitutions over deletions and insertions even if it results in unchanged tokens being marked as changed. For example in -[a] a a a a a [b b b] +[c] a a a a a [a c c] unchanged tokens are marked as deleted and inserted. Without substitutions this is highlighted as -a a a a a a [b b b] +[c ]a a a a a a [c c] which highlights the insertion at the beginning of the line and the change at the end of the line more clearly. There is a change to the distance calculation as substitutions only contributed the length of the deletion whereas now the same change will add the length of both the deletion and the insertion. This is addressed by doubling the contribution of unchanged sections so that the denominator equals the sum of the distance contributions of the plus line and minus line.
2022-08-16Fix clippy warnings after rust 1.63 upgrademliszcz
Following fixes are included: * derive_partial_eq_without_eq: Eq trait was added by running `cargo clippy --fix --no-deps`. * get_first: Function was replaced by running `cargo clippy --fix --no-deps`. * unnecessary_to_owned: This check was disabled for ANSIString as to_string call is required to enforce formatting. Otherwise the underlying string was returned directly (probably due to Deref implementation). * type_complexity: Closure type was simplified and Box<> usage was removed.
2021-11-10Remove +/- line prefix instead of substituting a spaceThomas Otto
Simplifies line handling and printing by removing a "magical" 1-offset previously required in various locations. Now explicitly prepend "" in `tokenize()`.
2020-06-26Bugfix: fix highlighting bug (no test coverage)Dan Davison
2020-05-14rustfmtDan Davison
2019-12-02[refactor] change zip to enumerateHerrington Darkholme
2019-08-11Clean upDan Davison
2019-08-08ClippyDan Davison
2019-08-07Compute distance in annotation routineDan Davison
2019-08-07Move run-length encodingDan Davison
2019-08-06Use alignment to annotate line pairDan Davison
2019-08-06Refactor: edits: array of structsDan Davison
2019-08-06Use enum instead of ad-hoc integer codeDan Davison
2019-08-06Update testsDan Davison
- Fix tests - Reproduce bug: short string vs long
2019-08-06Ignore whitespace in tokens when computing distanceDan Davison
2019-08-06Clean up distance-metricsDan Davison
2019-08-06Align tokenized string instead of characters/graphemesDan Davison
Thanks @clnoll
2019-08-06Use Needleman-Wunsch / Wagner-Fischer algorithmDan Davison