diff options
author | Phillip Wood <phillip.wood@dunelm.org.uk> | 2024-03-17 14:17:49 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-17 10:17:49 -0400 |
commit | 4b80dfb04c4a6e2dc841408345a2f72d441cf161 (patch) | |
tree | 1a6f17430741ada247056f3a3cf83b9723afa991 | |
parent | 1ea5ee87a54b3b8d2f4505d2abc34a37c7bc6de5 (diff) |
Stop highlighting unchanged whitespace (#1659)
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
-rw-r--r-- | src/edits.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/edits.rs b/src/edits.rs index b6e1ad9f..30d29958 100644 --- a/src/edits.rs +++ b/src/edits.rs @@ -256,7 +256,7 @@ where if let Some(non_whitespace) = get_contents_before_trailing_whitespace(plus_section) { annotated_plus_line.push((op, non_whitespace)); - annotated_plus_line.push((plus_op_prev, &plus_section[non_whitespace.len()..])); + annotated_plus_line.push((op, &plus_section[non_whitespace.len()..])); } else { annotated_plus_line.push((op, plus_section)); } @@ -832,7 +832,7 @@ mod tests { (Insertion, " "), (Insertion, "y"), (PlusNoop, " c"), - (Insertion, " "), + (PlusNoop, " "), (Insertion, "z"), (PlusNoop, " "), ], @@ -885,7 +885,7 @@ mod tests { (PlusNoop, ""), (Insertion, "c "), (PlusNoop, "a a a a a a"), - (Insertion, " "), + (PlusNoop, " "), (Insertion, "c"), (Insertion, " "), (Insertion, "c"), |