-
Notifications
You must be signed in to change notification settings - Fork 746
feat(amazonq): passing partialResultToken for the next trigger if user accepts an EDITS suggestion #7611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(amazonq): passing partialResultToken for the next trigger if user accepts an EDITS suggestion #7611
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import { globals, getLogger } from 'aws-core-vscode/shared' | |
| export interface GetAllRecommendationsOptions { | ||
| emitTelemetry?: boolean | ||
| showUi?: boolean | ||
| editsStreakToken?: number | string | ||
| } | ||
|
|
||
| export class RecommendationService { | ||
|
|
@@ -47,13 +48,16 @@ export class RecommendationService { | |
| // Record that a regular request is being made | ||
| this.cursorUpdateRecorder?.recordCompletionRequest() | ||
|
|
||
| const request: InlineCompletionWithReferencesParams = { | ||
| let request: InlineCompletionWithReferencesParams = { | ||
| textDocument: { | ||
| uri: document.uri.toString(), | ||
| }, | ||
| position, | ||
| context, | ||
| } | ||
| if (options.editsStreakToken) { | ||
| request = { ...request, partialResultToken: options.editsStreakToken } | ||
| } | ||
| const requestStartTime = globals.clock.Date.now() | ||
| const statusBar = CodeWhispererStatusBarManager.instance | ||
|
|
||
|
|
@@ -112,19 +116,31 @@ export class RecommendationService { | |
| firstCompletionDisplayLatency | ||
| ) | ||
|
|
||
| // If there are more results to fetch, handle them in the background | ||
| try { | ||
| while (result.partialResultToken) { | ||
| const paginatedRequest = { ...request, partialResultToken: result.partialResultToken } | ||
| result = await languageClient.sendRequest( | ||
| inlineCompletionWithReferencesRequestType.method, | ||
| paginatedRequest, | ||
| token | ||
| ) | ||
| this.sessionManager.updateSessionSuggestions(result.items) | ||
| const isInlineEdit = result.items.some((item) => item.isInlineEdit) | ||
| if (!isInlineEdit) { | ||
| // If the suggestion is COMPLETIONS and there are more results to fetch, handle them in the background | ||
| 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}`) | ||
| } | ||
| } 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 | ||
| // suggestions when the user start to accept a suggesion. | ||
| // Save editsStreakPartialResultToken for the next EDITS suggestion trigger if user accepts. | ||
| getLogger().info('Suggestion type is EDITS. Skip fetching for more items.') | ||
| this.sessionManager.updateActiveEditsStreakToken(result.partialResultToken) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assumes the first result is an edit, but the check on line 120 is just for at one edit anywhere in the results. Is there some undocumented assumption here about how the results are returned? Even if there is, there should be checks in code that the assumptions hold.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can only return either EDITS or COMPLETIONS so if one item is EDITS, we should follow the EDITS flow.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| // Close session and finalize telemetry regardless of pagination path | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.