Skip to content

Commit 081ec82

Browse files
committed
simplify the code base
1 parent 3679ce6 commit 081ec82

File tree

5 files changed

+5
-132
lines changed

5 files changed

+5
-132
lines changed

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

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

66
import * as vscode from 'vscode'
7-
import { Commands, getLogger } from 'aws-core-vscode/shared'
7+
import { Commands, getLogger, messages } from 'aws-core-vscode/shared'
88
import { focusAmazonQPanel } from 'aws-core-vscode/codewhispererChat'
99
import { placeholder } from 'aws-core-vscode/shared'
1010
import { AutoDebugController } from './controller'
@@ -31,7 +31,6 @@ export class AutoDebugCommands implements vscode.Disposable {
3131
{
3232
id: 'amazonq.01.fixWithQ',
3333
name: 'Amazon Q: Fix Problem',
34-
telemetryName: 'amazonq_openChat',
3534
},
3635
async (range?: vscode.Range, diagnostics?: vscode.Diagnostic[]) => {
3736
await this.fixWithAmazonQ(range, diagnostics)
@@ -43,7 +42,6 @@ export class AutoDebugCommands implements vscode.Disposable {
4342
{
4443
id: 'amazonq.02.fixAllWithQ',
4544
name: 'Amazon Q: Fix All Errors',
46-
telemetryName: 'amazonq_openChat',
4745
},
4846
async () => {
4947
await this.fixAllWithAmazonQ()
@@ -55,7 +53,6 @@ export class AutoDebugCommands implements vscode.Disposable {
5553
{
5654
id: 'amazonq.03.explainProblem',
5755
name: 'Amazon Q: Explain Problem',
58-
telemetryName: 'amazonq_openChat',
5956
},
6057
async (range?: vscode.Range, diagnostics?: vscode.Diagnostic[]) => {
6158
await this.explainProblem(range, diagnostics)
@@ -84,9 +81,7 @@ export class AutoDebugCommands implements vscode.Disposable {
8481
await this.controller.fixSpecificProblems(range, diagnostics)
8582
} catch (error) {
8683
this.logger.error('AutoDebugCommands: Error in Fix with Amazon Q: %s', error)
87-
void vscode.window.showErrorMessage(
88-
'Amazon Q was not able to fix or explain the problem. Try again shortly'
89-
)
84+
void messages.showMessage('error', 'Amazon Q was not able to fix or explain the problem. Try again shortly')
9085
}
9186
}
9287

@@ -107,9 +102,7 @@ export class AutoDebugCommands implements vscode.Disposable {
107102
await this.controller.fixAllProblemsInFile(10) // 10 errors per batch
108103
} catch (error) {
109104
this.logger.error('AutoDebugCommands: Error in Fix All with Amazon Q: %s', error)
110-
void vscode.window.showErrorMessage(
111-
'Amazon Q was not able to fix or explain the problem. Try again shortly'
112-
)
105+
void messages.showMessage('error', 'Amazon Q was not able to fix or explain the problem. Try again shortly')
113106
}
114107
}
115108

@@ -131,9 +124,7 @@ export class AutoDebugCommands implements vscode.Disposable {
131124
await this.controller.explainProblems(range, diagnostics)
132125
} catch (error) {
133126
this.logger.error('AutoDebugCommands: Error explaining problem: %s', error)
134-
void vscode.window.showErrorMessage(
135-
'Amazon Q was not able to fix or explain the problem. Try again shortly'
136-
)
127+
void messages.showMessage('error', 'Amazon Q was not able to fix or explain the problem. Try again shortly')
137128
}
138129
}
139130

packages/amazonq/src/lsp/autoDebug/diagnostics/diagnosticsMonitor.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ export class DiagnosticsMonitor implements vscode.Disposable {
3131
private readonly logger = getLogger()
3232
private readonly diagnosticsChangeEmitter = new vscode.EventEmitter<DiagnosticCollection>()
3333
private readonly disposables: vscode.Disposable[] = []
34-
private lastDiagnostics: DiagnosticCollection | undefined
3534
private debounceTimer: NodeJS.Timeout | undefined
3635
private readonly debounceDelayMs = 500
3736

3837
public readonly onDiagnosticsChanged = this.diagnosticsChangeEmitter.event
3938

4039
constructor() {
41-
// Monitor diagnostic changes from all language servers
4240
this.disposables.push(
4341
vscode.languages.onDidChangeDiagnostics((event) => {
4442
this.handleDiagnosticChange(event)
@@ -55,13 +53,6 @@ export class DiagnosticsMonitor implements vscode.Disposable {
5553
const currentDiagnostics = this.collectAllDiagnostics()
5654

5755
if (!shouldWaitForChanges) {
58-
this.lastDiagnostics = currentDiagnostics
59-
return currentDiagnostics
60-
}
61-
62-
// Check if diagnostics have changed since last collection
63-
if (!this.lastDiagnostics || !this.areDiagnosticsEqual(this.lastDiagnostics, currentDiagnostics)) {
64-
this.lastDiagnostics = currentDiagnostics
6556
return currentDiagnostics
6657
}
6758

@@ -124,13 +115,6 @@ export class DiagnosticsMonitor implements vscode.Disposable {
124115
captureTime: Date.now(),
125116
id: this.generateSnapshotId(),
126117
}
127-
128-
this.logger.debug(
129-
'DiagnosticsMonitor: Captured baseline with %d files, id=%s',
130-
diagnostics.diagnostics.length,
131-
snapshot.id
132-
)
133-
134118
return snapshot
135119
}
136120

@@ -161,13 +145,6 @@ export class DiagnosticsMonitor implements vscode.Disposable {
161145

162146
private processDiagnosticChange(event: vscode.DiagnosticChangeEvent): void {
163147
try {
164-
const currentDiagnostics = this.collectAllDiagnostics()
165-
166-
// Only emit if diagnostics actually changed
167-
if (!this.lastDiagnostics || !this.areDiagnosticsEqual(this.lastDiagnostics, currentDiagnostics)) {
168-
this.lastDiagnostics = currentDiagnostics
169-
this.diagnosticsChangeEmitter.fire(currentDiagnostics)
170-
}
171148
} catch (error) {
172149
this.logger.error('DiagnosticsMonitor: Error processing diagnostic change: %s', error)
173150
}
@@ -208,19 +185,6 @@ export class DiagnosticsMonitor implements vscode.Disposable {
208185
})
209186
})
210187
}
211-
212-
private areDiagnosticsEqual(a: DiagnosticCollection, b: DiagnosticCollection): boolean {
213-
if (a.diagnostics.length !== b.diagnostics.length) {
214-
return false
215-
}
216-
217-
// Simple comparison - could be optimized for performance
218-
const aStr = JSON.stringify(a.diagnostics.map(([uri, diags]) => [uri.toString(), diags]))
219-
const bStr = JSON.stringify(b.diagnostics.map(([uri, diags]) => [uri.toString(), diags]))
220-
221-
return aStr === bStr
222-
}
223-
224188
private generateSnapshotId(): string {
225189
return `snapshot_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
226190
}

packages/amazonq/src/lsp/autoDebug/diagnostics/errorContext.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ export interface FormattedErrorReport {
3636
*/
3737
export class ErrorContextFormatter {
3838
private readonly logger = getLogger()
39-
40-
constructor() {
41-
this.logger.debug('ErrorContextFormatter: Initializing error context formatter')
42-
}
43-
4439
/**
4540
* Converts a Problem to detailed ErrorContext
4641
*/

packages/amazonq/src/lsp/autoDebug/diagnostics/problemDetector.ts

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as vscode from 'vscode'
77
import * as path from 'path'
8-
import { DiagnosticCollection, DiagnosticSnapshot } from './diagnosticsMonitor'
8+
import { DiagnosticCollection } from './diagnosticsMonitor'
99
import { mapDiagnosticSeverity } from '../shared/diagnosticUtils'
1010

1111
export interface Problem {
@@ -27,25 +27,6 @@ export interface CategorizedProblems {
2727
* Detects new problems by comparing diagnostic snapshots and filtering relevant issues.
2828
*/
2929
export class ProblemDetector {
30-
/**
31-
* Detects new problems by comparing baseline and current diagnostics
32-
*/
33-
public detectNewProblems(baseline: DiagnosticSnapshot, current: DiagnosticSnapshot): Problem[] {
34-
const newProblems: Problem[] = []
35-
const baselineMap = this.createDiagnosticMap(baseline.diagnostics)
36-
37-
for (const [uri, currentDiagnostics] of current.diagnostics.diagnostics) {
38-
const baselineDiagnostics = baselineMap.get(uri.toString()) || []
39-
40-
for (const diagnostic of currentDiagnostics) {
41-
if (!this.isDiagnosticInBaseline(diagnostic, baselineDiagnostics)) {
42-
newProblems.push(this.createProblem(uri, diagnostic, true))
43-
}
44-
}
45-
}
46-
return newProblems
47-
}
48-
4930
/**
5031
* Filters problems to only include those relevant to changed files
5132
*/
@@ -122,51 +103,6 @@ export class ProblemDetector {
122103
return problems.filter((problem) => problem.severity === 'error')
123104
}
124105

125-
/**
126-
* Checks if two diagnostic snapshots have the same problems
127-
*/
128-
public areProblemsEqual(a: DiagnosticSnapshot, b: DiagnosticSnapshot): boolean {
129-
const problemsA = this.getAllProblems(a.diagnostics)
130-
const problemsB = this.getAllProblems(b.diagnostics)
131-
132-
if (problemsA.length !== problemsB.length) {
133-
return false
134-
}
135-
136-
// Simple comparison - could be optimized
137-
const sigA = this.createProblemSignature(problemsA)
138-
const sigB = this.createProblemSignature(problemsB)
139-
140-
return sigA === sigB
141-
}
142-
143-
private createDiagnosticMap(diagnostics: DiagnosticCollection): Map<string, vscode.Diagnostic[]> {
144-
const map = new Map<string, vscode.Diagnostic[]>()
145-
146-
for (const [uri, fileDiagnostics] of diagnostics.diagnostics) {
147-
map.set(uri.toString(), fileDiagnostics)
148-
}
149-
150-
return map
151-
}
152-
153-
private isDiagnosticInBaseline(diagnostic: vscode.Diagnostic, baselineDiagnostics: vscode.Diagnostic[]): boolean {
154-
return baselineDiagnostics.some((baseline) => this.areDiagnosticsEqual(diagnostic, baseline))
155-
}
156-
157-
private areDiagnosticsEqual(a: vscode.Diagnostic, b: vscode.Diagnostic): boolean {
158-
return (
159-
a.message === b.message &&
160-
a.severity === b.severity &&
161-
a.source === b.source &&
162-
a.code === b.code &&
163-
a.range.start.line === b.range.start.line &&
164-
a.range.start.character === b.range.start.character &&
165-
a.range.end.line === b.range.end.line &&
166-
a.range.end.character === b.range.end.character
167-
)
168-
}
169-
170106
private createProblem(uri: vscode.Uri, diagnostic: vscode.Diagnostic, isNew: boolean): Problem {
171107
return {
172108
uri,
@@ -198,15 +134,4 @@ export class ProblemDetector {
198134

199135
return false
200136
}
201-
202-
private createProblemSignature(problems: Problem[]): string {
203-
const signatures = problems
204-
.map(
205-
(problem) =>
206-
`${problem.uri.toString()}:${problem.diagnostic.range.start.line}:${problem.diagnostic.range.start.character}:${problem.diagnostic.message}:${problem.severity}`
207-
)
208-
.sort()
209-
210-
return signatures.join('|')
211-
}
212137
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ export class AutoDebugLspClient {
123123
autoSubmit: true, // Automatically submit the message
124124
},
125125
})
126-
127-
this.logger.debug('AutoDebugLspClient: Successfully sent message via webview postMessage')
128126
return true
129127
} catch (error) {
130128
this.logger.error('AutoDebugLspClient: Error sending message via webview: %s', error)

0 commit comments

Comments
 (0)