Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions src/ui/codeLensProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import * as vscode from 'vscode';
import { VerificationReport } from '../types';

export class ProofCodeCodeLensProvider implements vscode.CodeLensProvider {
private report: VerificationReport | null = null;
private onDidChangeCodeLensesEmitter = new vscode.EventEmitter<void>();
public readonly onDidChangeCodeLenses = this.onDidChangeCodeLensesEmitter.event;

public setReport(report: VerificationReport | null): void {
this.report = report;
this.onDidChangeCodeLensesEmitter.fire();
}

public provideCodeLenses(
document: vscode.TextDocument,
_token: vscode.CancellationToken
): vscode.CodeLens[] {
if (!this.report) return [];

const lenses: vscode.CodeLens[] = [];
const docPath = document.fileName.replace(/\\/g, '/');

// Find symbols in this file from impact analysis
const fileSymbols = this.report.impact.changedSymbols.filter(
(s) => s.filePath.replace(/\\/g, '/') === docPath || docPath.endsWith(s.filePath)
);

// Find risks in this file
const fileRisks = this.report.risks.filter(
(r) => r.file.replace(/\\/g, '/') === docPath || docPath.endsWith(r.file)
);

for (const sym of fileSymbols) {
const callersCount = sym.callers.length;
const untestedCount = sym.callers.filter((c) => !c.hasTest).length;

// Find line number in document for this symbol
for (let i = 0; i < Math.min(document.lineCount, 500); i++) {
const lineText = document.lineAt(i).text;
if (
lineText.includes(`function ${sym.symbolName}`) ||
lineText.includes(`const ${sym.symbolName}`) ||
lineText.includes(`export async function ${sym.symbolName}`) ||
lineText.includes(`export function ${sym.symbolName}`)
) {
const range = new vscode.Range(i, 0, i, lineText.length);
const relatedRisks = fileRisks.filter((r) => r.line >= i + 1 && r.line <= i + 15);

let title = `πŸ›‘οΈ ProofCode: ${callersCount} caller${callersCount === 1 ? '' : 's'}`;
if (untestedCount > 0) {
title += ` (${untestedCount} untested)`;
}
if (relatedRisks.length > 0) {
title += ` | ⚠️ ${relatedRisks.length} risk${relatedRisks.length === 1 ? '' : 's'}`;
}

lenses.push(
new vscode.CodeLens(range, {
title,
command: 'proofcode.openDashboard',
tooltip: 'Click to open ProofCode Change Verification Dashboard'
})
);
break;
}
}
}

return lenses;
}
}
Loading