@@ -7,27 +7,23 @@ import * as vscode from 'vscode'
77import { getLogger , randomUUID } from 'aws-core-vscode/shared'
88import { AutoDebugLspClient } from './lsp/autoDebugLspClient'
99import { mapDiagnosticSeverity } from './shared/diagnosticUtils'
10+ import { ErrorContextFormatter } from './diagnostics/errorContext'
11+ import { Problem } from './diagnostics/problemDetector'
1012
1113export interface AutoDebugConfig {
1214 readonly enabled : boolean
1315 readonly excludedSources : string [ ]
1416 readonly severityFilter : ( 'error' | 'warning' | 'info' | 'hint' ) [ ]
1517}
1618
17- export interface Problem {
18- readonly uri : vscode . Uri
19- readonly diagnostic : vscode . Diagnostic
20- readonly severity : 'error' | 'warning' | 'info' | 'hint'
21- readonly source : string
22- }
23-
2419/**
2520 * Simplified controller for Amazon Q Auto Debug system.
2621 * Focuses on context menu and quick fix functionality without workspace-wide monitoring.
2722 */
2823export class AutoDebugController implements vscode . Disposable {
2924 private readonly logger = getLogger ( )
3025 private readonly lspClient : AutoDebugLspClient
26+ private readonly errorFormatter : ErrorContextFormatter
3127 private readonly disposables : vscode . Disposable [ ] = [ ]
3228
3329 private config : AutoDebugConfig
@@ -41,6 +37,7 @@ export class AutoDebugController implements vscode.Disposable {
4137 }
4238
4339 this . lspClient = new AutoDebugLspClient ( client , encryptionKey )
40+ this . errorFormatter = new ErrorContextFormatter ( )
4441 }
4542
4643 /**
@@ -79,6 +76,7 @@ export class AutoDebugController implements vscode.Disposable {
7976 diagnostic,
8077 severity : mapDiagnosticSeverity ( diagnostic . severity ) ,
8178 source : diagnostic . source || 'unknown' ,
79+ isNew : false ,
8280 } ) )
8381
8482 // Create fix message
@@ -131,6 +129,7 @@ export class AutoDebugController implements vscode.Disposable {
131129 diagnostic,
132130 severity : mapDiagnosticSeverity ( diagnostic . severity ) ,
133131 source : diagnostic . source || 'unknown' ,
132+ isNew : false ,
134133 } ) )
135134
136135 // Create fix message
@@ -170,6 +169,7 @@ export class AutoDebugController implements vscode.Disposable {
170169 diagnostic,
171170 severity : mapDiagnosticSeverity ( diagnostic . severity ) ,
172171 source : diagnostic . source || 'unknown' ,
172+ isNew : false ,
173173 } ) )
174174
175175 // Create explanation message
@@ -182,35 +182,17 @@ export class AutoDebugController implements vscode.Disposable {
182182 }
183183
184184 private createFixMessage ( filePath : string , problems : Problem [ ] ) : string {
185- const parts = [ `Please help me fix the following errors in ${ filePath } ` ]
186-
187- for ( const problem of problems ) {
188- const line = problem . diagnostic . range . start . line + 1
189- const column = problem . diagnostic . range . start . character + 1
190- const source = problem . source !== 'unknown' ? problem . source : 'Unknown'
191- parts . push (
192- `ERROR: ${ problem . diagnostic . message } Location: Line ${ line } , Column ${ column } Source: ${ source } `
193- )
194- }
185+ const workspaceRoot = vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath || ''
186+ const formattedProblems = this . errorFormatter . formatProblemsString ( problems , workspaceRoot )
195187
196- return parts . join ( '\n' )
188+ return `Please help me fix the following errors in ${ filePath } : ${ formattedProblems } `
197189 }
198190
199191 private createExplainMessage ( filePath : string , problems : Problem [ ] ) : string {
200- const parts = [
201- `Please explain the following problems in ${ filePath } . DO NOT edit files. ONLY provide explanation` ,
202- ]
203-
204- for ( const problem of problems ) {
205- const line = problem . diagnostic . range . start . line + 1
206- const column = problem . diagnostic . range . start . character + 1
207- const source = problem . source !== 'unknown' ? problem . source : 'Unknown'
208- parts . push (
209- `${ problem . severity . toUpperCase ( ) } : ${ problem . diagnostic . message } Location: Line ${ line } , Column ${ column } Source: ${ source } `
210- )
211- }
192+ const workspaceRoot = vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath || ''
193+ const formattedProblems = this . errorFormatter . formatProblemsString ( problems , workspaceRoot )
212194
213- return parts . join ( '\n' )
195+ return `Please explain the following problems in ${ filePath } . DO NOT edit files. ONLY provide explanation: ${ formattedProblems } `
214196 }
215197
216198 /**
0 commit comments