Skip to content

Commit b1a1699

Browse files
committed
add new field in CodeCoverage
1 parent 961ff52 commit b1a1699

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/codewhisperer/client/user-service-2.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,8 @@
417417
"programmingLanguage": { "shape": "ProgrammingLanguage" },
418418
"acceptedCharacterCount": { "shape": "PrimitiveInteger" },
419419
"totalCharacterCount": { "shape": "PrimitiveInteger" },
420-
"timestamp": { "shape": "Timestamp" }
420+
"timestamp": { "shape": "Timestamp" },
421+
"unmodifiedAcceptedCharacterCount": { "shape": "PrimitiveInteger" }
421422
}
422423
},
423424
"CodeGenerationId": {

src/codewhisperer/tracker/codewhispererCodeCoverageTracker.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export class CodeWhispererCodeCoverageTracker {
6565
}
6666
// generate accepted recommendation token and stored in collection
6767
this.addAcceptedTokens(filename, { range: range, text: text, accepted: text.length })
68+
this.addTotalTokens(filename, text.length)
6869
}
6970

7071
public incrementServiceInvocationCount() {
@@ -85,6 +86,8 @@ export class CodeWhispererCodeCoverageTracker {
8586
}
8687
}
8788

89+
// TODO: Improve the range tracking of the accepted recommendation
90+
// TODO: use the editor of the filename, not the current editor
8891
public updateAcceptedTokensCount(editor: vscode.TextEditor) {
8992
const filename = editor.document.fileName
9093
if (filename in this._acceptedTokens) {
@@ -112,17 +115,25 @@ export class CodeWhispererCodeCoverageTracker {
112115
if (vscode.window.activeTextEditor) {
113116
this.updateAcceptedTokensCount(vscode.window.activeTextEditor)
114117
}
118+
// the accepted characters without counting user modification
115119
let acceptedTokens = 0
120+
// the accepted characters after calculating user modificaiton
121+
let unmodifiedAcceptedTokens = 0
116122
for (const filename in this._acceptedTokens) {
117123
this._acceptedTokens[filename].forEach(v => {
118124
if (filename in this._totalTokens && this._totalTokens[filename] >= v.accepted) {
119-
acceptedTokens += v.accepted
125+
unmodifiedAcceptedTokens += v.accepted
126+
acceptedTokens += v.text.length
120127
}
121128
})
122129
}
123130
const percentCount = ((acceptedTokens / totalTokens) * 100).toFixed(2)
124131
const percentage = Math.round(parseInt(percentCount))
125132
const selectedCustomization = getSelectedCustomization()
133+
if (this._serviceInvocationCount <= 0) {
134+
getLogger().info(`Skip emiting code contribution metric`)
135+
return
136+
}
126137
telemetry.codewhisperer_codePercentage.emit({
127138
codewhispererTotalTokens: totalTokens,
128139
codewhispererLanguage: this._language,
@@ -142,6 +153,7 @@ export class CodeWhispererCodeCoverageTracker {
142153
languageName: runtimeLanguageContext.toRuntimeLanguage(this._language),
143154
},
144155
acceptedCharacterCount: acceptedTokens,
156+
unmodifiedAcceptedCharacterCount: unmodifiedAcceptedTokens,
145157
totalCharacterCount: totalTokens,
146158
timestamp: new Date(Date.now()),
147159
},
@@ -228,13 +240,13 @@ export class CodeWhispererCodeCoverageTracker {
228240

229241
public countTotalTokens(e: vscode.TextDocumentChangeEvent) {
230242
// ignore no contentChanges. ignore contentChanges from other plugins (formatters)
231-
// only include contentChanges from user action.
243+
// only include contentChanges from user keystroke input(one character input).
232244
// Also ignore deletion events due to a known issue of tracking deleted CodeWhiperer tokens.
233245
if (
234246
!runtimeLanguageContext.isLanguageSupported(e.document.languageId) ||
235247
vsCodeState.isCodeWhispererEditing ||
236248
e.contentChanges.length !== 1 ||
237-
e.contentChanges[0].text.length === 0
249+
e.contentChanges[0].text.length !== 1
238250
) {
239251
return
240252
}

0 commit comments

Comments
 (0)