6
6
import * as vscode from 'vscode'
7
7
import { getLogger } from '../../shared/logger/logger'
8
8
import * as CodeWhispererConstants from '../models/constants'
9
- import { vsCodeState } from '../models/model'
9
+ import { OnRecommendationAcceptanceEntry , vsCodeState } from '../models/model'
10
10
import { runtimeLanguageContext } from '../util/runtimeLanguageContext'
11
11
import { TelemetryHelper } from '../util/telemetryHelper'
12
12
import { AuthUtil } from '../util/authUtil'
@@ -45,6 +45,8 @@ export class QCodeGenTracker {
45
45
return TelemetryHelper . instance . isTelemetryEnabled ( ) && AuthUtil . instance . isConnected ( )
46
46
}
47
47
48
+ // this should be invoked whenever there is a successful Q feature invocation
49
+ // for all Q features
48
50
public onQFeatureInvoked ( ) {
49
51
this . _serviceInvocationCount += 1
50
52
}
@@ -128,6 +130,10 @@ export class QCodeGenTracker {
128
130
}
129
131
}
130
132
133
+ private countNewLines ( str : string ) {
134
+ return str . split ( '\n' ) . length - 1
135
+ }
136
+
131
137
public onTextDocumentChange ( e : vscode . TextDocumentChangeEvent ) {
132
138
if (
133
139
! runtimeLanguageContext . isLanguageSupported ( e . document . languageId ) ||
@@ -143,8 +149,42 @@ export class QCodeGenTracker {
143
149
return
144
150
}
145
151
this . _totalNewCodeCharacterCount += contentChange . text . length
146
- this . _totalNewCodeLineCount += contentChange . text . split ( '\n' ) . length - 1
152
+ this . _totalNewCodeLineCount += this . countNewLines ( contentChange . text )
147
153
// start 5 min data reporting once valid user input is detected
148
154
this . tryStartTimer ( )
149
155
}
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 ( ) { }
150
190
}
0 commit comments