@@ -22,33 +22,29 @@ export class QCodeGenTracker {
2222 private _totalNewCodeCharacterCount : number
2323 private _totalNewCodeLineCount : number
2424 private _timer ?: NodeJS . Timer
25- private _serviceInvocationCount : number
25+ private _qUsageCount : number
2626
2727 static #instance: QCodeGenTracker
2828 static copySnippetThreshold = 50
2929
3030 private constructor ( ) {
3131 this . _totalNewCodeLineCount = 0
3232 this . _totalNewCodeCharacterCount = 0
33- this . _serviceInvocationCount = 0
33+ this . _qUsageCount = 0
3434 }
3535
3636 public static get instance ( ) {
3737 return ( this . #instance ??= new this ( ) )
3838 }
3939
40- public get serviceInvocationCount ( ) : number {
41- return this . _serviceInvocationCount
42- }
43-
4440 public isActive ( ) : boolean {
4541 return TelemetryHelper . instance . isTelemetryEnabled ( ) && AuthUtil . instance . isConnected ( )
4642 }
4743
4844 // this should be invoked whenever there is a successful Q feature invocation
4945 // for all Q features
5046 public onQFeatureInvoked ( ) {
51- this . _serviceInvocationCount += 1
47+ this . _qUsageCount += 1
5248 }
5349
5450 public emitCodeContribution ( ) {
@@ -98,7 +94,7 @@ export class QCodeGenTracker {
9894 const delay : number = CodeWhispererConstants . defaultCheckPeriodMillis
9995 const diffTime : number = startTime + delay
10096 if ( diffTime <= currentTime ) {
101- if ( this . _serviceInvocationCount <= 0 ) {
97+ if ( this . _qUsageCount <= 0 ) {
10298 getLogger ( ) . debug ( `Skip emiting code contribution metric. There is no active Amazon Q usage. ` )
10399 return
104100 }
@@ -120,7 +116,7 @@ export class QCodeGenTracker {
120116 private resetTracker ( ) {
121117 this . _totalNewCodeLineCount = 0
122118 this . _totalNewCodeCharacterCount = 0
123- this . _serviceInvocationCount = 0
119+ this . _qUsageCount = 0
124120 }
125121
126122 private closeTimer ( ) {
@@ -171,20 +167,29 @@ export class QCodeGenTracker {
171167 }
172168
173169 // 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+ }
175180
176181 // add Q inline chat acceptance to total code written
177- public onInlineChat ( ) { }
182+ public onInlineChatAcceptance ( ) { }
178183
179- // add Q inline chat acceptance to total code written
184+ // TODO: add Q inline chat acceptance to total code written
180185 public onTransformAcceptance ( ) { }
181186
182- // add Q feature dev acceptance to total code written
187+ // TODO: add Q feature dev acceptance to total code written
183188 public onFeatureDevAcceptance ( ) { }
184189
185- // add Q UTG acceptance to total code written
190+ // TODO: add Q UTG acceptance to total code written
186191 public onUtgAcceptance ( ) { }
187192
188- // add Q UTG acceptance to total code written
193+ // TODO: add Q UTG acceptance to total code written
189194 public onDocAcceptance ( ) { }
190195}
0 commit comments