Skip to content

Commit 908bd80

Browse files
committed
fix(amazonq): add reject reason to nep telemetry
1 parent e1abbe6 commit 908bd80

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

packages/amazonq/src/app/inline/EditRendering/displayImage.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import path from 'path'
1414
import { imageVerticalOffset } from './svgGenerator'
1515
import { EditSuggestionState } from '../editSuggestionState'
1616
import type { AmazonQInlineCompletionItemProvider } from '../completion'
17-
import { vsCodeState } from 'aws-core-vscode/codewhisperer'
17+
import { vsCodeState, InlineCompletionLoggingReason } from 'aws-core-vscode/codewhisperer'
1818

1919
const autoRejectEditCursorDistance = 25
2020
const autoDiscardEditCursorDistance = 10
@@ -25,7 +25,7 @@ export class EditDecorationManager {
2525
private currentImageDecoration: vscode.DecorationOptions | undefined
2626
private currentRemovedCodeDecorations: vscode.DecorationOptions[] = []
2727
private acceptHandler: (() => void) | undefined
28-
private rejectHandler: ((isDiscard: boolean) => void) | undefined
28+
private rejectHandler: ((isDiscard: boolean, reason?: InlineCompletionLoggingReason) => void) | undefined
2929

3030
constructor() {
3131
this.registerCommandHandlers()
@@ -132,7 +132,7 @@ export class EditDecorationManager {
132132
svgImage: vscode.Uri,
133133
startLine: number,
134134
onAccept: () => Promise<void>,
135-
onReject: (isDiscard: boolean) => Promise<void>,
135+
onReject: (isDiscard: boolean, reason?: InlineCompletionLoggingReason) => Promise<void>,
136136
originalCode: string,
137137
newCode: string,
138138
originalCodeHighlightRanges: Array<{ line: number; start: number; end: number }>
@@ -187,11 +187,14 @@ export class EditDecorationManager {
187187
})
188188

189189
// Register Esc key handler for rejecting suggestion
190-
vscode.commands.registerCommand('aws.amazonq.inline.rejectEdit', (isDiscard: boolean = false) => {
191-
if (this.rejectHandler) {
192-
this.rejectHandler(isDiscard)
190+
vscode.commands.registerCommand(
191+
'aws.amazonq.inline.rejectEdit',
192+
(isDiscard: boolean = false, reason?: InlineCompletionLoggingReason) => {
193+
if (this.rejectHandler) {
194+
this.rejectHandler(isDiscard, reason)
195+
}
193196
}
194-
})
197+
)
195198
}
196199

197200
/**
@@ -376,7 +379,11 @@ export async function displaySvgDecoration(
376379
const isPatchValid = applyPatch(e.document.getText(), item.insertText as string)
377380
if (!isPatchValid) {
378381
logSuggestionFailure('REJECT', 'Invalid patch due to document change', item.insertText as string)
379-
void vscode.commands.executeCommand('aws.amazonq.inline.rejectEdit')
382+
void vscode.commands.executeCommand(
383+
'aws.amazonq.inline.rejectEdit',
384+
false,
385+
InlineCompletionLoggingReason.IMPLICIT_REJECT
386+
)
380387
}
381388
})
382389
const cursorChangeListener = vscode.window.onDidChangeTextEditorSelection((e) => {
@@ -394,7 +401,11 @@ export async function displaySvgDecoration(
394401
`cursor position move too far away off ${autoRejectEditCursorDistance} lines`,
395402
item.insertText as string
396403
)
397-
void vscode.commands.executeCommand('aws.amazonq.inline.rejectEdit')
404+
void vscode.commands.executeCommand(
405+
'aws.amazonq.inline.rejectEdit',
406+
false,
407+
InlineCompletionLoggingReason.IMPLICIT_REJECT
408+
)
398409
}
399410
})
400411
await decorationManager.displayEditSuggestion(
@@ -436,7 +447,7 @@ export async function displaySvgDecoration(
436447
void languageClient.sendNotification('aws/logInlineCompletionSessionResults', params)
437448
session.triggerOnAcceptance = true
438449
},
439-
async (isDiscard: boolean) => {
450+
async (isDiscard: boolean, reason?: InlineCompletionLoggingReason) => {
440451
// Handle reject
441452
if (isDiscard) {
442453
getLogger().info('Edit suggestion discarded')
@@ -465,6 +476,7 @@ export async function displaySvgDecoration(
465476
totalSessionDisplayTime: Date.now() - session.requestStartTime,
466477
firstCompletionDisplayLatency: session.firstCompletionDisplayLatency,
467478
isInlineEdit: true,
479+
...(reason && !isDiscard ? { reason } : {}),
468480
}
469481
void languageClient.sendNotification('aws/logInlineCompletionSessionResults', params)
470482
},

packages/amazonq/test/unit/app/inline/EditRendering/displayImage.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as sinon from 'sinon'
88
import assert from 'assert'
99
import { EditDecorationManager, displaySvgDecoration } from '../../../../../src/app/inline/EditRendering/displayImage'
1010
import { EditSuggestionState } from '../../../../../src/app/inline/editSuggestionState'
11+
import { InlineCompletionLoggingReason } from 'aws-core-vscode/codewhisperer'
1112

1213
// Shared helper function to create common stubs
1314
function createCommonStubs(sandbox: sinon.SinonSandbox) {
@@ -371,7 +372,12 @@ describe('displaySvgDecoration cursor distance auto-reject', function () {
371372

372373
selectionChangeListener(createSelectionChangeEvent(startLine + 26))
373374

374-
sinon.assert.calledOnceWithExactly(commandsStub, 'aws.amazonq.inline.rejectEdit')
375+
sinon.assert.calledOnceWithExactly(
376+
commandsStub,
377+
'aws.amazonq.inline.rejectEdit',
378+
false,
379+
InlineCompletionLoggingReason.IMPLICIT_REJECT
380+
)
375381
})
376382

377383
it('should reject when cursor moves more than 25 lines before the edit', async function () {
@@ -384,7 +390,12 @@ describe('displaySvgDecoration cursor distance auto-reject', function () {
384390

385391
selectionChangeListener(createSelectionChangeEvent(startLine - 26))
386392

387-
sinon.assert.calledOnceWithExactly(commandsStub, 'aws.amazonq.inline.rejectEdit')
393+
sinon.assert.calledOnceWithExactly(
394+
commandsStub,
395+
'aws.amazonq.inline.rejectEdit',
396+
false,
397+
InlineCompletionLoggingReason.IMPLICIT_REJECT
398+
)
388399
})
389400

390401
it('should not reject when edit is near beginning of file and cursor cannot move far enough', async function () {

0 commit comments

Comments
 (0)