@@ -65,6 +65,7 @@ export class CodeWhispererCodeCoverageTracker {
65
65
}
66
66
// generate accepted recommendation token and stored in collection
67
67
this . addAcceptedTokens ( filename , { range : range , text : text , accepted : text . length } )
68
+ this . addTotalTokens ( filename , text . length )
68
69
}
69
70
70
71
public incrementServiceInvocationCount ( ) {
@@ -85,6 +86,8 @@ export class CodeWhispererCodeCoverageTracker {
85
86
}
86
87
}
87
88
89
+ // TODO: Improve the range tracking of the accepted recommendation
90
+ // TODO: use the editor of the filename, not the current editor
88
91
public updateAcceptedTokensCount ( editor : vscode . TextEditor ) {
89
92
const filename = editor . document . fileName
90
93
if ( filename in this . _acceptedTokens ) {
@@ -112,17 +115,25 @@ export class CodeWhispererCodeCoverageTracker {
112
115
if ( vscode . window . activeTextEditor ) {
113
116
this . updateAcceptedTokensCount ( vscode . window . activeTextEditor )
114
117
}
118
+ // the accepted characters without counting user modification
115
119
let acceptedTokens = 0
120
+ // the accepted characters after calculating user modificaiton
121
+ let unmodifiedAcceptedTokens = 0
116
122
for ( const filename in this . _acceptedTokens ) {
117
123
this . _acceptedTokens [ filename ] . forEach ( v => {
118
124
if ( filename in this . _totalTokens && this . _totalTokens [ filename ] >= v . accepted ) {
119
- acceptedTokens += v . accepted
125
+ unmodifiedAcceptedTokens += v . accepted
126
+ acceptedTokens += v . text . length
120
127
}
121
128
} )
122
129
}
123
130
const percentCount = ( ( acceptedTokens / totalTokens ) * 100 ) . toFixed ( 2 )
124
131
const percentage = Math . round ( parseInt ( percentCount ) )
125
132
const selectedCustomization = getSelectedCustomization ( )
133
+ if ( this . _serviceInvocationCount <= 0 ) {
134
+ getLogger ( ) . info ( `Skip emiting code contribution metric` )
135
+ return
136
+ }
126
137
telemetry . codewhisperer_codePercentage . emit ( {
127
138
codewhispererTotalTokens : totalTokens ,
128
139
codewhispererLanguage : this . _language ,
@@ -142,6 +153,7 @@ export class CodeWhispererCodeCoverageTracker {
142
153
languageName : runtimeLanguageContext . toRuntimeLanguage ( this . _language ) ,
143
154
} ,
144
155
acceptedCharacterCount : acceptedTokens ,
156
+ unmodifiedAcceptedCharacterCount : unmodifiedAcceptedTokens ,
145
157
totalCharacterCount : totalTokens ,
146
158
timestamp : new Date ( Date . now ( ) ) ,
147
159
} ,
@@ -228,13 +240,13 @@ export class CodeWhispererCodeCoverageTracker {
228
240
229
241
public countTotalTokens ( e : vscode . TextDocumentChangeEvent ) {
230
242
// 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) .
232
244
// Also ignore deletion events due to a known issue of tracking deleted CodeWhiperer tokens.
233
245
if (
234
246
! runtimeLanguageContext . isLanguageSupported ( e . document . languageId ) ||
235
247
vsCodeState . isCodeWhispererEditing ||
236
248
e . contentChanges . length !== 1 ||
237
- e . contentChanges [ 0 ] . text . length === 0
249
+ e . contentChanges [ 0 ] . text . length !== 1
238
250
) {
239
251
return
240
252
}
0 commit comments