Skip to content

Commit 010e665

Browse files
committed
fix(amazonq): make code fix's line number or file to be accurate
1 parent 3ce0dec commit 010e665

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
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": "fix bug where code fix line number or file was 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: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ export class SecurityIssueProvider {
4646
...group,
4747
issues: group.issues
4848
.filter((issue) => {
49-
const range = new vscode.Range(
50-
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
54-
)
49+
// event document is the new document after deleting lines, but issue.startLine and endLines are not
50+
let range
51+
if (issue.startLine === issue.endLine) {
52+
range = new vscode.Range(issue.startLine, 0, issue.endLine + 1, 0)
53+
} else {
54+
range = new vscode.Range(issue.startLine, 0, issue.endLine, 0)
55+
}
56+
5557
const intersection = changedRange.intersection(range)
5658
return !(intersection && (/\S/.test(changedText) || changedText === ''))
5759
})

0 commit comments

Comments
 (0)