Skip to content

Commit 070c66f

Browse files
committed
123
1 parent 3b2e28f commit 070c66f

File tree

5 files changed

+83
-54
lines changed

5 files changed

+83
-54
lines changed

packages/amazonq/package.json

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,159 +1289,173 @@
12891289
"fontCharacter": "\\f1d2"
12901290
}
12911291
},
1292-
"aws-lambda-function": {
1292+
"aws-lambda-deployed-function": {
12931293
"description": "AWS Contributed Icon",
12941294
"default": {
12951295
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
12961296
"fontCharacter": "\\f1d3"
12971297
}
12981298
},
1299-
"aws-mynah-MynahIconBlack": {
1299+
"aws-lambda-function": {
13001300
"description": "AWS Contributed Icon",
13011301
"default": {
13021302
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13031303
"fontCharacter": "\\f1d4"
13041304
}
13051305
},
1306-
"aws-mynah-MynahIconWhite": {
1306+
"aws-lambda-invoke-remotely": {
13071307
"description": "AWS Contributed Icon",
13081308
"default": {
13091309
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13101310
"fontCharacter": "\\f1d5"
13111311
}
13121312
},
1313-
"aws-mynah-logo": {
1313+
"aws-mynah-MynahIconBlack": {
13141314
"description": "AWS Contributed Icon",
13151315
"default": {
13161316
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13171317
"fontCharacter": "\\f1d6"
13181318
}
13191319
},
1320-
"aws-redshift-cluster": {
1320+
"aws-mynah-MynahIconWhite": {
13211321
"description": "AWS Contributed Icon",
13221322
"default": {
13231323
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13241324
"fontCharacter": "\\f1d7"
13251325
}
13261326
},
1327-
"aws-redshift-cluster-connected": {
1327+
"aws-mynah-logo": {
13281328
"description": "AWS Contributed Icon",
13291329
"default": {
13301330
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13311331
"fontCharacter": "\\f1d8"
13321332
}
13331333
},
1334-
"aws-redshift-database": {
1334+
"aws-redshift-cluster": {
13351335
"description": "AWS Contributed Icon",
13361336
"default": {
13371337
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13381338
"fontCharacter": "\\f1d9"
13391339
}
13401340
},
1341-
"aws-redshift-redshift-cluster-connected": {
1341+
"aws-redshift-cluster-connected": {
13421342
"description": "AWS Contributed Icon",
13431343
"default": {
13441344
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13451345
"fontCharacter": "\\f1da"
13461346
}
13471347
},
1348-
"aws-redshift-schema": {
1348+
"aws-redshift-database": {
13491349
"description": "AWS Contributed Icon",
13501350
"default": {
13511351
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13521352
"fontCharacter": "\\f1db"
13531353
}
13541354
},
1355-
"aws-redshift-table": {
1355+
"aws-redshift-redshift-cluster-connected": {
13561356
"description": "AWS Contributed Icon",
13571357
"default": {
13581358
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13591359
"fontCharacter": "\\f1dc"
13601360
}
13611361
},
1362-
"aws-s3-bucket": {
1362+
"aws-redshift-schema": {
13631363
"description": "AWS Contributed Icon",
13641364
"default": {
13651365
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13661366
"fontCharacter": "\\f1dd"
13671367
}
13681368
},
1369-
"aws-s3-create-bucket": {
1369+
"aws-redshift-table": {
13701370
"description": "AWS Contributed Icon",
13711371
"default": {
13721372
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13731373
"fontCharacter": "\\f1de"
13741374
}
13751375
},
1376-
"aws-sagemaker-code-editor": {
1376+
"aws-s3-bucket": {
13771377
"description": "AWS Contributed Icon",
13781378
"default": {
13791379
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13801380
"fontCharacter": "\\f1df"
13811381
}
13821382
},
1383-
"aws-sagemaker-jupyter-lab": {
1383+
"aws-s3-create-bucket": {
13841384
"description": "AWS Contributed Icon",
13851385
"default": {
13861386
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13871387
"fontCharacter": "\\f1e0"
13881388
}
13891389
},
1390-
"aws-sagemakerunifiedstudio-catalog": {
1390+
"aws-sagemaker-code-editor": {
13911391
"description": "AWS Contributed Icon",
13921392
"default": {
13931393
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13941394
"fontCharacter": "\\f1e1"
13951395
}
13961396
},
1397-
"aws-sagemakerunifiedstudio-spaces": {
1397+
"aws-sagemaker-jupyter-lab": {
13981398
"description": "AWS Contributed Icon",
13991399
"default": {
14001400
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
14011401
"fontCharacter": "\\f1e2"
14021402
}
14031403
},
1404-
"aws-sagemakerunifiedstudio-spaces-dark": {
1404+
"aws-sagemakerunifiedstudio-catalog": {
14051405
"description": "AWS Contributed Icon",
14061406
"default": {
14071407
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
14081408
"fontCharacter": "\\f1e3"
14091409
}
14101410
},
1411-
"aws-sagemakerunifiedstudio-symbol-int": {
1411+
"aws-sagemakerunifiedstudio-spaces": {
14121412
"description": "AWS Contributed Icon",
14131413
"default": {
14141414
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
14151415
"fontCharacter": "\\f1e4"
14161416
}
14171417
},
1418-
"aws-sagemakerunifiedstudio-table": {
1418+
"aws-sagemakerunifiedstudio-spaces-dark": {
14191419
"description": "AWS Contributed Icon",
14201420
"default": {
14211421
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
14221422
"fontCharacter": "\\f1e5"
14231423
}
14241424
},
1425-
"aws-schemas-registry": {
1425+
"aws-sagemakerunifiedstudio-symbol-int": {
14261426
"description": "AWS Contributed Icon",
14271427
"default": {
14281428
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
14291429
"fontCharacter": "\\f1e6"
14301430
}
14311431
},
1432-
"aws-schemas-schema": {
1432+
"aws-sagemakerunifiedstudio-table": {
14331433
"description": "AWS Contributed Icon",
14341434
"default": {
14351435
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
14361436
"fontCharacter": "\\f1e7"
14371437
}
14381438
},
1439-
"aws-stepfunctions-preview": {
1439+
"aws-schemas-registry": {
14401440
"description": "AWS Contributed Icon",
14411441
"default": {
14421442
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
14431443
"fontCharacter": "\\f1e8"
14441444
}
1445+
},
1446+
"aws-schemas-schema": {
1447+
"description": "AWS Contributed Icon",
1448+
"default": {
1449+
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1450+
"fontCharacter": "\\f1e9"
1451+
}
1452+
},
1453+
"aws-stepfunctions-preview": {
1454+
"description": "AWS Contributed Icon",
1455+
"default": {
1456+
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1457+
"fontCharacter": "\\f1ea"
1458+
}
14451459
}
14461460
},
14471461
"walkthroughs": [

packages/amazonq/src/app/inline/EditRendering/displayImage.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ export class EditDecorationManager {
163163
/**
164164
* Clears all edit suggestion decorations
165165
*/
166-
public async clearDecorations(editor: vscode.TextEditor): Promise<void> {
166+
public async clearDecorations(editor: vscode.TextEditor, disposables: vscode.Disposable[]): Promise<void> {
167+
for (const d of disposables) {
168+
d.dispose()
169+
}
167170
editor.setDecorations(this.imageDecorationType, [])
168171
editor.setDecorations(this.removedCodeDecorationType, [])
169172
this.currentImageDecoration = undefined
@@ -380,12 +383,7 @@ export async function displaySvgDecoration(
380383
const endPosition = getEndOfEditPosition(originalCode, newCode)
381384
editor.selection = new vscode.Selection(endPosition, endPosition)
382385

383-
await decorationManager.clearDecorations(editor)
384-
385-
// Dispose registered listeners on popup close
386-
for (const listener of listeners) {
387-
listener.dispose()
388-
}
386+
await decorationManager.clearDecorations(editor, listeners)
389387

390388
const params: LogInlineCompletionSessionResultsParams = {
391389
sessionId: session.sessionId,
@@ -410,12 +408,7 @@ export async function displaySvgDecoration(
410408
} else {
411409
getLogger().info('Edit suggestion rejected')
412410
}
413-
await decorationManager.clearDecorations(editor)
414-
415-
// Dispose registered listeners on popup close
416-
for (const listener of listeners) {
417-
listener.dispose()
418-
}
411+
await decorationManager.clearDecorations(editor, listeners)
419412

420413
const suggestionState = isDiscard
421414
? {

packages/amazonq/src/app/inline/EditRendering/imageRenderer.ts

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import * as vscode from 'vscode'
7-
import { displaySvgDecoration } from './displayImage'
7+
import { displaySvgDecoration, decorationManager } from './displayImage'
88
import { SvgGenerationService } from './svgGenerator'
99
import { getContext, getLogger } from 'aws-core-vscode/shared'
1010
import { LanguageClient } from 'vscode-languageclient'
@@ -32,8 +32,8 @@ enum RejectReason {
3232

3333
export class EditsSuggestionSvg {
3434
private readonly logger = getLogger('nextEditPrediction')
35-
private readonly documentChangedListener: vscode.Disposable
36-
private readonly cursorChangedListener: vscode.Disposable
35+
private documentChangedListener: vscode.Disposable | undefined
36+
private cursorChangedListener: vscode.Disposable | undefined
3737
private readonly updatedSuggestions: InlineCompletionItemWithReferences[] = []
3838
private startLine = 0
3939

@@ -42,16 +42,8 @@ export class EditsSuggestionSvg {
4242
private readonly editor: vscode.TextEditor,
4343
private readonly languageClient: LanguageClient,
4444
private readonly session: CodeWhispererSession,
45-
private readonly inlineCompletionProvider?: AmazonQInlineCompletionItemProvider // why nullable?
46-
) {
47-
this.documentChangedListener = vscode.workspace.onDidChangeTextDocument(async (e) => {
48-
await this.onDocChange(e)
49-
})
50-
51-
this.cursorChangedListener = vscode.window.onDidChangeTextEditorSelection((e) => {
52-
this.onCursorChange(e)
53-
})
54-
}
45+
private readonly inlineCompletionProvider?: AmazonQInlineCompletionItemProvider
46+
) {}
5547

5648
async show() {
5749
if (!this.editor) {
@@ -80,6 +72,16 @@ export class EditsSuggestionSvg {
8072
}
8173

8274
if (svgImage) {
75+
const documentChangedListener = (this.documentChangedListener ??=
76+
vscode.workspace.onDidChangeTextDocument(async (e) => {
77+
await this.onDocChange(e)
78+
}))
79+
80+
const cursorChangedListener = (this.cursorChangedListener ??=
81+
vscode.window.onDidChangeTextEditorSelection((e) => {
82+
this.onCursorChange(e)
83+
}))
84+
8385
// display the SVG image
8486
await displaySvgDecoration(
8587
this.editor,
@@ -90,7 +92,7 @@ export class EditsSuggestionSvg {
9092
this.session,
9193
this.languageClient,
9294
item,
93-
[this.documentChangedListener, this.cursorChangedListener],
95+
[documentChangedListener, cursorChangedListener],
9496
this.inlineCompletionProvider
9597
)
9698
} else {
@@ -134,6 +136,8 @@ export class EditsSuggestionSvg {
134136
return
135137
}
136138

139+
this.logger.info(`docChange ${this.session.sessionId}, contentChange=${e.contentChanges[0].text}`)
140+
137141
/**
138142
* 1. Take the diff returned by the model and apply it to the code we originally sent to the model
139143
* 2. Do a diff between the above code and what's currently in the editor
@@ -150,18 +154,30 @@ export class EditsSuggestionSvg {
150154
this.autoReject(RejectReason.MaxRetry)
151155
} else if (applyPatch(this.editor.document.getText(), updatedPatch) === false) {
152156
this.autoReject(RejectReason.DocumentChange)
157+
} else {
158+
// Close the previoius popup and rerender it
159+
await this.rerender()
153160
}
154-
155-
await this.show()
156161
} else {
157-
this.autoReject(RejectReason.NotApplicableToOriginal)
162+
// this.autoReject(RejectReason.NotApplicableToOriginal)
158163
}
159164
} catch (e) {
160165
// TODO: format
161166
this.logger.error(`${e}`)
162167
}
163168
}
164169

170+
async dispose() {
171+
this.documentChangedListener?.dispose()
172+
this.cursorChangedListener?.dispose()
173+
await decorationManager.clearDecorations(this.editor, [])
174+
}
175+
176+
private async rerender() {
177+
await decorationManager.clearDecorations(this.editor, [])
178+
await this.show()
179+
}
180+
165181
private autoReject(reason: string) {
166182
logSuggestionFailure('REJECT', reason, this.suggestion.insertText as string)
167183
void vscode.commands.executeCommand('aws.amazonq.inline.rejectEdit')

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ export class InlineCompletionManager implements Disposable {
214214
export class AmazonQInlineCompletionItemProvider implements InlineCompletionItemProvider {
215215
private logger = getLogger()
216216
private pendingRequest: Promise<InlineCompletionItem[]> | undefined
217+
private lastEdit: EditsSuggestionSvg | undefined
217218

218219
constructor(
219220
private readonly languageClient: LanguageClient,
@@ -529,7 +530,12 @@ ${itemLog}
529530
if (item.isInlineEdit) {
530531
// Check if Next Edit Prediction feature flag is enabled
531532
if (Experiments.instance.get('amazonqLSPNEP', true)) {
532-
await new EditsSuggestionSvg(item, editor, this.languageClient, session, this).show()
533+
if (this.lastEdit) {
534+
await this.lastEdit.dispose()
535+
}
536+
const e = new EditsSuggestionSvg(item, editor, this.languageClient, session, this)
537+
await e.show()
538+
this.lastEdit = e
533539
logstr += `- duration between trigger to edits suggestion is displayed: ${Date.now() - t0}ms`
534540
}
535541
return []

packages/amazonq/test/unit/app/inline/EditRendering/displayImage.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ describe('EditDecorationManager', function () {
177177
editorStub.setDecorations.reset()
178178

179179
// Call clearDecorations
180-
await manager.clearDecorations(editorStub as unknown as vscode.TextEditor)
180+
await manager.clearDecorations(editorStub as unknown as vscode.TextEditor, [])
181181

182182
// Verify decorations were cleared
183183
assert.strictEqual(editorStub.setDecorations.callCount, 2)

0 commit comments

Comments
 (0)