Skip to content

Commit 9919754

Browse files
committed
remove codes for loop debug
1 parent 081ec82 commit 9919754

File tree

2 files changed

+4
-176
lines changed

2 files changed

+4
-176
lines changed

packages/amazonq/src/lsp/autoDebug/controller.ts

Lines changed: 4 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
*/
55

66
import * as vscode from 'vscode'
7-
import { getLogger } from 'aws-core-vscode/shared'
8-
import { ErrorContextFormatter, ErrorContext } from './diagnostics/errorContext'
7+
import { getLogger, randomUUID } from 'aws-core-vscode/shared'
98
import { AutoDebugLspClient } from './lsp/autoDebugLspClient'
10-
import { randomUUID } from 'aws-core-vscode/shared'
119
import { mapDiagnosticSeverity } from './shared/diagnosticUtils'
1210

1311
export interface AutoDebugConfig {
@@ -21,7 +19,6 @@ export interface Problem {
2119
readonly diagnostic: vscode.Diagnostic
2220
readonly severity: 'error' | 'warning' | 'info' | 'hint'
2321
readonly source: string
24-
readonly isNew: boolean
2522
}
2623

2724
/**
@@ -30,7 +27,6 @@ export interface Problem {
3027
*/
3128
export class AutoDebugController implements vscode.Disposable {
3229
private readonly logger = getLogger()
33-
private readonly errorFormatter: ErrorContextFormatter
3430
private readonly lspClient: AutoDebugLspClient
3531
private readonly disposables: vscode.Disposable[] = []
3632

@@ -44,63 +40,16 @@ export class AutoDebugController implements vscode.Disposable {
4440
...config,
4541
}
4642

47-
this.errorFormatter = new ErrorContextFormatter()
4843
this.lspClient = new AutoDebugLspClient(client, encryptionKey)
4944
}
5045

51-
/**
52-
* Creates formatted error contexts for AI debugging
53-
*/
54-
public async createErrorContexts(problems: Problem[]): Promise<ErrorContext[]> {
55-
const contexts: ErrorContext[] = []
56-
57-
for (const problem of problems) {
58-
try {
59-
const context = await this.errorFormatter.createErrorContext(problem)
60-
contexts.push(context)
61-
} catch (error) {
62-
this.logger.warn('AutoDebugController: Failed to create context for problem: %s', error)
63-
}
64-
}
65-
return contexts
66-
}
67-
68-
/**
69-
* Formats problems for display or AI consumption
70-
*/
71-
public formatProblemsForChat(problems: Problem[]): string {
72-
const cwd = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath || process.cwd()
73-
return this.errorFormatter.formatProblemsString(problems, cwd)
74-
}
75-
76-
/**
77-
* Gets the current configuration
78-
*/
79-
public getConfig(): AutoDebugConfig {
80-
return this.config
81-
}
82-
83-
/**
84-
* Updates the configuration
85-
*/
86-
public updateConfig(newConfig: Partial<AutoDebugConfig>): void {
87-
this.config = { ...this.config, ...newConfig }
88-
}
89-
9046
/**
9147
* Sets the language client for LSP communication
9248
*/
9349
public setLanguageClient(client: any): void {
9450
this.lspClient.setLanguageClient(client)
9551
}
9652

97-
/**
98-
* Sends a chat message through the LSP client (public interface)
99-
*/
100-
public async sendChatMessage(message: string, source: string): Promise<void> {
101-
await this.sendMessageToChat(message)
102-
}
103-
10453
/**
10554
* Fix specific problems in the code
10655
*/
@@ -130,12 +79,11 @@ export class AutoDebugController implements vscode.Disposable {
13079
diagnostic,
13180
severity: mapDiagnosticSeverity(diagnostic.severity),
13281
source: diagnostic.source || 'unknown',
133-
isNew: false,
13482
}))
13583

13684
// Create fix message
13785
const fixMessage = this.createFixMessage(filePath, problems)
138-
await this.sendChatMessage(fixMessage, 'specificFix')
86+
await this.sendMessageToChat(fixMessage)
13987
} catch (error) {
14088
this.logger.error('AutoDebugController: Error fixing specific problems: %s', error)
14189
throw error
@@ -183,12 +131,11 @@ export class AutoDebugController implements vscode.Disposable {
183131
diagnostic,
184132
severity: mapDiagnosticSeverity(diagnostic.severity),
185133
source: diagnostic.source || 'unknown',
186-
isNew: false,
187134
}))
188135

189136
// Create fix message
190137
const fixMessage = this.createFixMessage(filePath, problems)
191-
await this.sendChatMessage(fixMessage, 'singleFix')
138+
await this.sendMessageToChat(fixMessage)
192139
} catch (error) {
193140
this.logger.error('AutoDebugController: Error in fix process: %s', error)
194141
}
@@ -223,55 +170,17 @@ export class AutoDebugController implements vscode.Disposable {
223170
diagnostic,
224171
severity: mapDiagnosticSeverity(diagnostic.severity),
225172
source: diagnostic.source || 'unknown',
226-
isNew: false,
227173
}))
228174

229175
// Create explanation message
230176
const explainMessage = this.createExplainMessage(filePath, problems)
231-
await this.sendChatMessage(explainMessage, 'explain')
177+
await this.sendMessageToChat(explainMessage)
232178
} catch (error) {
233179
this.logger.error('AutoDebugController: Error explaining problems: %s', error)
234180
throw error
235181
}
236182
}
237183

238-
/**
239-
* Detect problems in the current file
240-
*/
241-
async detectProblems(): Promise<void> {
242-
try {
243-
const editor = vscode.window.activeTextEditor
244-
if (!editor) {
245-
throw new Error('No active editor found')
246-
}
247-
248-
const filePath = editor.document.uri.fsPath
249-
250-
// Get all diagnostics for the current file
251-
const allDiagnostics = vscode.languages.getDiagnostics(editor.document.uri)
252-
253-
if (allDiagnostics.length === 0) {
254-
return
255-
}
256-
257-
// Convert diagnostics to problems
258-
const problems = allDiagnostics.map((diagnostic) => ({
259-
uri: editor.document.uri,
260-
diagnostic,
261-
severity: mapDiagnosticSeverity(diagnostic.severity),
262-
source: diagnostic.source || 'unknown',
263-
isNew: false,
264-
}))
265-
266-
// Create detection message
267-
const detectMessage = this.createDetectMessage(filePath, problems)
268-
await this.sendChatMessage(detectMessage, 'detect')
269-
} catch (error) {
270-
this.logger.error('AutoDebugController: Error detecting problems: %s', error)
271-
throw error
272-
}
273-
}
274-
275184
private createFixMessage(filePath: string, problems: Problem[]): string {
276185
const parts = [`Please help me fix the following errors in ${filePath}`]
277186

@@ -302,35 +211,6 @@ export class AutoDebugController implements vscode.Disposable {
302211
return parts.join('\n')
303212
}
304213

305-
private createDetectMessage(filePath: string, problems: Problem[]): string {
306-
const errorCount = problems.filter((p) => p.severity === 'error').length
307-
const warningCount = problems.filter((p) => p.severity === 'warning').length
308-
309-
const parts = [`I detected ${problems.length} problems in ${filePath}:`]
310-
311-
if (errorCount > 0) {
312-
parts.push(`- ${errorCount} errors`)
313-
}
314-
if (warningCount > 0) {
315-
parts.push(`- ${warningCount} warnings`)
316-
}
317-
318-
parts.push('\nHere are the details:')
319-
320-
for (const problem of problems.slice(0, 10)) {
321-
// Limit to first 10
322-
const line = problem.diagnostic.range.start.line + 1
323-
const source = problem.source !== 'unknown' ? problem.source : 'Unknown'
324-
parts.push(`${problem.severity.toUpperCase()}: ${problem.diagnostic.message} (Line ${line}, ${source})`)
325-
}
326-
327-
if (problems.length > 10) {
328-
parts.push(`... and ${problems.length - 10} more problems`)
329-
}
330-
331-
return parts.join('\n')
332-
}
333-
334214
/**
335215
* Sends message directly to language server bypassing webview connectors
336216
* This ensures messages go through the proper LSP chat system

packages/amazonq/src/lsp/autoDebug/shared/diagnosticUtils.ts

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55

66
import * as vscode from 'vscode'
77

8-
/**
9-
* Shared utility functions for diagnostic operations across AutoDebug components
10-
*/
11-
128
/**
139
* Maps VSCode DiagnosticSeverity to string representation
1410
*/
@@ -26,51 +22,3 @@ export function mapDiagnosticSeverity(severity: vscode.DiagnosticSeverity): 'err
2622
return 'error'
2723
}
2824
}
29-
30-
/**
31-
* Maps string severity to VSCode DiagnosticSeverity
32-
*/
33-
export function mapSeverityToVSCode(severity: 'error' | 'warning' | 'info' | 'hint'): vscode.DiagnosticSeverity {
34-
switch (severity) {
35-
case 'error':
36-
return vscode.DiagnosticSeverity.Error
37-
case 'warning':
38-
return vscode.DiagnosticSeverity.Warning
39-
case 'info':
40-
return vscode.DiagnosticSeverity.Information
41-
case 'hint':
42-
return vscode.DiagnosticSeverity.Hint
43-
default:
44-
return vscode.DiagnosticSeverity.Error
45-
}
46-
}
47-
48-
/**
49-
* Gets diagnostics for a specific range in a document
50-
*/
51-
export function getDiagnosticsForRange(uri: vscode.Uri, range?: vscode.Range): vscode.Diagnostic[] {
52-
const allDiagnostics = vscode.languages.getDiagnostics(uri)
53-
54-
if (!range) {
55-
return allDiagnostics
56-
}
57-
58-
return allDiagnostics.filter((diagnostic) => diagnostic.range.intersection(range) !== undefined)
59-
}
60-
61-
/**
62-
* Filters diagnostics by severity levels
63-
*/
64-
export function filterDiagnosticsBySeverity(
65-
diagnostics: vscode.Diagnostic[],
66-
severities: vscode.DiagnosticSeverity[]
67-
): vscode.Diagnostic[] {
68-
return diagnostics.filter((diagnostic) => severities.includes(diagnostic.severity))
69-
}
70-
71-
/**
72-
* Gets only error-level diagnostics
73-
*/
74-
export function getErrorDiagnostics(diagnostics: vscode.Diagnostic[]): vscode.Diagnostic[] {
75-
return filterDiagnosticsBySeverity(diagnostics, [vscode.DiagnosticSeverity.Error])
76-
}

0 commit comments

Comments
 (0)