Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Bug Fix",
"description": "fix increased latency due to inline completion API is called in a blocking manner"
}
45 changes: 32 additions & 13 deletions packages/amazonq/src/app/inline/recommendationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class RecommendationService {
nextToken: request.partialResultToken,
},
})
let result: InlineCompletionListWithReferences = await languageClient.sendRequest(
const result: InlineCompletionListWithReferences = await languageClient.sendRequest(
inlineCompletionWithReferencesRequestType.method,
request,
token
Expand Down Expand Up @@ -120,18 +120,10 @@ export class RecommendationService {
getLogger().info(
'Suggestion type is COMPLETIONS. Start fetching for more items if partialResultToken exists.'
)
try {
while (result.partialResultToken) {
const paginatedRequest = { ...request, partialResultToken: result.partialResultToken }
result = await languageClient.sendRequest(
inlineCompletionWithReferencesRequestType.method,
paginatedRequest,
token
)
this.sessionManager.updateSessionSuggestions(result.items)
}
} catch (error) {
languageClient.warn(`Error when getting suggestions: ${error}`)
if (result.partialResultToken) {
this.processRemainingRequests(languageClient, request, result, token).catch((error) => {
languageClient.warn(`Error when getting suggestions: ${error}`)
})
}
} else {
// Skip fetching for more items if the suggesion is EDITS. If it is EDITS suggestion, only fetching for more
Expand Down Expand Up @@ -167,4 +159,31 @@ export class RecommendationService {
}
}
}

private async processRemainingRequests(
languageClient: LanguageClient,
initialRequest: InlineCompletionWithReferencesParams,
firstResult: InlineCompletionListWithReferences,
token: CancellationToken
): Promise<void> {
let nextToken = firstResult.partialResultToken
while (nextToken) {
const request = { ...initialRequest, partialResultToken: nextToken }

const result: InlineCompletionListWithReferences = await languageClient.sendRequest(
inlineCompletionWithReferencesRequestType.method,
request,
token
)

this.sessionManager.updateSessionSuggestions(result.items)
nextToken = result.partialResultToken
}

this.sessionManager.closeSession()

// All pagination requests completed
TelemetryHelper.instance.setAllPaginationEndTime()
TelemetryHelper.instance.tryRecordClientComponentLatency()
}
}
Loading