@@ -22,33 +22,29 @@ export class QCodeGenTracker {
22
22
private _totalNewCodeCharacterCount : number
23
23
private _totalNewCodeLineCount : number
24
24
private _timer ?: NodeJS . Timer
25
- private _serviceInvocationCount : number
25
+ private _qUsageCount : number
26
26
27
27
static #instance: QCodeGenTracker
28
28
static copySnippetThreshold = 50
29
29
30
30
private constructor ( ) {
31
31
this . _totalNewCodeLineCount = 0
32
32
this . _totalNewCodeCharacterCount = 0
33
- this . _serviceInvocationCount = 0
33
+ this . _qUsageCount = 0
34
34
}
35
35
36
36
public static get instance ( ) {
37
37
return ( this . #instance ??= new this ( ) )
38
38
}
39
39
40
- public get serviceInvocationCount ( ) : number {
41
- return this . _serviceInvocationCount
42
- }
43
-
44
40
public isActive ( ) : boolean {
45
41
return TelemetryHelper . instance . isTelemetryEnabled ( ) && AuthUtil . instance . isConnected ( )
46
42
}
47
43
48
44
// this should be invoked whenever there is a successful Q feature invocation
49
45
// for all Q features
50
46
public onQFeatureInvoked ( ) {
51
- this . _serviceInvocationCount += 1
47
+ this . _qUsageCount += 1
52
48
}
53
49
54
50
public emitCodeContribution ( ) {
@@ -98,7 +94,7 @@ export class QCodeGenTracker {
98
94
const delay : number = CodeWhispererConstants . defaultCheckPeriodMillis
99
95
const diffTime : number = startTime + delay
100
96
if ( diffTime <= currentTime ) {
101
- if ( this . _serviceInvocationCount <= 0 ) {
97
+ if ( this . _qUsageCount <= 0 ) {
102
98
getLogger ( ) . debug ( `Skip emiting code contribution metric. There is no active Amazon Q usage. ` )
103
99
return
104
100
}
@@ -120,7 +116,7 @@ export class QCodeGenTracker {
120
116
private resetTracker ( ) {
121
117
this . _totalNewCodeLineCount = 0
122
118
this . _totalNewCodeCharacterCount = 0
123
- this . _serviceInvocationCount = 0
119
+ this . _qUsageCount = 0
124
120
}
125
121
126
122
private closeTimer ( ) {
@@ -171,20 +167,29 @@ export class QCodeGenTracker {
171
167
}
172
168
173
169
// add Q chat insert to cursor code to total code written
174
- public onQChatInsertion ( ) { }
170
+ public onQChatInsertion ( acceptedCharacterCount ?: number , acceptedLineCount ?: number ) {
171
+ if ( acceptedCharacterCount && acceptedLineCount ) {
172
+ // if the chat inserted code is less than 50 characters, it will be auto captured by onTextDocumentChange
173
+ if ( acceptedCharacterCount <= QCodeGenTracker . copySnippetThreshold ) {
174
+ return
175
+ }
176
+ this . _totalNewCodeCharacterCount += acceptedCharacterCount
177
+ this . _totalNewCodeLineCount += acceptedLineCount
178
+ }
179
+ }
175
180
176
181
// add Q inline chat acceptance to total code written
177
- public onInlineChat ( ) { }
182
+ public onInlineChatAcceptance ( ) { }
178
183
179
- // add Q inline chat acceptance to total code written
184
+ // TODO: add Q inline chat acceptance to total code written
180
185
public onTransformAcceptance ( ) { }
181
186
182
- // add Q feature dev acceptance to total code written
187
+ // TODO: add Q feature dev acceptance to total code written
183
188
public onFeatureDevAcceptance ( ) { }
184
189
185
- // add Q UTG acceptance to total code written
190
+ // TODO: add Q UTG acceptance to total code written
186
191
public onUtgAcceptance ( ) { }
187
192
188
- // add Q UTG acceptance to total code written
193
+ // TODO: add Q UTG acceptance to total code written
189
194
public onDocAcceptance ( ) { }
190
195
}
0 commit comments