Skip to content

Commit 85d3df2

Browse files
committed
patch
1 parent c9b5cf0 commit 85d3df2

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

packages/core/src/codewhisperer/models/model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export interface CodeWhispererSupplementalContextItem {
8181

8282
// This response struct can contain more info as needed
8383
export interface GetRecommendationsResponse {
84+
readonly sessionId: string
8485
readonly result: 'Succeeded' | 'Failed'
8586
readonly recommendationCount: number
8687
readonly errorMessage: string | undefined

packages/core/src/codewhisperer/service/recommendationHandler.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export class RecommendationHandler {
181181

182182
if (!editor) {
183183
return Promise.resolve<GetRecommendationsResponse>({
184+
sessionId: '',
184185
result: invocationResult,
185186
errorMessage: errorMessage,
186187
recommendationCount: 0,
@@ -259,6 +260,7 @@ export class RecommendationHandler {
259260
errorMessage = `${languageName} is currently not supported by Amazon Q inline suggestions`
260261
}
261262
return Promise.resolve<GetRecommendationsResponse>({
263+
sessionId: '',
262264
result: invocationResult,
263265
errorMessage: errorMessage,
264266
recommendationCount: 0,
@@ -390,6 +392,7 @@ export class RecommendationHandler {
390392

391393
if (!isNextSession && this.isCancellationRequested()) {
392394
return Promise.resolve<GetRecommendationsResponse>({
395+
sessionId: '',
393396
result: invocationResult,
394397
errorMessage: errorMessage,
395398
recommendationCount: currentSession.recommendations.length,
@@ -450,6 +453,7 @@ export class RecommendationHandler {
450453
}
451454
}
452455
return Promise.resolve<GetRecommendationsResponse>({
456+
sessionId: sessionId,
453457
result: invocationResult,
454458
errorMessage: errorMessage,
455459
recommendationCount: currentSession.recommendations.length,
@@ -638,7 +642,7 @@ export class RecommendationHandler {
638642
const session = CodeWhispererSessionState.instance.getSession()
639643

640644
if (!indexShift && session.recommendations.length) {
641-
await this.fetchNextRecommendations()
645+
await this.fetchNextRecommendations(session)
642646
}
643647
await lock.acquire(updateInlineLockKey, async () => {
644648
if (!vscode.window.state.focused) {
@@ -717,15 +721,14 @@ export class RecommendationHandler {
717721
}
718722
}
719723

720-
async fetchNextRecommendations() {
721-
const session = CodeWhispererSessionState.instance.getSession()
724+
async fetchNextRecommendations(session: CodeWhispererSession) {
722725
const client = new codewhispererClient.DefaultCodeWhispererClient()
723726
const editor = vscode.window.activeTextEditor
724727
if (!editor) {
725728
return
726729
}
727730

728-
await this.getRecommendations(
731+
const nextResp = await this.getRecommendations(
729732
client,
730733
editor,
731734
session.triggerType,
@@ -737,6 +740,11 @@ export class RecommendationHandler {
737740
false,
738741
true
739742
)
743+
744+
const nextSessionId = nextResp.sessionId
745+
if (nextSessionId.length === 0 || nextSessionId !== session.sessionId) {
746+
CodeWhispererSessionState.instance.getNextSession().reset()
747+
}
740748
}
741749

742750
async tryShowRecommendation() {

0 commit comments

Comments
 (0)