-
Notifications
You must be signed in to change notification settings - Fork 399
Fix bug expanding large-diff-gated patches with comments #2007
Conversation
File patches that exceed the large diff threshold are initially collapsed. We were not actually populating the diffRowOffsetIndex for these collapsed patches. When expanding a collapsed patch with comments, we'd try to use the diffRowOffsetIndex which was empty, and throw an error. Co-Authored-By: Vanessa Yuen <vanessayuenn@users.noreply.github.com>
Co-Authored-By: Vanessa Yuen <vanessayuenn@users.noreply.github.com>
Co-Authored-By: Vanessa Yuen <vanessayuenn@users.noreply.github.com>
Codecov Report
@@ Coverage Diff @@
## master #2007 +/- ##
==========================================
- Coverage 92.58% 92.58% -0.01%
==========================================
Files 189 189
Lines 11237 11244 +7
Branches 1633 1634 +1
==========================================
+ Hits 10404 10410 +6
- Misses 833 834 +1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting in this fix so quickly! It looks good 👍
Just left a couple of comments -- one suggestion and one question about a potential edge case. But I think neither of them are necessarily ship-blocking.
lib/models/patch/multi-file-patch.js
Outdated
const diffRowOffsetIndex = this.diffRowOffsetIndices.get(filePatch.getPath()); | ||
// if the patch was initially collapsed, we need to calculate | ||
// the diffRowOffsetIndices to calculate comment position. | ||
if (diffRowOffsetIndex.index.size === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎨minor readability suggestion -- I noticed I had to look at this a couple times, as well as assert.strictEqual(multiFilePatch.diffRowOffsetIndices.get('1.txt').index.size, 0)
in the tests.
Perhaps we could add a method diffRowOffsetIndexUnpopulated
that does this check and reads more declaratively. And we can also use the method to improve readability in our test assertions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm is there an edge case here for symlink and file mode change diffs that would have empty indexes? I guess we'd just unnecessarily call populateDiffRowOffsetIndices
and create a new empty index, which isn't a big deal. It's probably not worth the extra effort to distinguish between empty indexes from large diffs versus symlink or file mode changes, huh?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I'd take readability and simplicity over dealing with symlink and file mode changes here. Creating a new empty index shouldn't impact performance very much.
I'll work on the other changes though, thanks for the suggestion.
Description of the Change
Once upon a time, there was a bug where clicking "expand" on a file patch that exceeded the large diff gate size, that had comments, would throw a stacktrace. Sadness!
@vanessayuenn and I determined that the root cause of this bug was that because large patches are initially collapsed, we were never populating the red and black tree used to keep track of the diff offset indices for comment placement.
Solution was to extract a function to populate the diff offset indices, and then call that function when expanding file patches.
Screenshot/Gif
N/A
Alternate Designs
None considered.
Benefits
Users can now expand large-diff-gated file patches that contain comments without errors and sadness. (Well, I can't guarantee there will be no sadness.)
Possible Drawbacks
Can't think of any drawbacks but if you can, I'm open to discussion.
Applicable Issues
Metrics
N/A
Tests
Wrote unit test to ensure that:
diffOffsetIndices
if it's emptygetBufferRowForDiffPosition
in fact gives us the correct buffer row.Manually testing expanding the file patch on https://github.com/kuychaco/test-repo/pull/7
Documentation
Added one code comment like a champ.
Release Notes
This bug is for a feature that hasn't been released yet so I'm ok leaving it out of the release notes.
User Experience Research (Optional)
N/A