From beaa287d69ca4b6659c3d278b31bd43fc40bb1ab Mon Sep 17 00:00:00 2001 From: Will Lo Date: Thu, 3 Jul 2025 12:39:41 -0700 Subject: [PATCH 1/2] debug setup --- aws-toolkit-vscode.code-workspace | 3 +++ packages/amazonq/.vscode/launch.json | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/aws-toolkit-vscode.code-workspace b/aws-toolkit-vscode.code-workspace index f03aafae2fe..479f9e8fd66 100644 --- a/aws-toolkit-vscode.code-workspace +++ b/aws-toolkit-vscode.code-workspace @@ -12,6 +12,9 @@ { "path": "packages/amazonq", }, + { + "path": "../language-servers", + }, ], "settings": { "typescript.tsdk": "node_modules/typescript/lib", diff --git a/packages/amazonq/.vscode/launch.json b/packages/amazonq/.vscode/launch.json index b00c5071ce5..cdeabe152a9 100644 --- a/packages/amazonq/.vscode/launch.json +++ b/packages/amazonq/.vscode/launch.json @@ -13,10 +13,10 @@ "args": ["--extensionDevelopmentPath=${workspaceFolder}"], "env": { "SSMDOCUMENT_LANGUAGESERVER_PORT": "6010", - "WEBPACK_DEVELOPER_SERVER": "http://localhost:8080" + "WEBPACK_DEVELOPER_SERVER": "http://localhost:8080", // Below allows for overrides used during development - // "__AMAZONQLSP_PATH": "${workspaceFolder}/../../../language-servers/app/aws-lsp-codewhisperer-runtimes/out/agent-standalone.js", - // "__AMAZONQLSP_UI": "${workspaceFolder}/../../../language-servers/chat-client/build/amazonq-ui.js" + "__AMAZONQLSP_PATH": "${workspaceFolder}/../../../language-servers/app/aws-lsp-codewhisperer-runtimes/out/agent-standalone.js", + "__AMAZONQLSP_UI": "${workspaceFolder}/../../../language-servers/chat-client/build/amazonq-ui.js" }, "envFile": "${workspaceFolder}/.local.env", "outFiles": ["${workspaceFolder}/dist/**/*.js", "${workspaceFolder}/../core/dist/**/*.js"], From 1b77dae96152f1d9b3edf1c65e9c15ee31e52fec Mon Sep 17 00:00:00 2001 From: Will Lo Date: Tue, 8 Jul 2025 01:50:10 -0700 Subject: [PATCH 2/2] fix(amazonq): nep path asynchronous ops are not awaited --- .../app/inline/EditRendering/displayImage.ts | 24 +++++++++---------- .../inline/EditRendering/displayImage.test.ts | 20 ++++++++-------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/amazonq/src/app/inline/EditRendering/displayImage.ts b/packages/amazonq/src/app/inline/EditRendering/displayImage.ts index 2c5986afa51..485dd098a8b 100644 --- a/packages/amazonq/src/app/inline/EditRendering/displayImage.ts +++ b/packages/amazonq/src/app/inline/EditRendering/displayImage.ts @@ -122,19 +122,19 @@ export class EditDecorationManager { /** * Displays an edit suggestion as an SVG image in the editor and highlights removed code */ - public displayEditSuggestion( + public async displayEditSuggestion( editor: vscode.TextEditor, svgImage: vscode.Uri, startLine: number, - onAccept: () => void, - onReject: () => void, + onAccept: () => Promise, + onReject: () => Promise, originalCode: string, newCode: string, originalCodeHighlightRanges: Array<{ line: number; start: number; end: number }> - ): void { - this.clearDecorations(editor) + ): Promise { + await this.clearDecorations(editor) - void setContext('aws.amazonq.editSuggestionActive' as any, true) + await setContext('aws.amazonq.editSuggestionActive' as any, true) this.acceptHandler = onAccept this.rejectHandler = onReject @@ -157,14 +157,14 @@ export class EditDecorationManager { /** * Clears all edit suggestion decorations */ - public clearDecorations(editor: vscode.TextEditor): void { + public async clearDecorations(editor: vscode.TextEditor): Promise { editor.setDecorations(this.imageDecorationType, []) editor.setDecorations(this.removedCodeDecorationType, []) this.currentImageDecoration = undefined this.currentRemovedCodeDecorations = [] this.acceptHandler = undefined this.rejectHandler = undefined - void setContext('aws.amazonq.editSuggestionActive' as any, false) + await setContext('aws.amazonq.editSuggestionActive' as any, false) } /** @@ -285,7 +285,7 @@ export async function displaySvgDecoration( ) { const originalCode = editor.document.getText() - decorationManager.displayEditSuggestion( + await decorationManager.displayEditSuggestion( editor, svgImage, startLine, @@ -303,7 +303,7 @@ export async function displaySvgDecoration( // Move cursor to end of the actual changed content editor.selection = new vscode.Selection(endPosition, endPosition) - decorationManager.clearDecorations(editor) + await decorationManager.clearDecorations(editor) const params: LogInlineCompletionSessionResultsParams = { sessionId: session.sessionId, completionSessionResult: { @@ -330,10 +330,10 @@ export async function displaySvgDecoration( ) } }, - () => { + async () => { // Handle reject getLogger().info('Edit suggestion rejected') - decorationManager.clearDecorations(editor) + await decorationManager.clearDecorations(editor) const params: LogInlineCompletionSessionResultsParams = { sessionId: session.sessionId, completionSessionResult: { diff --git a/packages/amazonq/test/unit/app/inline/EditRendering/displayImage.test.ts b/packages/amazonq/test/unit/app/inline/EditRendering/displayImage.test.ts index df4fac09c28..b88e30487a5 100644 --- a/packages/amazonq/test/unit/app/inline/EditRendering/displayImage.test.ts +++ b/packages/amazonq/test/unit/app/inline/EditRendering/displayImage.test.ts @@ -57,7 +57,7 @@ describe('EditDecorationManager', function () { sandbox.restore() }) - it('should display SVG decorations in the editor', function () { + it('should display SVG decorations in the editor', async function () { // Create a fake SVG image URI const svgUri = vscode.Uri.parse('file:///path/to/image.svg') @@ -69,7 +69,7 @@ describe('EditDecorationManager', function () { editorStub.setDecorations.reset() // Call displayEditSuggestion - manager.displayEditSuggestion( + await manager.displayEditSuggestion( editorStub as unknown as vscode.TextEditor, svgUri, 0, @@ -94,7 +94,7 @@ describe('EditDecorationManager', function () { }) // Helper function to setup edit suggestion test - function setupEditSuggestionTest() { + async function setupEditSuggestionTest() { // Create a fake SVG image URI const svgUri = vscode.Uri.parse('file:///path/to/image.svg') @@ -103,7 +103,7 @@ describe('EditDecorationManager', function () { const rejectHandler = sandbox.stub() // Display the edit suggestion - manager.displayEditSuggestion( + await manager.displayEditSuggestion( editorStub as unknown as vscode.TextEditor, svgUri, 0, @@ -117,8 +117,8 @@ describe('EditDecorationManager', function () { return { acceptHandler, rejectHandler } } - it('should trigger accept handler when command is executed', function () { - const { acceptHandler, rejectHandler } = setupEditSuggestionTest() + it('should trigger accept handler when command is executed', async function () { + const { acceptHandler, rejectHandler } = await setupEditSuggestionTest() // Find the command handler that was registered for accept const acceptCommandArgs = commandsStub.registerCommand.args.find( @@ -138,8 +138,8 @@ describe('EditDecorationManager', function () { } }) - it('should trigger reject handler when command is executed', function () { - const { acceptHandler, rejectHandler } = setupEditSuggestionTest() + it('should trigger reject handler when command is executed', async function () { + const { acceptHandler, rejectHandler } = await setupEditSuggestionTest() // Find the command handler that was registered for reject const rejectCommandArgs = commandsStub.registerCommand.args.find( @@ -159,12 +159,12 @@ describe('EditDecorationManager', function () { } }) - it('should clear decorations when requested', function () { + it('should clear decorations when requested', async function () { // Reset the setDecorations stub to clear any previous calls editorStub.setDecorations.reset() // Call clearDecorations - manager.clearDecorations(editorStub as unknown as vscode.TextEditor) + await manager.clearDecorations(editorStub as unknown as vscode.TextEditor) // Verify decorations were cleared assert.strictEqual(editorStub.setDecorations.callCount, 2)