@@ -208,10 +208,41 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
208208 return [ ]
209209 }
210210
211- // report suggestion state for previous suggestions if they exist
212- const prevSessionId = this . sessionManager . getActiveSession ( ) ?. sessionId
211+ // handling previous session
212+ const prevSession = this . sessionManager . getActiveSession ( )
213+ const prevSessionId = prevSession ?. sessionId
213214 const prevItemId = this . sessionManager . getActiveRecommendation ( ) ?. [ 0 ] ?. itemId
214- if ( prevSessionId && prevItemId ) {
215+ const prevStartPosition = prevSession ?. startPosition
216+ const editor = window . activeTextEditor
217+ if ( prevSession && prevSessionId && prevItemId && prevStartPosition ) {
218+ const prefix = document . getText ( new Range ( prevStartPosition , position ) )
219+ const prevItemMatchingPrefix = [ ]
220+ for ( const item of this . sessionManager . getActiveRecommendation ( ) ) {
221+ const text = typeof item . insertText === 'string' ? item . insertText : item . insertText . value
222+ if ( text . startsWith ( prefix ) && position . isAfterOrEqual ( prevStartPosition ) ) {
223+ item . command = {
224+ command : 'aws.amazonq.acceptInline' ,
225+ title : 'On acceptance' ,
226+ arguments : [
227+ prevSessionId ,
228+ item ,
229+ editor ,
230+ prevSession ?. requestStartTime ,
231+ position . line ,
232+ prevSession ?. firstCompletionDisplayLatency ,
233+ ] ,
234+ }
235+ item . range = new Range ( prevStartPosition , position )
236+ prevItemMatchingPrefix . push ( item as InlineCompletionItem )
237+ }
238+ }
239+ // re-use previous suggestions as long as new typed prefix matches
240+ if ( prevItemMatchingPrefix . length > 0 ) {
241+ getLogger ( ) . debug ( `Re-using suggestions that match user typed characters` )
242+ return prevItemMatchingPrefix
243+ }
244+ getLogger ( ) . debug ( `Auto rejecting previous suggestion in session` )
245+ // if no such suggestions, report the previous suggestion as Reject
215246 const params : LogInlineCompletionSessionResultsParams = {
216247 sessionId : prevSessionId ,
217248 completionSessionResult : {
@@ -242,7 +273,6 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
242273 const items = this . sessionManager . getActiveRecommendation ( )
243274 const itemId = this . sessionManager . getActiveRecommendation ( ) ?. [ 0 ] ?. itemId
244275 const session = this . sessionManager . getActiveSession ( )
245- const editor = window . activeTextEditor
246276
247277 // Show message to user when manual invoke fails to produce results.
248278 if ( items . length === 0 && context . triggerKind === InlineCompletionTriggerKind . Invoke ) {
0 commit comments