fix: Use correct line num with trimmed suggestions #321
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I came across rust-lang/rust-clippy#15883, which reported incorrect line numbers for a multi-line suggestion. I realized the incorrect line numbers were coming from
rustc
, which made me realize thatannotate-snippets
also had this problem.The root cause of the problems comes from the process of trimming
Patch
's replacement to be a substring of the original. During this process, the span also gets adjusted to match the trimmed replacement. We later use this span to get theline_start
when rendering the suggestion. This is where the bug happens: if the adjusted span'sline_start
does not match the original span'sline_start
, we would show incorrect line numbers.To fix this, I made it so we track both the original span and trimmed span for
Patch
s, and use the original span forline_start
.