@@ -14,7 +14,7 @@ import path from 'path'
1414import { imageVerticalOffset } from './svgGenerator'
1515import { EditSuggestionState } from '../editSuggestionState'
1616import type { AmazonQInlineCompletionItemProvider } from '../completion'
17- import { vsCodeState } from 'aws-core-vscode/codewhisperer'
17+ import { vsCodeState , InlineCompletionLoggingReason } from 'aws-core-vscode/codewhisperer'
1818
1919const autoRejectEditCursorDistance = 25
2020const 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 } ,
0 commit comments