Skip to content

Commit 63946ff

Browse files
authored
fix(amazonq): inline pagination doesn't work, the paginated response will not be rendered (#8470)
## Problem ## Solution ``` 2025-12-29 01:20:24.853 [info] inline: found non null next token; Start pagination 2025-12-29 01:20:24.853 [info] GenerateCompletion activity: - number of suggestions: 1 - sessionId: 584db06a-4e51-4fbf-9656-6ac590756627 - first suggestion content (next line): // a function to find the square of a number public static int square(int a) { return a * a; } - duration between trigger to before sending LSP call: 0ms - duration between trigger to after receiving LSP response: 758ms - duration between before sending LSP call to after receving LSP response: 758ms - duration between trigger to completion suggestion is displayed: 759ms 2025-12-29 01:20:25.145 [info] inline: Pagination call is complete page 0 has 1 suggestions page 1 has 1 suggestions 2025-12-29 01:20:25.160 [info] inline: Done pagination; ShouldUpdate=true; updatedSuggestionCount=2 ``` --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 3d07d02 commit 63946ff

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
369369
// yield event loop to let the document listen catch updates
370370
await sleep(1)
371371

372-
let logstr = `GenerateCompletion activity:\\n`
372+
let logstr = `GenerateCompletion activity:\n`
373373
try {
374374
const t0 = Date.now()
375375
vsCodeState.isRecommendationsActive = true

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

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface GetAllRecommendationsOptions {
3535
}
3636

3737
export class RecommendationService {
38-
private logger = getLogger()
38+
private logger = getLogger('inline')
3939

4040
constructor(
4141
private readonly sessionManager: SessionManager,
@@ -176,7 +176,7 @@ export class RecommendationService {
176176
}
177177
}
178178

179-
this.logger.info('Received inline completion response from LSP: %O', {
179+
this.logger.info('Received inline completion response (page 0) from LSP: %O', {
180180
sessionId: result.sessionId,
181181
latency: Date.now() - t0,
182182
itemCount: result.items?.length || 0,
@@ -188,6 +188,7 @@ export class RecommendationService {
188188
50
189189
) + '...',
190190
})),
191+
nextToken: result.partialResultToken,
191192
})
192193

193194
if (result.items.length > 0 && result.items[0].isInlineEdit === false) {
@@ -249,18 +250,27 @@ export class RecommendationService {
249250

250251
// TODO: question, is it possible that the first request returns empty suggestion but has non-empty next token?
251252
if (result.partialResultToken) {
252-
let logstr = `found non null next token; `
253+
let logstr = `Found non null next token; `
253254
if (!isInlineEdit) {
254255
// If the suggestion is COMPLETIONS and there are more results to fetch, handle them in the background
255-
logstr += 'Suggestion type is COMPLETIONS. Start pulling more items'
256-
this.processRemainingRequests(languageClient, request, result, token).catch((error) => {
257-
languageClient.warn(`Error when getting suggestions: ${error}`)
258-
})
256+
logstr += 'start pagination'
257+
this.processRemainingRequests(languageClient, request, result, token)
258+
.then(async (flag) => {
259+
// Force vscode to reload suggestions
260+
await commands.executeCommand('editor.action.inlineSuggest.hide')
261+
await commands.executeCommand('editor.action.inlineSuggest.trigger')
262+
263+
const logstr = `Done pagination; shouldUpdate=${flag}; updatedSuggestionCount=${this.sessionManager.getActiveRecommendation().length}`
264+
this.logger.info(logstr)
265+
})
266+
.catch((error) => {
267+
languageClient.warn(`Error when getting suggestions: ${error}`)
268+
})
259269
} else {
260270
// Skip fetching for more items if the suggesion is EDITS. If it is EDITS suggestion, only fetching for more
261271
// suggestions when the user start to accept a suggesion.
262272
// Save editsStreakPartialResultToken for the next EDITS suggestion trigger if user accepts.
263-
logstr += 'Suggestion type is EDITS. Skip pulling more items'
273+
logstr += 'skip pagination as Edit doesnt support pagination'
264274
this.sessionManager.updateActiveEditsStreakToken(result.partialResultToken)
265275
}
266276

@@ -294,26 +304,39 @@ export class RecommendationService {
294304
initialRequest: InlineCompletionWithReferencesParams,
295305
firstResult: InlineCompletionListWithReferences,
296306
token: CancellationToken
297-
): Promise<void> {
307+
): Promise<boolean> {
308+
let page = 1
309+
let logstr = `Pagination call is complete\n\tpage 0 has ${this.sessionManager.getActiveRecommendation().length} suggestions\n`
298310
let nextToken = firstResult.partialResultToken
311+
let shouldUpdateUi: boolean = false
299312
while (nextToken) {
300313
const request = { ...initialRequest, partialResultToken: nextToken }
301314

302315
const result = await this.getRecommendationsWithTimeout(languageClient, request, token)
316+
317+
logstr += `\tpage ${page} has ${result.items.length} suggestions\n`
318+
303319
// when pagination is in progress, but user has already accepted or rejected an inline completion
304320
// then stop pagination
305321
if (this.sessionManager.getActiveSession() === undefined || vsCodeState.isCodeWhispererEditing) {
306322
break
307323
}
308324
this.sessionManager.updateSessionSuggestions(result.items)
325+
if (result.items.length > 0) {
326+
shouldUpdateUi = true
327+
}
309328
nextToken = result.partialResultToken
329+
page++
310330
}
311331

332+
this.logger.info(logstr)
312333
this.sessionManager.closeSession()
313334

314335
// refresh inline completion items to render paginated responses
315336
// All pagination requests completed
316337
TelemetryHelper.instance.setAllPaginationEndTime()
317338
TelemetryHelper.instance.tryRecordClientComponentLatency()
339+
340+
return shouldUpdateUi
318341
}
319342
}

packages/core/src/shared/logger/logger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type LogTopic =
2525
| 'proxyUtil'
2626
| 'sagemaker'
2727
| 'smus'
28+
| 'inline'
2829

2930
class ErrorLog {
3031
constructor(

0 commit comments

Comments
 (0)