-
Notifications
You must be signed in to change notification settings - Fork 398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regression in highlighting from #1037 #1658
Comments
Here is the patch for reproducing the issue
Unfortunately the markdown parser seems to be trimming the trailing empty line from the diff. |
I managed to narrow it down to a such example:
The specific characters do not matter much, they are mostly there to facilitate detection of the changes in line. Adding such test to #[test]
fn test_infer_edits_1658() {
assert_edits(
vec!["x a x b"],
vec!["x c x d"],
(
vec![vec![
(MinusNoop, "x "),
(Deletion, "a"),
(MinusNoop, " x "),
(Deletion, "b"),
]],
vec![vec![
(PlusNoop, "x"),
(PlusNoop, " "),
(Insertion, "c"),
(PlusNoop, " x"),
(PlusNoop, " "),
(Insertion, "d"),
]],
),
1.0,
);
} Results in (emphasis mine): Not sure why in the plus line the trailing whitespace split into separate tokens, for example I suspect because of that change, there are more tokens in the plus line than in the minus line, and therefore the additional space tokens are highlighted as additions? |
Fix a regression introduced by feec45b (Fix warning highlight for trailing whitespace (dandavison#1037), 2023-05-17) where trailing space at the end of an unchanged token is highlighted if the token follows an insertion. This happens because when the token is split in two to separate trailing whitespace the two halves end up being tagged with different edit operations. This can be seen in the test changes in `test_infer_edits_14` and `test_infer_edits_16` introduced by feec45b which changed the operation from `PlusNoop` to `Insertion` when splitting trailing whitespace from unchanged tokens. Fix this by using the same operation when adding both halves of a split token and correcting the tests. Fixes dandavison#1658
The trailing space is split off so that it can be highlighted as a whitespace error if it comes at the end of the line. I think the tests changes in that commit are buggy, I've got a fix that I will post soon.
The total number of tokens shouldn't matter, the problem is the whitespace token gets added with a different operation to the non-whitespace part by a mistake. |
Well spotted! And thanks for the explanations 😊 |
Fix a regression introduced by feec45b (Fix warning highlight for trailing whitespace (#1037), 2023-05-17) where trailing space at the end of an unchanged token is highlighted if the token follows an insertion. This happens because when the token is split in two to separate trailing whitespace the two halves end up being tagged with different edit operations. This can be seen in the test changes in `test_infer_edits_14` and `test_infer_edits_16` introduced by feec45b which changed the operation from `PlusNoop` to `Insertion` when splitting trailing whitespace from unchanged tokens. Fix this by using the same operation when adding both halves of a split token and correcting the tests. Fixes #1658
Thanks for the investigation @phillipwood and @imbrish -- I've merged @phillipwood's fix. |
I noticed that delta has started to sometimes highlight unchanged whitespace before insertions. This appears to be caused by #1037
With delta built from feec45b^ only the insertion is highlighted
With delta built from feec45b the space before the insertion is highlighted
The text was updated successfully, but these errors were encountered: