-
Notifications
You must be signed in to change notification settings - Fork 93
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
Missing context regions for single-line #2616
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7bd9cb8
Add rolling has optional data enum value. Remove SarifLogger tool par…
michaelcfanning 9346d42
Remove unnecessary tool argument from all log construction.
michaelcfanning e596d39
Formatting updates.
michaelcfanning 0edd2d4
Fine-tune extensions serialization.
michaelcfanning d4efb0d
Don't serialize empty guid values.
michaelcfanning fe3d138
Add hash computation helpers.
michaelcfanning bae5a37
Update release notes.
michaelcfanning 4369a20
Fix compute hash function callback logic.
michaelcfanning fdb2545
Formatting changes.
michaelcfanning f470849
Fix condition where context regions are required for single-line file…
michaelcfanning 0926536
Merge remote-tracking branch 'origin' into missing-context-regions
michaelcfanning 09a417c
All tests pass.
michaelcfanning 520eb13
Update test comment.
michaelcfanning c70851b
CodeQL advice taken.
michaelcfanning 44f8e58
Fix CodeQL alert.
michaelcfanning 2d48491
Restore test and correct comment.
michaelcfanning File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,6 +142,9 @@ private Region PopulateTextRegionProperties(NewLineIndex lineIndex, Region input | |
return region; | ||
} | ||
|
||
internal const int BIGSNIPPETLENGTH = 512; | ||
internal const int SMALLSNIPPETLENGTH = 128; | ||
|
||
public Region ConstructMultilineContextSnippet(Region inputRegion, Uri uri, string fileText = null) | ||
{ | ||
if (inputRegion?.IsBinaryRegion != false) | ||
|
@@ -156,11 +159,10 @@ public Region ConstructMultilineContextSnippet(Region inputRegion, Uri uri, stri | |
return null; | ||
} | ||
|
||
const int bigSnippetLength = 512; | ||
const int smallSnippetLength = 128; | ||
fileText ??= newLineIndex.Text; | ||
|
||
// Generating full inputRegion to prevent issues. | ||
Region originalRegion = this.PopulateTextRegionProperties(inputRegion, uri, populateSnippet: true); | ||
Region originalRegion = this.PopulateTextRegionProperties(inputRegion, uri, populateSnippet: true, fileText); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
int maxLineNumber = newLineIndex.MaximumLineNumber; | ||
|
||
|
@@ -171,10 +173,10 @@ public Region ConstructMultilineContextSnippet(Region inputRegion, Uri uri, stri | |
}; | ||
|
||
// Generating multilineRegion with one line before and after. | ||
Region multilineContextSnippet = this.PopulateTextRegionProperties(region, uri, populateSnippet: true); | ||
Region multilineContextSnippet = this.PopulateTextRegionProperties(region, uri, populateSnippet: true, fileText); | ||
|
||
if (originalRegion.CharLength <= multilineContextSnippet.CharLength && | ||
multilineContextSnippet.CharLength <= bigSnippetLength) | ||
multilineContextSnippet.CharLength <= BIGSNIPPETLENGTH) | ||
{ | ||
return multilineContextSnippet; | ||
} | ||
|
@@ -184,17 +186,15 @@ public Region ConstructMultilineContextSnippet(Region inputRegion, Uri uri, stri | |
region.EndColumn = 0; | ||
region.StartLine = 0; | ||
region.EndLine = 0; | ||
region.CharOffset = originalRegion.CharOffset < smallSnippetLength | ||
? 0 | ||
: originalRegion.CharOffset - smallSnippetLength; | ||
region.CharOffset = Math.Max(0, originalRegion.CharOffset - SMALLSNIPPETLENGTH); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
region.CharLength = originalRegion.CharLength + region.CharOffset + smallSnippetLength < newLineIndex.Text.Length | ||
? originalRegion.CharLength + smallSnippetLength + Math.Abs(region.CharOffset - originalRegion.CharOffset) | ||
: newLineIndex.Text.Length - region.CharOffset; | ||
region.CharLength = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
Math.Min(originalRegion.CharLength + region.CharOffset + SMALLSNIPPETLENGTH, | ||
fileText.Length - region.CharOffset); | ||
|
||
// Generating multineRegion with 128 characters to the left and right from the | ||
// Generating multiline region with 128 characters to the left and right from the | ||
// originalRegion if possible. | ||
multilineContextSnippet = this.PopulateTextRegionProperties(region, uri, populateSnippet: true); | ||
multilineContextSnippet = this.PopulateTextRegionProperties(region, uri, populateSnippet: true, fileText); | ||
|
||
// We can't generate a contextRegion which is smaller than the original region. | ||
Debug.Assert(originalRegion.CharLength <= multilineContextSnippet.CharLength); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
Note that I've lifted out these magic values to make them more explicit in test use, and to allow product changes to flow more naturally to test validation.
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.
do we prefer put at the top of the file with other definitions
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.
Yes, will do this in a follow-on change, thanks for the review!!