Skip to content

Commit 7c8764c

Browse files
authored
fix(amazonq): nep path asynchronous ops are not awaited (#7619)
## Problem ## Solution --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 815eada commit 7c8764c

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,19 @@ export class EditDecorationManager {
122122
/**
123123
* Displays an edit suggestion as an SVG image in the editor and highlights removed code
124124
*/
125-
public displayEditSuggestion(
125+
public async displayEditSuggestion(
126126
editor: vscode.TextEditor,
127127
svgImage: vscode.Uri,
128128
startLine: number,
129-
onAccept: () => void,
130-
onReject: () => void,
129+
onAccept: () => Promise<void>,
130+
onReject: () => Promise<void>,
131131
originalCode: string,
132132
newCode: string,
133133
originalCodeHighlightRanges: Array<{ line: number; start: number; end: number }>
134-
): void {
135-
this.clearDecorations(editor)
134+
): Promise<void> {
135+
await this.clearDecorations(editor)
136136

137-
void setContext('aws.amazonq.editSuggestionActive' as any, true)
137+
await setContext('aws.amazonq.editSuggestionActive' as any, true)
138138

139139
this.acceptHandler = onAccept
140140
this.rejectHandler = onReject
@@ -157,14 +157,14 @@ export class EditDecorationManager {
157157
/**
158158
* Clears all edit suggestion decorations
159159
*/
160-
public clearDecorations(editor: vscode.TextEditor): void {
160+
public async clearDecorations(editor: vscode.TextEditor): Promise<void> {
161161
editor.setDecorations(this.imageDecorationType, [])
162162
editor.setDecorations(this.removedCodeDecorationType, [])
163163
this.currentImageDecoration = undefined
164164
this.currentRemovedCodeDecorations = []
165165
this.acceptHandler = undefined
166166
this.rejectHandler = undefined
167-
void setContext('aws.amazonq.editSuggestionActive' as any, false)
167+
await setContext('aws.amazonq.editSuggestionActive' as any, false)
168168
}
169169

170170
/**
@@ -285,7 +285,7 @@ export async function displaySvgDecoration(
285285
) {
286286
const originalCode = editor.document.getText()
287287

288-
decorationManager.displayEditSuggestion(
288+
await decorationManager.displayEditSuggestion(
289289
editor,
290290
svgImage,
291291
startLine,
@@ -303,7 +303,7 @@ export async function displaySvgDecoration(
303303
// Move cursor to end of the actual changed content
304304
editor.selection = new vscode.Selection(endPosition, endPosition)
305305

306-
decorationManager.clearDecorations(editor)
306+
await decorationManager.clearDecorations(editor)
307307
const params: LogInlineCompletionSessionResultsParams = {
308308
sessionId: session.sessionId,
309309
completionSessionResult: {
@@ -330,10 +330,10 @@ export async function displaySvgDecoration(
330330
)
331331
}
332332
},
333-
() => {
333+
async () => {
334334
// Handle reject
335335
getLogger().info('Edit suggestion rejected')
336-
decorationManager.clearDecorations(editor)
336+
await decorationManager.clearDecorations(editor)
337337
const params: LogInlineCompletionSessionResultsParams = {
338338
sessionId: session.sessionId,
339339
completionSessionResult: {

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('EditDecorationManager', function () {
5757
sandbox.restore()
5858
})
5959

60-
it('should display SVG decorations in the editor', function () {
60+
it('should display SVG decorations in the editor', async function () {
6161
// Create a fake SVG image URI
6262
const svgUri = vscode.Uri.parse('file:///path/to/image.svg')
6363

@@ -69,7 +69,7 @@ describe('EditDecorationManager', function () {
6969
editorStub.setDecorations.reset()
7070

7171
// Call displayEditSuggestion
72-
manager.displayEditSuggestion(
72+
await manager.displayEditSuggestion(
7373
editorStub as unknown as vscode.TextEditor,
7474
svgUri,
7575
0,
@@ -94,7 +94,7 @@ describe('EditDecorationManager', function () {
9494
})
9595

9696
// Helper function to setup edit suggestion test
97-
function setupEditSuggestionTest() {
97+
async function setupEditSuggestionTest() {
9898
// Create a fake SVG image URI
9999
const svgUri = vscode.Uri.parse('file:///path/to/image.svg')
100100

@@ -103,7 +103,7 @@ describe('EditDecorationManager', function () {
103103
const rejectHandler = sandbox.stub()
104104

105105
// Display the edit suggestion
106-
manager.displayEditSuggestion(
106+
await manager.displayEditSuggestion(
107107
editorStub as unknown as vscode.TextEditor,
108108
svgUri,
109109
0,
@@ -117,8 +117,8 @@ describe('EditDecorationManager', function () {
117117
return { acceptHandler, rejectHandler }
118118
}
119119

120-
it('should trigger accept handler when command is executed', function () {
121-
const { acceptHandler, rejectHandler } = setupEditSuggestionTest()
120+
it('should trigger accept handler when command is executed', async function () {
121+
const { acceptHandler, rejectHandler } = await setupEditSuggestionTest()
122122

123123
// Find the command handler that was registered for accept
124124
const acceptCommandArgs = commandsStub.registerCommand.args.find(
@@ -138,8 +138,8 @@ describe('EditDecorationManager', function () {
138138
}
139139
})
140140

141-
it('should trigger reject handler when command is executed', function () {
142-
const { acceptHandler, rejectHandler } = setupEditSuggestionTest()
141+
it('should trigger reject handler when command is executed', async function () {
142+
const { acceptHandler, rejectHandler } = await setupEditSuggestionTest()
143143

144144
// Find the command handler that was registered for reject
145145
const rejectCommandArgs = commandsStub.registerCommand.args.find(
@@ -159,12 +159,12 @@ describe('EditDecorationManager', function () {
159159
}
160160
})
161161

162-
it('should clear decorations when requested', function () {
162+
it('should clear decorations when requested', async function () {
163163
// Reset the setDecorations stub to clear any previous calls
164164
editorStub.setDecorations.reset()
165165

166166
// Call clearDecorations
167-
manager.clearDecorations(editorStub as unknown as vscode.TextEditor)
167+
await manager.clearDecorations(editorStub as unknown as vscode.TextEditor)
168168

169169
// Verify decorations were cleared
170170
assert.strictEqual(editorStub.setDecorations.callCount, 2)

0 commit comments

Comments
 (0)