@@ -170,10 +170,11 @@ export class InlineCompletionManager implements Disposable {
170170 const onInlineRejection = async ( ) => {
171171 try {
172172 vsCodeState . isCodeWhispererEditing = true
173- if ( this . sessionManager . getActiveSession ( ) === undefined ) {
173+ const session = this . sessionManager . getActiveSession ( )
174+ if ( session === undefined ) {
174175 return
175176 }
176- const requestStartTime = this . sessionManager . getActiveSession ( ) ! . requestStartTime
177+ const requestStartTime = session . requestStartTime
177178 const totalSessionDisplayTime = performance . now ( ) - requestStartTime
178179 await commands . executeCommand ( 'editor.action.inlineSuggest.hide' )
179180 // TODO: also log the seen state for other suggestions in session
@@ -182,9 +183,9 @@ export class InlineCompletionManager implements Disposable {
182183 CodeWhispererConstants . platformLanguageIds ,
183184 this . inlineCompletionProvider
184185 )
185- const sessionId = this . sessionManager . getActiveSession ( ) ? .sessionId
186+ const sessionId = session . sessionId
186187 const itemId = this . sessionManager . getActiveRecommendation ( ) [ 0 ] ?. itemId
187- if ( ! sessionId || ! itemId ) {
188+ if ( ! itemId ) {
188189 return
189190 }
190191 const params : LogInlineCompletionSessionResultsParams = {
@@ -196,6 +197,7 @@ export class InlineCompletionManager implements Disposable {
196197 discarded : false ,
197198 } ,
198199 } ,
200+ firstCompletionDisplayLatency : session . firstCompletionDisplayLatency ,
199201 totalSessionDisplayTime : totalSessionDisplayTime ,
200202 }
201203 this . languageClient . sendNotification ( this . logSessionResultMessageName , params )
@@ -274,12 +276,6 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
274276
275277 // yield event loop to let the document listen catch updates
276278 await sleep ( 1 )
277- // prevent user deletion invoking auto trigger
278- // this is a best effort estimate of deletion
279- if ( this . documentEventListener . isLastEventDeletion ( document . uri . fsPath ) ) {
280- getLogger ( ) . debug ( 'Skip auto trigger when deleting code' )
281- return [ ]
282- }
283279
284280 let logstr = `GenerateCompletion metadata:\\n`
285281 try {
@@ -290,14 +286,16 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
290286 const prevSessionId = prevSession ?. sessionId
291287 const prevItemId = this . sessionManager . getActiveRecommendation ( ) ?. [ 0 ] ?. itemId
292288 const prevStartPosition = prevSession ?. startPosition
293- if ( prevSession ?. triggerOnAcceptance ) {
289+ const editsTriggerOnAcceptance = prevSession ?. triggerOnAcceptance
290+ if ( editsTriggerOnAcceptance ) {
294291 getAllRecommendationsOptions = {
295292 ...getAllRecommendationsOptions ,
296293 editsStreakToken : prevSession ?. editsStreakPartialResultToken ,
297294 }
298295 }
299296 const editor = window . activeTextEditor
300- if ( prevSession && prevSessionId && prevItemId && prevStartPosition ) {
297+ // Skip prefix matching for Edits suggestions that trigger on acceptance.
298+ if ( prevSession && prevSessionId && prevItemId && prevStartPosition && ! editsTriggerOnAcceptance ) {
301299 const prefix = document . getText ( new Range ( prevStartPosition , position ) )
302300 const prevItemMatchingPrefix = [ ]
303301 for ( const item of this . sessionManager . getActiveRecommendation ( ) ) {
@@ -341,6 +339,7 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
341339 discarded : ! prevSession . displayed ,
342340 } ,
343341 } ,
342+ firstCompletionDisplayLatency : prevSession . firstCompletionDisplayLatency ,
344343 totalSessionDisplayTime : performance . now ( ) - prevSession . requestStartTime ,
345344 }
346345 this . languageClient . sendNotification ( this . logSessionResultMessageName , params )
@@ -365,8 +364,8 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
365364 } ,
366365 token ,
367366 isAutoTrigger ,
368- getAllRecommendationsOptions ,
369- this . documentEventListener . getLastDocumentChangeEvent ( document . uri . fsPath ) ?. event
367+ this . documentEventListener ,
368+ getAllRecommendationsOptions
370369 )
371370 // get active item from session for displaying
372371 const items = this . sessionManager . getActiveRecommendation ( )
@@ -399,21 +398,24 @@ ${itemLog}
399398
400399 const cursorPosition = document . validatePosition ( position )
401400
402- if ( position . isAfter ( editor . selection . active ) ) {
403- const params : LogInlineCompletionSessionResultsParams = {
404- sessionId : session . sessionId ,
405- completionSessionResult : {
406- [ itemId ] : {
407- seen : false ,
408- accepted : false ,
409- discarded : true ,
401+ // Completion will not be rendered if users cursor moves to a position which is before the position when the service is invoked
402+ if ( items . length > 0 && ! items [ 0 ] . isInlineEdit ) {
403+ if ( position . isAfter ( editor . selection . active ) ) {
404+ const params : LogInlineCompletionSessionResultsParams = {
405+ sessionId : session . sessionId ,
406+ completionSessionResult : {
407+ [ itemId ] : {
408+ seen : false ,
409+ accepted : false ,
410+ discarded : true ,
411+ } ,
410412 } ,
411- } ,
413+ }
414+ this . languageClient . sendNotification ( this . logSessionResultMessageName , params )
415+ this . sessionManager . clear ( )
416+ logstr += `- cursor moved behind trigger position. Discarding completion suggestion...`
417+ return [ ]
412418 }
413- this . languageClient . sendNotification ( this . logSessionResultMessageName , params )
414- this . sessionManager . clear ( )
415- logstr += `- cursor moved behind trigger position. Discarding suggestion...`
416- return [ ]
417419 }
418420
419421 // delay the suggestion rendeing if user is actively typing
0 commit comments