Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Bug Fix",
"description": "Amazon Q: \"Fix All Issues\" now includes warnings when triggered from a warning diagnostic"
}
19 changes: 14 additions & 5 deletions packages/amazonq/src/lsp/chat/autoDebug/codeActionsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,16 @@ export class AutoDebugCodeActionsProvider implements vscode.CodeActionProvider,
// Add "Fix with Amazon Q" action
actions.push(this.createFixWithQAction(document, range, diagnostics))

// Add "Fix All with Amazon Q" action
actions.push(this.createFixAllWithQAction(document))
// Check if any diagnostic is error or warning to show "Fix All Issues"
const hasErrorOrWarning = diagnostics.some(
(d) =>
d.severity === vscode.DiagnosticSeverity.Error || d.severity === vscode.DiagnosticSeverity.Warning
)
if (hasErrorOrWarning) {
// If triggered from warning, include warnings; if from error, only errors
const hasWarning = diagnostics.some((d) => d.severity === vscode.DiagnosticSeverity.Warning)
actions.push(this.createFixAllWithQAction(document, hasWarning))
}

// Add "Explain Problem" action
actions.push(this.createExplainProblemAction(document, range, diagnostics))
Expand Down Expand Up @@ -84,12 +92,13 @@ export class AutoDebugCodeActionsProvider implements vscode.CodeActionProvider,
return action
}

private createFixAllWithQAction(document: vscode.TextDocument): vscode.CodeAction {
const action = new vscode.CodeAction('Amazon Q: Fix All Errors', vscode.CodeActionKind.QuickFix)
private createFixAllWithQAction(document: vscode.TextDocument, includeWarnings: boolean): vscode.CodeAction {
const action = new vscode.CodeAction('Amazon Q: Fix All Issues', vscode.CodeActionKind.QuickFix)

action.command = {
command: 'amazonq.02.fixAllWithQ',
title: 'Amazon Q: Fix All Errors',
title: 'Amazon Q: Fix All Issues',
arguments: [includeWarnings],
}

return action
Expand Down
13 changes: 7 additions & 6 deletions packages/amazonq/src/lsp/chat/autoDebug/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export class AutoDebugCommands implements vscode.Disposable {
Commands.register(
{
id: 'amazonq.02.fixAllWithQ',
name: 'Amazon Q: Fix All Errors',
name: 'Amazon Q: Fix All Issues',
},
async () => {
await this.fixAllWithAmazonQ()
async (includeWarnings?: boolean) => {
await this.fixAllWithAmazonQ(includeWarnings)
}
),

Expand Down Expand Up @@ -124,9 +124,10 @@ export class AutoDebugCommands implements vscode.Disposable {
}

/**
* Fix All with Amazon Q - processes all errors in the current file
* Fix All with Amazon Q - processes issues in the current file
* @param includeWarnings - if true, fix errors and warnings; if false, fix only errors
*/
private async fixAllWithAmazonQ(): Promise<void> {
private async fixAllWithAmazonQ(includeWarnings: boolean = false): Promise<void> {
autoDebugTelemetry.recordCommandInvocation('fixAllWithQ')

await this.executeWithErrorHandling(
Expand All @@ -139,7 +140,7 @@ export class AutoDebugCommands implements vscode.Disposable {
if (!saved) {
throw new Error('Failed to save document')
}
const problemCount = await this.controller.fixAllProblemsInFile(10) // 10 errors per batch
const problemCount = await this.controller.fixAllProblemsInFile(includeWarnings)
autoDebugTelemetry.recordCommandSuccess('fixAllWithQ', problemCount)
},
'Fix All with Amazon Q',
Expand Down
23 changes: 14 additions & 9 deletions packages/amazonq/src/lsp/chat/autoDebug/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,14 @@ export class AutoDebugController implements vscode.Disposable {
}

/**
* Filter diagnostics to only errors and apply source filtering
* Filter diagnostics by severity and apply source filtering
*/
private filterErrorDiagnostics(diagnostics: vscode.Diagnostic[]): vscode.Diagnostic[] {
private filterDiagnostics(diagnostics: vscode.Diagnostic[], includeWarnings: boolean = false): vscode.Diagnostic[] {
return diagnostics.filter((d) => {
if (d.severity !== vscode.DiagnosticSeverity.Error) {
// Filter by severity: errors always, warnings only if includeWarnings
const isError = d.severity === vscode.DiagnosticSeverity.Error
const isWarning = d.severity === vscode.DiagnosticSeverity.Warning
if (!isError && !(includeWarnings && isWarning)) {
return false
}
// Apply source filtering
Expand Down Expand Up @@ -108,9 +111,11 @@ export class AutoDebugController implements vscode.Disposable {
}

/**
* Fix with Amazon Q - sends up to 15 error messages one time when user clicks the button
* Fix with Amazon Q - sends up to maxProblems issues when user clicks the button
* @param includeWarnings - if true, fix both errors and warnings; if false, fix only errors
* @param maxProblems - maximum number of problems to fix (default 10)
*/
public async fixAllProblemsInFile(maxProblems: number = 15): Promise<number> {
public async fixAllProblemsInFile(includeWarnings: boolean = false, maxProblems: number = 10): Promise<number> {
try {
const editor = vscode.window.activeTextEditor
if (!editor) {
Expand All @@ -120,13 +125,13 @@ export class AutoDebugController implements vscode.Disposable {

// Get all diagnostics for the current file
const allDiagnostics = vscode.languages.getDiagnostics(editor.document.uri)
const errorDiagnostics = this.filterErrorDiagnostics(allDiagnostics)
if (errorDiagnostics.length === 0) {
const filteredDiagnostics = this.filterDiagnostics(allDiagnostics, includeWarnings)
if (filteredDiagnostics.length === 0) {
return 0
}

// Take up to maxProblems errors (15 by default)
const diagnosticsToFix = errorDiagnostics.slice(0, maxProblems)
// Take up to maxProblems
const diagnosticsToFix = filteredDiagnostics.slice(0, maxProblems)
const result = await this.getProblemsFromDiagnostics(undefined, diagnosticsToFix)
if (!result) {
return 0
Expand Down
Loading