Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

fix(rome_analyze): prevent the range end search of find_diff_range from crossing the start of the range #2697

Merged
merged 1 commit into from
Jun 10, 2022

Conversation

leops
Copy link
Contributor

@leops leops commented Jun 10, 2022

Summary

In #2694 I implemented a simplified solution (clamping the resulting range) to prevent the end of the diff range from crossing the start of the range when calculating the diff of a token removal operation. Unfortunately this solution isn't entirely correct and can result in mismatches between the two ranges (due to the clamping being applied to the new range independently from the original range)

With this PR I implemented a fix that completely removes the root cause of the issue by preventing the search for the endpoint of the modified range from crossing the start of the range in the first place, eliminating the need for the clamping operation on the resulting index

Fixes #2696

Test Plan

I also fixed the diff_range_remove test case, it turns out I made a mistake when calculating the values the range returned by find_diff_range were supposed to have, which in turn led to implementing an incorrect fix

@leops leops temporarily deployed to aws June 10, 2022 16:31 Inactive
@github-actions
Copy link

@cloudflare-pages
Copy link

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: c85f4cb
Status: ✅  Deploy successful!
Preview URL: https://ce7f1951.tools-8rn.pages.dev
Branch Preview URL: https://fix-find-diff-range-end.tools-8rn.pages.dev

View logs

// reuse the same underlying green node after an edit, so the equality
// check can stop at doing a pointer + length equality without having
// to actually check the content of the string
prev_token.text() == next_token.text()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a dump question. Can't we compare the hash of the tokens?

EDIT: seems not, as we use the TextSize as key for the hash

@ematipico ematipico merged commit 7d3d257 into main Jun 10, 2022
@ematipico ematipico deleted the fix/find-diff-range-end branch June 10, 2022 18:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 diff_print seems still not right
2 participants