Command 6: let QodeX fix the editor's reported problems in a file (or one diagnostic).
(documentUri?: vscode.Uri, range?: vscode.Range)
| 228 | |
| 229 | /** Command 6: let QodeX fix the editor's reported problems in a file (or one diagnostic). */ |
| 230 | async function fixDiagnostics(documentUri?: vscode.Uri, range?: vscode.Range): Promise<void> { |
| 231 | const uri = documentUri ?? vscode.window.activeTextEditor?.document.uri; |
| 232 | if (!uri) { vscode.window.showWarningMessage('QodeX: no active file.'); return; } |
| 233 | |
| 234 | const { text, count } = collectDiagnostics(uri, range); |
| 235 | if (count === 0) { |
| 236 | vscode.window.showInformationMessage('QodeX: no errors or warnings to fix in this file.'); |
| 237 | return; |
| 238 | } |
| 239 | |
| 240 | const filePath = uri.fsPath; |
| 241 | const scope = range ? `the problem at line ${range.start.line + 1}` : `${count} problem(s)`; |
| 242 | const choice = await vscode.window.showInformationMessage( |
| 243 | `Let QodeX fix ${scope} in ${path.basename(filePath)}? It edits the file on disk — use Undo or git to revert.`, |
| 244 | 'Fix it', 'Cancel', |
| 245 | ); |
| 246 | if (choice !== 'Fix it') return; |
| 247 | |
| 248 | await saveIfOpen(uri); |
| 249 | const prompt = |
| 250 | `Fix the following ${range ? 'problem' : 'problems'} in ${filePath} reported by the editor's language server:\n\n` + |
| 251 | `${text}\n\n` + |
| 252 | `Read the file first. Fix the ROOT CAUSE — don't just silence the symptom or suppress the warning. ` + |
| 253 | `Keep the change minimal and scoped to these issues; do not introduce new ones or refactor unrelated code. ` + |
| 254 | `After editing, verify with the project's typecheck/lint if one is available.`; |
| 255 | |
| 256 | const cfg = getConfig(); |
| 257 | const term = getOrCreateTerminal(getCwd()); |
| 258 | term.sendText(`${cfg.executablePath} ${shellQuote(prompt)}`); |
| 259 | vscode.window.showInformationMessage('QodeX is fixing the problem(s) in the terminal — the file will update on disk when it finishes.'); |
| 260 | } |
| 261 | |
| 262 | /** Command 7: explain the problem(s) at the cursor (read-only — no edits). */ |
| 263 | async function explainDiagnostic(documentUri?: vscode.Uri, range?: vscode.Range): Promise<void> { |
nothing calls this directly
no test coverage detected