Skip to content

Commit 3eef02a

Browse files
committed
a
1 parent 6052c3a commit 3eef02a

File tree

6 files changed

+128
-50
lines changed

6 files changed

+128
-50
lines changed

packages/amazonq/package.json

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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/EditRendering/displayImage.ts

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { getLogger, setContext } from 'aws-core-vscode/shared'
6+
import { getLogger, setContext, waitUntil } from 'aws-core-vscode/shared'
77
import * as vscode from 'vscode'
88
import { diffLines } from 'diff'
99
import { LanguageClient } from 'vscode-languageclient'
@@ -292,22 +292,42 @@ export async function displaySvgDecoration(
292292
startLine,
293293
async () => {
294294
// Handle accept
295+
session.isAccepted = true
295296
getLogger().info('Edit suggestion accepted')
296297

297-
// Replace content
298+
const endPosition = getEndOfEditPosition(originalCode, newCode)
299+
300+
let isEditDone: boolean | undefined
298301
try {
299302
vsCodeState.isCodeWhispererEditing = true
303+
getLogger().info('set isEditing to TRUE')
304+
// Replace content
300305
await replaceEditorContent(editor, newCode)
306+
307+
// Move cursor to end of the actual changed content
308+
editor.selection = new vscode.Selection(endPosition, endPosition)
309+
310+
// Move cursor to end of the actual changed content
311+
// editor.selection = new vscode.Selection(endPosition, endPosition)
312+
313+
isEditDone = await waitUntil(
314+
async () => {
315+
return editor.document.getText() === newCode
316+
},
317+
{
318+
timeout: 1000,
319+
interval: 50,
320+
truthy: true,
321+
}
322+
)
301323
} finally {
324+
getLogger().info('set isEditing to FALSE')
302325
vsCodeState.isCodeWhispererEditing = false
303326
}
304327

305-
// Move cursor to end of the actual changed content
306-
const endPosition = getEndOfEditPosition(originalCode, newCode)
307-
editor.selection = new vscode.Selection(endPosition, endPosition)
308-
309-
// Move cursor to end of the actual changed content
310-
editor.selection = new vscode.Selection(endPosition, endPosition)
328+
if (!isEditDone) {
329+
console.log()
330+
}
311331

312332
await decorationManager.clearDecorations(editor)
313333
const params: LogInlineCompletionSessionResultsParams = {
@@ -326,19 +346,19 @@ export async function displaySvgDecoration(
326346
languageClient.sendNotification('aws/logInlineCompletionSessionResults', params)
327347
// Only auto trigger on acceptance if there is a nextToken
328348
if (inlineCompletionProvider && session.editsStreakPartialResultToken) {
329-
getLogger('nextEditPrediction').info(
330-
`on acceptance trigger with nextToken ${session.editsStreakPartialResultToken}`
331-
)
332-
await inlineCompletionProvider.provideInlineCompletionItems(
333-
editor.document,
334-
endPosition,
335-
{
336-
triggerKind: vscode.InlineCompletionTriggerKind.Automatic,
337-
selectedCompletionInfo: undefined,
338-
},
339-
new vscode.CancellationTokenSource().token,
340-
{ emitTelemetry: false, showUi: false, editsStreakToken: session.editsStreakPartialResultToken }
341-
)
349+
// getLogger('nextEditPrediction').info(
350+
// `on acceptance trigger with nextToken ${session.editsStreakPartialResultToken}`
351+
// )
352+
// await inlineCompletionProvider._provideInlineCompletionItems(
353+
// editor.document,
354+
// endPosition,
355+
// {
356+
// triggerKind: vscode.InlineCompletionTriggerKind.Automatic,
357+
// selectedCompletionInfo: undefined,
358+
// },
359+
// new vscode.CancellationTokenSource().token,
360+
// { emitTelemetry: false, showUi: false, editsStreakToken: session.editsStreakPartialResultToken }
361+
// )
342362
}
343363
},
344364
async () => {

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

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,15 @@ export class InlineCompletionManager implements Disposable {
207207

208208
export class AmazonQInlineCompletionItemProvider implements InlineCompletionItemProvider {
209209
private logger = getLogger('nextEditPrediction')
210+
private isGcInProgress: boolean = false
210211
constructor(
211212
private readonly languageClient: LanguageClient,
212213
private readonly recommendationService: RecommendationService,
213214
private readonly sessionManager: SessionManager,
214215
private readonly inlineTutorialAnnotation: InlineTutorialAnnotation
215-
) {}
216+
) {
217+
this.inlineTutorialAnnotation
218+
}
216219

217220
private readonly logSessionResultMessageName = 'aws/logInlineCompletionSessionResults'
218221
provideInlineCompletionItems = debounce(
@@ -221,7 +224,7 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
221224
true
222225
)
223226

224-
private async _provideInlineCompletionItems(
227+
async _provideInlineCompletionItems(
225228
document: TextDocument,
226229
position: Position,
227230
context: InlineCompletionContext,
@@ -320,24 +323,35 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
320323
this.sessionManager.clear()
321324
}
322325

326+
if (this.isGcInProgress) {
327+
getLogger().info(`there is inflight generateCompletion request, exit generateCompletion flow`)
328+
return []
329+
}
330+
323331
// TODO: this line will take ~200ms each trigger, need to root cause and maybe better to disable it for now
324332
// tell the tutorial that completions has been triggered
325-
await this.inlineTutorialAnnotation.triggered(context.triggerKind)
333+
// await this.inlineTutorialAnnotation.triggered(context.triggerKind)
326334

327335
TelemetryHelper.instance.setInvokeSuggestionStartTime()
328336
TelemetryHelper.instance.setTriggerType(context.triggerKind)
329337

330338
const t1 = performance.now()
331339

332-
await this.recommendationService.getAllRecommendations(
333-
this.languageClient,
334-
document,
335-
position,
336-
context,
337-
token,
338-
isAutoTrigger,
339-
getAllRecommendationsOptions
340-
)
340+
try {
341+
this.isGcInProgress = true
342+
await this.recommendationService.getAllRecommendations(
343+
this.languageClient,
344+
document,
345+
position,
346+
context,
347+
token,
348+
isAutoTrigger,
349+
getAllRecommendationsOptions
350+
)
351+
} finally {
352+
this.isGcInProgress = false
353+
}
354+
341355
// get active item from session for displaying
342356
const items = this.sessionManager.getActiveRecommendation()
343357
const itemId = this.sessionManager.getActiveRecommendation()?.[0]?.itemId

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ export class CursorUpdateManager implements vscode.Disposable, ICursorUpdateReco
140140
* Creates a cancellation token source
141141
* This method exists to make testing easier by allowing it to be stubbed
142142
*/
143-
private createCancellationTokenSource(): vscode.CancellationTokenSource {
144-
return new vscode.CancellationTokenSource()
145-
}
143+
// private createCancellationTokenSource(): vscode.CancellationTokenSource {
144+
// return new vscode.CancellationTokenSource()
145+
// }
146146

147147
/**
148148
* Request LSP generate a completion for the current cursor position.
@@ -176,16 +176,16 @@ export class CursorUpdateManager implements vscode.Disposable, ICursorUpdateReco
176176

177177
// Call the inline completion provider instead of directly calling getAllRecommendations
178178
try {
179-
await this.inlineCompletionProvider.provideInlineCompletionItems(
180-
editor.document,
181-
position,
182-
{
183-
triggerKind: vscode.InlineCompletionTriggerKind.Automatic,
184-
selectedCompletionInfo: undefined,
185-
},
186-
this.createCancellationTokenSource().token,
187-
{ emitTelemetry: false, showUi: false }
188-
)
179+
// await this.inlineCompletionProvider.provideInlineCompletionItems(
180+
// editor.document,
181+
// position,
182+
// {
183+
// triggerKind: vscode.InlineCompletionTriggerKind.Automatic,
184+
// selectedCompletionInfo: undefined,
185+
// },
186+
// this.createCancellationTokenSource().token,
187+
// { emitTelemetry: false, showUi: false }
188+
// )
189189

190190
// Only update the last sent position after successfully sending the request
191191
this.lastSentPosition = position

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,21 @@ export class RecommendationService {
7070
await statusBar.setLoading()
7171
}
7272

73+
const prevSession = this.sessionManager.previousSession
74+
getLogger.info(`
75+
- prevSessionId = ${prevSession?.sessionId},
76+
- prevSession !== undefined = ${prevSession !== undefined},
77+
- prevSession.isAccepted = ${prevSession?.isAccepted},
78+
- prevSession.nextToken = ${prevSession?.editsStreakPartialResultToken}
79+
`)
80+
if (prevSession && prevSession.isAccepted && prevSession.editsStreakPartialResultToken) {
81+
getLogger().info(
82+
`previous session; sessionId=${prevSession.sessionId}; nextToken=${prevSession.editsStreakPartialResultToken}`
83+
)
84+
request.partialResultToken = prevSession.editsStreakPartialResultToken
85+
getLogger().info(`set request nextToken to ${request.partialResultToken}`)
86+
}
87+
7388
// Handle first request
7489
getLogger().info('Sending inline completion request: %O', {
7590
method: inlineCompletionWithReferencesRequestType.method,
@@ -85,8 +100,14 @@ export class RecommendationService {
85100
request,
86101
token
87102
)
103+
104+
if (!result.partialResultToken) {
105+
console.log()
106+
}
107+
88108
getLogger().info('Received inline completion response: %O', {
89109
sessionId: result.sessionId,
110+
nextToken: result.partialResultToken ?? '',
90111
itemCount: result.items?.length || 0,
91112
items: result.items?.map((item) => ({
92113
itemId: item.itemId,
@@ -137,7 +158,7 @@ export class RecommendationService {
137158
// Skip fetching for more items if the suggesion is EDITS. If it is EDITS suggestion, only fetching for more
138159
// suggestions when the user start to accept a suggesion.
139160
// Save editsStreakPartialResultToken for the next EDITS suggestion trigger if user accepts.
140-
getLogger().info('Suggestion type is EDITS. Skip fetching for more items.')
161+
getLogger('nextEditPrediction').info(`setting editstreak nextToken: ${result.partialResultToken}`)
141162
this.sessionManager.updateActiveEditsStreakToken(result.partialResultToken)
142163
}
143164

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import * as vscode from 'vscode'
66
import { InlineCompletionItemWithReferences } from '@aws/language-server-runtimes-types'
77
import { FileDiagnostic, getDiagnosticsOfCurrentFile } from 'aws-core-vscode/codewhisperer'
8+
import { getLogger } from 'aws-core-vscode/shared'
89

910
// TODO: add more needed data to the session interface
1011
export interface CodeWhispererSession {
@@ -18,10 +19,12 @@ export interface CodeWhispererSession {
1819
diagnosticsBeforeAccept: FileDiagnostic | undefined
1920
// partialResultToken for the next trigger if user accepts an EDITS suggestion
2021
editsStreakPartialResultToken?: number | string
22+
isAccepted: boolean
2123
}
2224

2325
export class SessionManager {
2426
private activeSession?: CodeWhispererSession
27+
previousSession?: CodeWhispererSession
2528
private _acceptedSuggestionCount: number = 0
2629

2730
constructor() {}
@@ -42,6 +45,7 @@ export class SessionManager {
4245
startPosition,
4346
firstCompletionDisplayLatency,
4447
diagnosticsBeforeAccept,
48+
isAccepted: false,
4549
}
4650
}
4751

@@ -83,6 +87,11 @@ export class SessionManager {
8387
}
8488

8589
public clear() {
90+
getLogger().info(`sessionManager sets previousSession with previousSessionId=${this.activeSession?.sessionId}`)
91+
this.previousSession = this.getActiveSession()
92+
getLogger().info(
93+
`sessionManager sets activeSession to undefined; previousSessionId=${this.activeSession?.sessionId}`
94+
)
8695
this.activeSession = undefined
8796
}
8897
}

0 commit comments

Comments
 (0)