Skip to content

Commit 721e951

Browse files
authored
fix(cwspr): update codePercentage metrics threshold from 500 to 50 #4522
Problem: By conducting one week of data collection, we find that multi character text change which has more than 50 characters only account for 2% of total document change, but they somehow contributed to more than 98% of characters in the doc. This is because user rarely copy and paste code into their editor, but when they do, the copy will result in huge number of character increase. This kind of increase is not what we want to capture in the cwspr percentage code written metric. 50 is a good threshold that includes copy of small code snippets and IDE intelliSense accepted code. Solution: Ignore any multi character input more than 50 characters. The userDetails JSON will be removed in the future. We want to monitor it for a few weeks longer.
1 parent b60cdf5 commit 721e951

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "CodeWhisperer: Include copied code in percentage code written metrics"
4+
}

packages/core/src/codewhisperer/tracker/codewhispererCodeCoverageTracker.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,16 +338,17 @@ export class CodeWhispererCodeCoverageTracker {
338338
this._userInputDetails.lt1.count += 1
339339
this._userInputDetails.lt1.total += characterIncrease
340340
}
341-
// also include multi character input within 500 characters (not from CWSPR)
341+
// also include multi character input within 50 characters (not from CWSPR)
342342
else if (
343343
e.contentChanges.length === 1 &&
344344
e.contentChanges[0].text.length > 1 &&
345345
TelemetryHelper.instance.lastSuggestionInDisplay !== e.contentChanges[0].text
346346
) {
347347
const multiCharInputSize = e.contentChanges[0].text.length
348348

349-
// select 500 as the cut-off threshold for counting user input.
350-
if (multiCharInputSize < 500) {
349+
// select 50 as the cut-off threshold for counting user input.
350+
// ignore all white space multi char input, this usually comes from reformat.
351+
if (multiCharInputSize < 50 && e.contentChanges[0].text.trim().length > 0) {
351352
this.addTotalTokens(e.document.fileName, multiCharInputSize)
352353
}
353354

packages/core/src/test/codewhisperer/tracker/codewhispererCodeCoverageTracker.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ describe('codewhispererCodecoverageTracker', function () {
232232
CodeWhispererCodeCoverageTracker.instances.clear()
233233
})
234234

235-
it('Should skip when content change size is more than 500', function () {
235+
it('Should skip when content change size is more than 50', function () {
236236
if (!tracker) {
237237
assert.fail()
238238
}
@@ -251,7 +251,7 @@ describe('codewhispererCodecoverageTracker', function () {
251251
assert.strictEqual(Object.keys(tracker.totalTokens).length, 0)
252252
})
253253

254-
it('Should not skip when content change size is less than 500', function () {
254+
it('Should not skip when content change size is less than 50', function () {
255255
if (!tracker) {
256256
assert.fail()
257257
}
@@ -260,15 +260,15 @@ describe('codewhispererCodecoverageTracker', function () {
260260
document: createMockDocument(),
261261
contentChanges: [
262262
{
263-
range: new vscode.Range(0, 0, 0, 300),
263+
range: new vscode.Range(0, 0, 0, 49),
264264
rangeOffset: 0,
265-
rangeLength: 300,
266-
text: 'def twoSum(nums, target): for '.repeat(10),
265+
rangeLength: 49,
266+
text: 'a = 123'.repeat(7),
267267
},
268268
],
269269
})
270270
assert.strictEqual(Object.keys(tracker.totalTokens).length, 1)
271-
assert.strictEqual(Object.values(tracker.totalTokens)[0], 300)
271+
assert.strictEqual(Object.values(tracker.totalTokens)[0], 49)
272272
})
273273

274274
it('Should skip when CodeWhisperer is editing', function () {

0 commit comments

Comments
 (0)