From 67dc49ef052bbfb1cad5c9d231dbf665c4c03876 Mon Sep 17 00:00:00 2001 From: waleedcodes <110061477+waleedcodes@users.noreply.github.com> Date: Fri, 9 Oct 2026 21:22:20 +0500 Subject: [PATCH 1/3] feat(ui): scaffold ProofCodeCodeActionProvider and quick fix registration --- src/ui/codeActionProvider.ts | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/ui/codeActionProvider.ts diff --git a/src/ui/codeActionProvider.ts b/src/ui/codeActionProvider.ts new file mode 100644 index 0000000..7f38401 --- /dev/null +++ b/src/ui/codeActionProvider.ts @@ -0,0 +1,39 @@ +import * as vscode from 'vscode'; + +export class ProofCodeCodeActionProvider implements vscode.CodeActionProvider { + public static readonly providedCodeActionKinds = [vscode.CodeActionKind.QuickFix]; + + public provideCodeActions( + document: vscode.TextDocument, + _range: vscode.Range | vscode.Selection, + context: vscode.CodeActionContext, + _token: vscode.CancellationToken + ): vscode.CodeAction[] { + const actions: vscode.CodeAction[] = []; + + // Filter diagnostics generated by ProofCode + const proofCodeDiagnostics = context.diagnostics.filter( + (diag) => diag.source === 'ProofCode' + ); + + for (const diag of proofCodeDiagnostics) { + const lineIdx = diag.range.start.line; + const line = document.lineAt(lineIdx); + const lineText = line.text; + const indentMatch = lineText.match(/^\s*/); + const indent = indentMatch ? indentMatch[0] : ''; + + // 1. Quick Fix for PC-REL-006: Unhandled Async Operation + if (diag.code === 'PC-REL-006') { + const action = new vscode.CodeAction( + '🛡️ ProofCode: Wrap in try/catch block', + vscode.CodeActionKind.QuickFix + ); + action.isPreferred = true; + action.diagnostics = [diag]; + + const edit = new vscode.WorkspaceEdit(); + const wrapped = `${indent}try {\n${indent} ${lineText.trim()}\n${indent}} catch (error) {\n${indent} console.error('Async operation failed:', error);\n${indent}}`; + edit.replace(document.uri, line.range, wrapped); + action.edit = edit; + actions.push(action); From 34b8bb946ad0adc994a80f8b4910faf77cf14fe7 Mon Sep 17 00:00:00 2001 From: waleedcodes <110061477+waleedcodes@users.noreply.github.com> Date: Fri, 9 Oct 2026 21:22:20 +0500 Subject: [PATCH 2/3] feat(ui): implement wrap in try/catch quick fix for PC-REL-006 --- src/ui/codeActionProvider.ts | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/ui/codeActionProvider.ts b/src/ui/codeActionProvider.ts index 7f38401..5a450b1 100644 --- a/src/ui/codeActionProvider.ts +++ b/src/ui/codeActionProvider.ts @@ -37,3 +37,48 @@ export class ProofCodeCodeActionProvider implements vscode.CodeActionProvider { edit.replace(document.uri, line.range, wrapped); action.edit = edit; actions.push(action); + } + + // 2. Quick Fix for PC-DATA-001: Unhandled Null/Undefined Database Result + if (diag.code === 'PC-DATA-001') { + // Match variable name from diagnostic message or code line + const varMatch = diag.message.match(/\(([^)]+)\)/); + const varName = varMatch ? varMatch[1] : 'record'; + + // Fix A: Add null guard + const guardAction = new vscode.CodeAction( + `🛡️ ProofCode: Add null guard check (if (!${varName}))`, + vscode.CodeActionKind.QuickFix + ); + guardAction.isPreferred = true; + guardAction.diagnostics = [diag]; + + const guardEdit = new vscode.WorkspaceEdit(); + const guardText = `${indent}if (!${varName}) throw new Error('${varName} not found');\n`; + guardEdit.insert(document.uri, new vscode.Position(lineIdx, 0), guardText); + guardAction.edit = guardEdit; + actions.push(guardAction); + + // Fix B: Use optional chaining + const dotIndex = lineText.indexOf(`${varName}.`); + if (dotIndex !== -1) { + const optChainAction = new vscode.CodeAction( + `🛡️ ProofCode: Use optional chaining (${varName}?.${lineText.slice(dotIndex + varName.length + 1).split(/\W/)[0]})`, + vscode.CodeActionKind.QuickFix + ); + optChainAction.diagnostics = [diag]; + + const optEdit = new vscode.WorkspaceEdit(); + const dotRange = new vscode.Range( + lineIdx, + dotIndex + varName.length, + lineIdx, + dotIndex + varName.length + 1 + ); + optEdit.replace(document.uri, dotRange, '?.'); + optChainAction.edit = optEdit; + actions.push(optChainAction); + } + } + + // 3. Quick Fix for PC-AUTH-001: Missing Authorization Check in API Route From 7932cf13b36976009a28e7ed5b29574ec595dea1 Mon Sep 17 00:00:00 2001 From: waleedcodes <110061477+waleedcodes@users.noreply.github.com> Date: Fri, 9 Oct 2026 21:22:20 +0500 Subject: [PATCH 3/3] feat(ui): implement null guard and session auth insertion quick fixes --- src/ui/codeActionProvider.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/ui/codeActionProvider.ts b/src/ui/codeActionProvider.ts index 5a450b1..4e32c88 100644 --- a/src/ui/codeActionProvider.ts +++ b/src/ui/codeActionProvider.ts @@ -82,3 +82,32 @@ export class ProofCodeCodeActionProvider implements vscode.CodeActionProvider { } // 3. Quick Fix for PC-AUTH-001: Missing Authorization Check in API Route + if (diag.code === 'PC-AUTH-001') { + const authAction = new vscode.CodeAction( + '🛡️ ProofCode: Insert session authentication guard', + vscode.CodeActionKind.QuickFix + ); + authAction.isPreferred = true; + authAction.diagnostics = [diag]; + + const authEdit = new vscode.WorkspaceEdit(); + const authSnippet = `${indent} const session = await auth();\n${indent} if (!session) return new Response('Unauthorized', { status: 401 });\n`; + authEdit.insert(document.uri, new vscode.Position(lineIdx + 1, 0), authSnippet); + authAction.edit = authEdit; + actions.push(authAction); + } + + // 4. Quick Fix for PC-SEC-001: Potential SQL Injection + if (diag.code === 'PC-SEC-001') { + const sqlAction = new vscode.CodeAction( + '🛡️ ProofCode: Review query parameterization guidance', + vscode.CodeActionKind.QuickFix + ); + sqlAction.diagnostics = [diag]; + actions.push(sqlAction); + } + } + + return actions; + } +}