66import * as vscode from 'vscode'
77import { getLogger } from '../../shared/logger/logger'
88import * as CodeWhispererConstants from '../models/constants'
9- import { vsCodeState } from '../models/model'
9+ import { OnRecommendationAcceptanceEntry , vsCodeState } from '../models/model'
1010import { runtimeLanguageContext } from '../util/runtimeLanguageContext'
1111import { TelemetryHelper } from '../util/telemetryHelper'
1212import { AuthUtil } from '../util/authUtil'
@@ -45,6 +45,8 @@ export class QCodeGenTracker {
4545 return TelemetryHelper . instance . isTelemetryEnabled ( ) && AuthUtil . instance . isConnected ( )
4646 }
4747
48+ // this should be invoked whenever there is a successful Q feature invocation
49+ // for all Q features
4850 public onQFeatureInvoked ( ) {
4951 this . _serviceInvocationCount += 1
5052 }
@@ -128,6 +130,10 @@ export class QCodeGenTracker {
128130 }
129131 }
130132
133+ private countNewLines ( str : string ) {
134+ return str . split ( '\n' ) . length - 1
135+ }
136+
131137 public onTextDocumentChange ( e : vscode . TextDocumentChangeEvent ) {
132138 if (
133139 ! runtimeLanguageContext . isLanguageSupported ( e . document . languageId ) ||
@@ -143,8 +149,42 @@ export class QCodeGenTracker {
143149 return
144150 }
145151 this . _totalNewCodeCharacterCount += contentChange . text . length
146- this . _totalNewCodeLineCount += contentChange . text . split ( '\n' ) . length - 1
152+ this . _totalNewCodeLineCount += this . countNewLines ( contentChange . text )
147153 // start 5 min data reporting once valid user input is detected
148154 this . tryStartTimer ( )
149155 }
156+
157+ // add Q inline completion contributed code to total code written
158+ public onInlineCompletionAcceptance ( acceptanceEntry : OnRecommendationAcceptanceEntry ) {
159+ let typeaheadLength = 0
160+ if ( acceptanceEntry . editor ) {
161+ typeaheadLength = acceptanceEntry . editor . document . getText ( acceptanceEntry . range ) . length
162+ }
163+ const documentChangeLength = acceptanceEntry . recommendation . length - typeaheadLength
164+ // if the inline completion is less than 50 characters, it will be auto captured by onTextDocumentChange
165+ // notice that the document change event of such acceptance do not include typeahead
166+ if ( documentChangeLength <= QCodeGenTracker . copySnippetThreshold ) {
167+ return
168+ }
169+ this . _totalNewCodeCharacterCount += acceptanceEntry . recommendation . length
170+ this . _totalNewCodeLineCount += this . countNewLines ( acceptanceEntry . recommendation )
171+ }
172+
173+ // add Q chat insert to cursor code to total code written
174+ public onQChatInsertion ( ) { }
175+
176+ // add Q inline chat acceptance to total code written
177+ public onInlineChat ( ) { }
178+
179+ // add Q inline chat acceptance to total code written
180+ public onTransformAcceptance ( ) { }
181+
182+ // add Q feature dev acceptance to total code written
183+ public onFeatureDevAcceptance ( ) { }
184+
185+ // add Q UTG acceptance to total code written
186+ public onUtgAcceptance ( ) { }
187+
188+ // add Q UTG acceptance to total code written
189+ public onDocAcceptance ( ) { }
150190}
0 commit comments