Skip to content

Commit a895111

Browse files
committed
fix pagination
1 parent 4028800 commit a895111

File tree

5 files changed

+79
-24
lines changed

5 files changed

+79
-24
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Render first response before receiving all paginated inline completion results"
4+
}

packages/amazonq/package.json

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -917,12 +917,12 @@
917917
},
918918
{
919919
"key": "right",
920-
"command": "editor.action.inlineSuggest.showNext",
920+
"command": "aws.amazonq.showNext",
921921
"when": "inlineSuggestionVisible && !editorReadonly && aws.codewhisperer.connected"
922922
},
923923
{
924924
"key": "left",
925-
"command": "editor.action.inlineSuggest.showPrevious",
925+
"command": "aws.amazonq.showPrev",
926926
"when": "inlineSuggestionVisible && !editorReadonly && aws.codewhisperer.connected"
927927
},
928928
{
@@ -1325,26 +1325,40 @@
13251325
"fontCharacter": "\\f1de"
13261326
}
13271327
},
1328-
"aws-schemas-registry": {
1328+
"aws-sagemaker-code-editor": {
13291329
"description": "AWS Contributed Icon",
13301330
"default": {
13311331
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13321332
"fontCharacter": "\\f1df"
13331333
}
13341334
},
1335-
"aws-schemas-schema": {
1335+
"aws-sagemaker-jupyter-lab": {
13361336
"description": "AWS Contributed Icon",
13371337
"default": {
13381338
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13391339
"fontCharacter": "\\f1e0"
13401340
}
13411341
},
1342-
"aws-stepfunctions-preview": {
1342+
"aws-schemas-registry": {
13431343
"description": "AWS Contributed Icon",
13441344
"default": {
13451345
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13461346
"fontCharacter": "\\f1e1"
13471347
}
1348+
},
1349+
"aws-schemas-schema": {
1350+
"description": "AWS Contributed Icon",
1351+
"default": {
1352+
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1353+
"fontCharacter": "\\f1e2"
1354+
}
1355+
},
1356+
"aws-stepfunctions-preview": {
1357+
"description": "AWS Contributed Icon",
1358+
"default": {
1359+
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1360+
"fontCharacter": "\\f1e3"
1361+
}
13481362
}
13491363
},
13501364
"walkthroughs": [

packages/amazonq/src/app/inline/recommendationService.ts

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
5+
//import vscode from 'vscode'
66
import {
77
InlineCompletionListWithReferences,
88
InlineCompletionWithReferencesParams,
@@ -80,7 +80,7 @@ export class RecommendationService {
8080
nextToken: request.partialResultToken,
8181
},
8282
})
83-
let result: InlineCompletionListWithReferences = await languageClient.sendRequest(
83+
const result: InlineCompletionListWithReferences = await languageClient.sendRequest(
8484
inlineCompletionWithReferencesRequestType.method,
8585
request,
8686
token
@@ -120,18 +120,10 @@ export class RecommendationService {
120120
getLogger().info(
121121
'Suggestion type is COMPLETIONS. Start fetching for more items if partialResultToken exists.'
122122
)
123-
try {
124-
while (result.partialResultToken) {
125-
const paginatedRequest = { ...request, partialResultToken: result.partialResultToken }
126-
result = await languageClient.sendRequest(
127-
inlineCompletionWithReferencesRequestType.method,
128-
paginatedRequest,
129-
token
130-
)
131-
this.sessionManager.updateSessionSuggestions(result.items)
132-
}
133-
} catch (error) {
134-
languageClient.warn(`Error when getting suggestions: ${error}`)
123+
if (result.partialResultToken) {
124+
this.processRemainingRequests(languageClient, request, result, token).catch((error) => {
125+
languageClient.warn(`Error when getting suggestions: ${error}`)
126+
})
135127
}
136128
} else {
137129
// Skip fetching for more items if the suggesion is EDITS. If it is EDITS suggestion, only fetching for more
@@ -140,11 +132,6 @@ export class RecommendationService {
140132
getLogger().info('Suggestion type is EDITS. Skip fetching for more items.')
141133
this.sessionManager.updateActiveEditsStreakToken(result.partialResultToken)
142134
}
143-
144-
// Close session and finalize telemetry regardless of pagination path
145-
this.sessionManager.closeSession()
146-
TelemetryHelper.instance.setAllPaginationEndTime()
147-
options.emitTelemetry && TelemetryHelper.instance.tryRecordClientComponentLatency()
148135
} catch (error: any) {
149136
getLogger().error('Error getting recommendations: %O', error)
150137
// bearer token expired
@@ -167,4 +154,31 @@ export class RecommendationService {
167154
}
168155
}
169156
}
157+
158+
private async processRemainingRequests(
159+
languageClient: LanguageClient,
160+
initialRequest: InlineCompletionWithReferencesParams,
161+
firstResult: InlineCompletionListWithReferences,
162+
token: CancellationToken
163+
): Promise<void> {
164+
let nextToken = firstResult.partialResultToken
165+
while (nextToken) {
166+
const request = { ...initialRequest, partialResultToken: nextToken }
167+
168+
const result: InlineCompletionListWithReferences = await languageClient.sendRequest(
169+
inlineCompletionWithReferencesRequestType.method,
170+
request,
171+
token
172+
)
173+
this.sessionManager.updateSessionSuggestions(result.items)
174+
nextToken = result.partialResultToken
175+
}
176+
177+
this.sessionManager.closeSession()
178+
179+
// refresh inline completion items to render paginated responses
180+
// All pagination requests completed
181+
TelemetryHelper.instance.setAllPaginationEndTime()
182+
TelemetryHelper.instance.tryRecordClientComponentLatency()
183+
}
170184
}

packages/amazonq/src/app/inline/sessionManager.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface CodeWhispererSession {
2424
export class SessionManager {
2525
private activeSession?: CodeWhispererSession
2626
private _acceptedSuggestionCount: number = 0
27+
private _refreshedSessions = new Set<string>()
2728

2829
constructor() {}
2930

@@ -51,6 +52,7 @@ export class SessionManager {
5152
return
5253
}
5354
this.activeSession.isRequestInProgress = false
55+
console.log(`session closed!`)
5456
}
5557

5658
public getActiveSession() {
@@ -86,4 +88,17 @@ export class SessionManager {
8688
public clear() {
8789
this.activeSession = undefined
8890
}
91+
92+
// re-render the session ghost text to display paginated responses once per completed session
93+
public async maybeRefreshSessionUx() {
94+
if (
95+
this.activeSession &&
96+
!this.activeSession.isRequestInProgress &&
97+
!this._refreshedSessions.has(this.activeSession.sessionId)
98+
) {
99+
await vscode.commands.executeCommand('editor.action.inlineSuggest.hide')
100+
await vscode.commands.executeCommand('editor.action.inlineSuggest.trigger')
101+
this._refreshedSessions.add(this.activeSession.sessionId)
102+
}
103+
}
89104
}

packages/amazonq/src/lsp/client.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,14 @@ async function onLanguageServerReady(
265265

266266
toDispose.push(
267267
inlineManager,
268+
Commands.register('aws.amazonq.showPrev', async () => {
269+
await sessionManager.maybeRefreshSessionUx()
270+
await vscode.commands.executeCommand('editor.action.inlineSuggest.showPrevious')
271+
}),
272+
Commands.register('aws.amazonq.showNext', async () => {
273+
await sessionManager.maybeRefreshSessionUx()
274+
await vscode.commands.executeCommand('editor.action.inlineSuggest.showNext')
275+
}),
268276
Commands.register({ id: 'aws.amazonq.invokeInlineCompletion', autoconnect: true }, async () => {
269277
await vscode.commands.executeCommand('editor.action.inlineSuggest.trigger')
270278
}),

0 commit comments

Comments
 (0)