-
Notifications
You must be signed in to change notification settings - Fork 94
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
Changes from 3 commits
b04dfc1
d3886be
fef1246
58cf640
6f9318c
e493b7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,15 +156,42 @@ internal Region ConstructMultilineContextSnippet(Region inputRegion, Uri uri) | |
return null; | ||
} | ||
|
||
const int maxSnippetLength = 512; | ||
const int reasonableSnippetLength = 256; | ||
const int smallSnippetLength = 128; | ||
|
||
// If this is big enough, we don't need to create a new snippet. | ||
if (inputRegion.CharLength >= reasonableSnippetLength) | ||
{ | ||
return null; | ||
} | ||
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. 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 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; | ||
|
||
// Currently, we just grab a single line before and after the region start | ||
// and end lines, respectively. In the future, we could make this configurable. | ||
var region = new Region() | ||
var region = new Region | ||
{ | ||
StartLine = inputRegion.StartLine == 1 ? 1 : inputRegion.StartLine - 1, | ||
EndLine = inputRegion.EndLine == maxLineNumber ? maxLineNumber : inputRegion.EndLine + 1 | ||
}; | ||
|
||
Region multilineContextSnippet = this.PopulateTextRegionProperties(region, uri, populateSnippet: true); | ||
|
||
// If the new snippet is big enough, we will use. Otherwise, we will | ||
// generate a new snippet | ||
if (multilineContextSnippet.CharLength <= maxSnippetLength) | ||
{ | ||
return multilineContextSnippet; | ||
} | ||
|
||
// We are going to grab 128 characters from left and from right if possible. | ||
region.CharOffset = inputRegion.CharOffset < smallSnippetLength | ||
? 0 | ||
: inputRegion.CharOffset - smallSnippetLength; | ||
|
||
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); | ||
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.
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 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. Added the debug.Assert to verify if the new length >= the original In reply to: 578572270 [](ancestors = 578572270) |
||
} | ||
|
||
|
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.
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.
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.
Ok, so, we will just check this value if charOffset != -1.
In reply to: 578571743 [](ancestors = 578571743)
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.
Wait, this isn't right, is it? If CharOffset == -1, this method can't function, can it?
In reply to: 578583524 [](ancestors = 578583524,578571743)
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.
if == -1, then, ur region is using startline / startcolumn, with that, the populateTextRegion handle both cases.
In reply to: 578586111 [](ancestors = 578586111,578583524,578571743)