Skip to content
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

Improving multiline context snippet #2288

Merged
merged 6 commits into from
Feb 20, 2021

Conversation

eddynaka
Copy link
Collaborator

Change

  • this will improve contextSnippet when we have only one line containing everything

if (inputRegion.Snippet?.Text.Length >= reasonableSnippetLength)
{
return null;
}
Copy link
Member

@michaelcfanning michaelcfanning Feb 18, 2021

Choose a reason for hiding this comment

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

shouldn't we actually be checking the region size, not the snippet size? basically, if a region exceeds a certain size, no context region is required. so for this case, the region should have the snippet. your code will permit the following case:

region is 10k in size but has no snippet
we then create a context region + snippet which is smaller than the region! this breaks the SARIF spec. :) #Resolved

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed to the charLength.


In reply to: 578048420 [](ancestors = 578048420)

const int smallSnippetLength = 128;

// If this is big enough, we don't need to create a new snippet.
if (inputRegion.CharLength >= reasonableSnippetLength)
Copy link
Member

@michaelcfanning michaelcfanning Feb 18, 2021

Choose a reason for hiding this comment

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

inputRegion.CharLength [](start = 16, length = 22)

Can we please put a check in place that ensures the region has populated char length and offset properly? Go check the spec on this type, there's a sentinel value/property default that you can use to verify.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, so, we will just check this value if charOffset != -1.


In reply to: 578571743 [](ancestors = 578571743)

Copy link
Member

Choose a reason for hiding this comment

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

Wait, this isn't right, is it? If CharOffset == -1, this method can't function, can it?


In reply to: 578583524 [](ancestors = 578583524,578571743)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if == -1, then, ur region is using startline / startcolumn, with that, the populateTextRegion handle both cases.


In reply to: 578586111 [](ancestors = 578586111,578583524,578571743)

region.CharLength = inputRegion.CharLength + inputRegion.CharOffset + smallSnippetLength < newLineIndex.Text.Length
? inputRegion.CharLength + inputRegion.CharOffset + smallSnippetLength
: newLineIndex.Text.Length - region.CharOffset;

return this.PopulateTextRegionProperties(region, uri, populateSnippet: true);
Copy link
Member

@michaelcfanning michaelcfanning Feb 18, 2021

Choose a reason for hiding this comment

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

return [](start = 12, length = 6)

the end of this method could be a good place to introduce a debug assert that verifies we have limited the size of the region that we return. #Resolved

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added the debug.Assert to verify if the new length >= the original


In reply to: 578572270 [](ancestors = 578572270)

Copy link
Member

@michaelcfanning michaelcfanning left a comment

Choose a reason for hiding this comment

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

:shipit:

@eddynaka eddynaka marked this pull request as ready for review February 20, 2021 20:46
@eddynaka eddynaka merged commit fa29013 into main Feb 20, 2021
@eddynaka eddynaka deleted the users/ednakamu/multiline-region-snippet branch February 20, 2021 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants