@@ -10,7 +10,6 @@ import {
1010 DefaultCodeWhispererClient ,
1111 CognitoCredentialsError ,
1212 ListRecommendationsRequest ,
13- GenerateRecommendationsRequest ,
1413} from '../client/codewhisperer'
1514import * as EditorContext from '../util/editorContext'
1615import * as CodeWhispererConstants from '../models/constants'
@@ -93,8 +92,6 @@ export class RecommendationHandler {
9392 private prev : vscode . Disposable
9493 private _timer ?: NodeJS . Timer
9594 documentUri : vscode . Uri | undefined = undefined
96- // private session: CodeWhispererSession
97- // private nextSession: CodeWhispererSession
9895
9996 constructor ( ) {
10097 this . requestId = ''
@@ -104,8 +101,6 @@ export class RecommendationHandler {
104101 this . prev = new vscode . Disposable ( ( ) => { } )
105102 this . next = new vscode . Disposable ( ( ) => { } )
106103 this . reject = new vscode . Disposable ( ( ) => { } )
107- // this.session = CodeWhispererSessionState.instance.getSession()
108- // this.nextSession = CodeWhispererSessionState.instance.getNextSession()
109104 }
110105
111106 static #instance: RecommendationHandler
@@ -178,7 +173,7 @@ export class RecommendationHandler {
178173 let errorCode : string | undefined = undefined
179174 let currentSession = CodeWhispererSessionState . instance . getSession ( )
180175 if ( isNextSession ) {
181- getLogger ( ) . info ( 'pre-fetching next recommendation for model routing' )
176+ getLogger ( ) . debug ( 'pre-fetching next recommendation for model routing' )
182177 currentSession = new CodeWhispererSession ( )
183178 CodeWhispererSessionState . instance . setNextSession ( currentSession )
184179 }
@@ -205,7 +200,6 @@ export class RecommendationHandler {
205200 currentSession . taskType = await this . getTaskTypeFromEditorFileName ( editor . document . fileName )
206201
207202 if ( pagination && ! generate ) {
208- // else {
209203 if ( page === 0 ) {
210204 if ( isNextSession ) {
211205 const session = CodeWhispererSessionState . instance . getSession ( )
@@ -234,7 +228,7 @@ export class RecommendationHandler {
234228 ...currentSession . requestContext . request ,
235229 // Putting nextToken assignment in the end so it overwrites the existing nextToken
236230 nextToken : this . nextToken ,
237- } as ListRecommendationsRequest ,
231+ } ,
238232 supplementalMetadata : currentSession . requestContext . supplementalMetadata ,
239233 }
240234 }
@@ -244,10 +238,7 @@ export class RecommendationHandler {
244238 editor as vscode . TextEditor
245239 )
246240 }
247- const request = generate
248- ? ( currentSession . requestContext . request as GenerateRecommendationsRequest )
249- : ( currentSession . requestContext . request as ListRecommendationsRequest )
250- getLogger ( ) . info ( `request to inline recommendation : \n${ JSON . stringify ( request ) } ` )
241+ const request = currentSession . requestContext . request
251242 TelemetryHelper . instance . setPreprocessEndTime ( )
252243
253244 // set start pos for non pagination call or first pagination call
@@ -295,7 +286,6 @@ export class RecommendationHandler {
295286 requestId = resp ?. $response && resp ?. $response ?. requestId
296287 nextToken = resp ?. nextToken ? resp ?. nextToken : ''
297288 sessionId = resp ?. $response ?. httpResponse ?. headers [ 'x-amzn-sessionid' ]
298- getLogger ( ) . info ( `response from inline recommendation : \n${ JSON . stringify ( resp ) } ` )
299289 TelemetryHelper . instance . setFirstResponseRequestId ( requestId )
300290 if ( page === 0 ) {
301291 currentSession . setTimeToFirstRecommendation ( performance . now ( ) )
@@ -422,15 +412,19 @@ export class RecommendationHandler {
422412 }
423413 currentSession . setCompletionType ( recommendationIndex , r )
424414 }
425- currentSession . recommendations = pagination ? currentSession . recommendations . concat ( recommendations ) : recommendations
415+ currentSession . recommendations = pagination
416+ ? currentSession . recommendations . concat ( recommendations )
417+ : recommendations
426418 if ( isInlineCompletionEnabled ( ) && this . hasAtLeastOneValidSuggestion ( typedPrefix , currentSession ) ) {
427419 this . _onDidReceiveRecommendation . fire ( )
428420 }
429421 }
430422
431423 this . requestId = requestId
432424 currentSession . sessionId = sessionId
433- this . nextToken = nextToken
425+ if ( ! isNextSession ) {
426+ this . nextToken = nextToken
427+ }
434428
435429 // send Empty userDecision event if user receives no recommendations in this session at all.
436430 if ( invocationResult === 'Succeeded' && nextToken === '' ) {
@@ -490,22 +484,12 @@ export class RecommendationHandler {
490484 const session = CodeWhispererSessionState . instance . getSession ( )
491485 session . requestIdList = [ ]
492486 session . recommendations = [ ]
493- // session.nextRecommendations = []
494487 session . suggestionStates = new Map < number , string > ( )
495488 session . completionTypes = new Map < number , CodewhispererCompletionType > ( )
496489 this . requestId = ''
497490 session . sessionId = ''
498491 this . nextToken = ''
499492 session . requestContext . supplementalMetadata = undefined
500- // nextSession.requestIdList = []
501- // nextSession.recommendations = []
502- // // nextSession.nextRecommendations = []
503- // nextSession.suggestionStates = new Map<number, string>()
504- // nextSession.completionTypes = new Map<number, CodewhispererCompletionType>()
505- // this.requestId = ''
506- // nextSession.sessionId = ''
507- // this.nextToken = ''
508- // nextSession.requestContext.supplementalMetadata = undefined
509493 }
510494
511495 async clearInlineCompletionStates ( ) {
@@ -653,7 +637,6 @@ export class RecommendationHandler {
653637 const session = CodeWhispererSessionState . instance . getSession ( )
654638
655639 if ( ! indexShift && session . recommendations . length ) {
656- // TODO: gate behind A/B group if needed
657640 await this . fetchNextRecommendations ( )
658641 }
659642 await lock . acquire ( updateInlineLockKey , async ( ) => {
@@ -725,7 +708,6 @@ export class RecommendationHandler {
725708 const isManualTriggerEnabled : boolean = true
726709 const isSuggestionsWithCodeReferencesEnabled = codewhispererSettings . isSuggestionsWithCodeReferencesEnabled ( )
727710
728- // TODO:remove isManualTriggerEnabled
729711 return {
730712 isShowMethodsEnabled,
731713 isManualTriggerEnabled,
@@ -738,9 +720,11 @@ export class RecommendationHandler {
738720 const session = CodeWhispererSessionState . instance . getSession ( )
739721 const client = new codewhispererClient . DefaultCodeWhispererClient ( )
740722 const editor = vscode . window . activeTextEditor
741- if ( ! editor ) return
723+ if ( ! editor ) {
724+ return
725+ }
742726
743- this . getRecommendations (
727+ await this . getRecommendations (
744728 client ,
745729 editor ,
746730 session . triggerType ,
0 commit comments