Skip to content

Commit dd14b98

Browse files
authored
fix(amazonq): make code fix's line number or file to be accurate (aws#7023)
## Problem 1. `document.lineAt` would error due to line out of bounds. 2. File uploaded for codeFix is not the same as the one in editor ## Solution 1. Remove `document.lineAt` logic 2. Ensure dirty file is saved before zipping. --- - 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 4c0d098 commit dd14b98

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Code fix line number or file is sometimes not accurate"
4+
}

packages/core/src/codewhisperer/commands/startCodeFixGeneration.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { TelemetryHelper } from '../util/telemetryHelper'
2020
import { tempDirPath } from '../../shared/filesystemUtilities'
2121
import { CodeWhispererSettings } from '../util/codewhispererSettings'
2222
import { AuthUtil } from '../util/authUtil'
23+
import { saveDocumentIfDirty } from '../../shared/utilities/textDocumentUtilities'
2324

2425
export async function startCodeFixGeneration(
2526
client: DefaultCodeWhispererClient,
@@ -44,6 +45,9 @@ export async function startCodeFixGeneration(
4445
* Step 1: Generate zip
4546
*/
4647
throwIfCancelled()
48+
49+
// Save the file if it has unsaved changes to ensure the latest content is included in the zip
50+
await saveDocumentIfDirty(filePath)
4751
const admZip = new AdmZip()
4852
admZip.addLocalFile(filePath)
4953

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ export class SecurityIssueProvider {
4848
.filter((issue) => {
4949
const range = new vscode.Range(
5050
issue.startLine,
51-
event.document.lineAt(issue.startLine)?.range.start.character ?? 0,
52-
issue.endLine,
53-
event.document.lineAt(issue.endLine - 1)?.range.end.character ?? 0
51+
0,
52+
issue.startLine === issue.endLine ? issue.endLine + 1 : issue.endLine,
53+
0
5454
)
55+
5556
const intersection = changedRange.intersection(range)
5657
return !(intersection && (/\S/.test(changedText) || changedText === ''))
5758
})

0 commit comments

Comments
 (0)