Skip to content

Commit ad0e018

Browse files
committed
update
1 parent dd72f01 commit ad0e018

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

packages/amazonq/src/inlineChat/controller/inlineChatController.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { computeDecorations } from '../decorations/computeDecorations'
1313
import { CodelensProvider } from '../codeLenses/codeLenseProvider'
1414
import { PromptMessage, ReferenceLogController } from 'aws-core-vscode/codewhispererChat'
1515
import { CodeWhispererSettings } from 'aws-core-vscode/codewhisperer'
16+
import { QCodeGenTracker } from 'aws-core-vscode/codewhisperer'
1617
import {
1718
codicon,
1819
getIcon,
@@ -68,6 +69,7 @@ export class InlineChatController {
6869
},
6970
this.task
7071
)
72+
QCodeGenTracker.instance.onInlineChatAcceptance()
7173
}
7274
const deletions = task.diff.filter((diff) => diff.type === 'deletion')
7375
await editor.edit(

packages/core/src/codewhisperer/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,4 @@ export * as CodeWhispererConstants from '../codewhisperer/models/constants'
101101
export { getSelectedCustomization } from './util/customizationUtil'
102102
export { Container } from './service/serviceContainer'
103103
export * from './util/gitUtil'
104+
export { QCodeGenTracker } from './tracker/qCodeGenTracker'

packages/core/src/codewhisperer/tracker/qCodeGenTracker.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

packages/core/src/codewhispererChat/controllers/chat/telemetryHelper.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { supportedLanguagesList } from '../chat/chatRequest/converter'
3838
import { AuthUtil } from '../../../codewhisperer/util/authUtil'
3939
import { getSelectedCustomization } from '../../../codewhisperer/util/customizationUtil'
4040
import { undefinedIfEmpty } from '../../../shared'
41+
import { QCodeGenTracker } from '../../../codewhisperer/tracker/qCodeGenTracker'
4142

4243
export function logSendTelemetryEventFailure(error: any) {
4344
let requestId: string | undefined
@@ -321,7 +322,10 @@ export class CWCTelemetryHelper {
321322
return
322323
}
323324
telemetry.amazonq_interactWithMessage.emit(event)
324-
325+
QCodeGenTracker.instance.onQChatInsertion(
326+
event.cwsprChatAcceptedCharactersLength,
327+
event.cwsprChatAcceptedNumberOfLines
328+
)
325329
codeWhispererClient
326330
.sendTelemetryEvent({
327331
telemetryEvent: {

0 commit comments

Comments
 (0)