diff --git a/packages/amazonq/.changes/next-release/Bug Fix-42b2c2f0-e40e-4f97-842b-cb7ead1a010b.json b/packages/amazonq/.changes/next-release/Bug Fix-42b2c2f0-e40e-4f97-842b-cb7ead1a010b.json new file mode 100644 index 00000000000..ca8f9878401 --- /dev/null +++ b/packages/amazonq/.changes/next-release/Bug Fix-42b2c2f0-e40e-4f97-842b-cb7ead1a010b.json @@ -0,0 +1,4 @@ +{ + "type": "Bug Fix", + "description": "Code fix line number or file is sometimes not accurate" +} diff --git a/packages/core/src/codewhisperer/commands/startCodeFixGeneration.ts b/packages/core/src/codewhisperer/commands/startCodeFixGeneration.ts index 9dc2fd5f68f..f0118eef46a 100644 --- a/packages/core/src/codewhisperer/commands/startCodeFixGeneration.ts +++ b/packages/core/src/codewhisperer/commands/startCodeFixGeneration.ts @@ -20,6 +20,7 @@ import { TelemetryHelper } from '../util/telemetryHelper' import { tempDirPath } from '../../shared/filesystemUtilities' import { CodeWhispererSettings } from '../util/codewhispererSettings' import { AuthUtil } from '../util/authUtil' +import { saveDocumentIfDirty } from '../../shared/utilities/textDocumentUtilities' export async function startCodeFixGeneration( client: DefaultCodeWhispererClient, @@ -44,6 +45,9 @@ export async function startCodeFixGeneration( * Step 1: Generate zip */ throwIfCancelled() + + // Save the file if it has unsaved changes to ensure the latest content is included in the zip + await saveDocumentIfDirty(filePath) const admZip = new AdmZip() admZip.addLocalFile(filePath) diff --git a/packages/core/src/codewhisperer/service/securityIssueProvider.ts b/packages/core/src/codewhisperer/service/securityIssueProvider.ts index 4e1662753e4..61957e6eca5 100644 --- a/packages/core/src/codewhisperer/service/securityIssueProvider.ts +++ b/packages/core/src/codewhisperer/service/securityIssueProvider.ts @@ -48,10 +48,11 @@ export class SecurityIssueProvider { .filter((issue) => { const range = new vscode.Range( issue.startLine, - event.document.lineAt(issue.startLine)?.range.start.character ?? 0, - issue.endLine, - event.document.lineAt(issue.endLine - 1)?.range.end.character ?? 0 + 0, + issue.startLine === issue.endLine ? issue.endLine + 1 : issue.endLine, + 0 ) + const intersection = changedRange.intersection(range) return !(intersection && (/\S/.test(changedText) || changedText === '')) })