Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "coverage-visualizer",
"displayName": "Python Coverage Visualizer",
"description": "Visualize Python test coverage inline in VS Code — highlights, CodeLens, dashboard, and sidebar tree view",
"version": "1.0.1",
"version": "1.0.2",
"publisher": "kool7",
"engines": {
"vscode": "^1.90.0"
Expand Down
13 changes: 13 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ async function handleNoCoverage(workspaceFolder: string) {
proc.on('close', code => {
coverageRunInProgress = false;
coverageOutputChannel!.appendLine(`\n[exited ${code ?? '?'}]`);
if (code !== 0) {
vscode.window.showWarningMessage('pytest failed — check the Coverage Run output panel.');
}
});
} finally {
noCoveragePromptActive = false;
Expand Down Expand Up @@ -230,6 +233,16 @@ async function detectAndParse(

const sqlitePath = path.join(workspaceFolder, '.coverage');
if (fs.existsSync(sqlitePath)) {
const python = resolvePython(workspaceFolder);
const generated = await new Promise<boolean>(resolve => {
exec(`"${python}" -m coverage json`, { cwd: workspaceFolder }, err => resolve(!err));
});
if (generated && fs.existsSync(jsonPath)) {
try {
const raw = JSON.parse(fs.readFileSync(jsonPath, 'utf-8')) as RawCoverageJson;
return { report: parseCoverageJson(raw), formatUsed: 'coverage.json' };
} catch { /* fall through */ }
}
try {
return { report: await parseCoverageSqlite(sqlitePath, workspaceFolder), formatUsed: '.coverage' };
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions src/parsers/coverageParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ export function findFileInReport(
report: CoverageReport,
absolutePath: string
): FileCoverage | undefined {
const normalized = absolutePath.replace(/\\/g, '/');
const normalized = absolutePath.replace(/\\/g, '/').toLowerCase();
return Object.entries(report.files).find(([key]) => {
const normalizedKey = key.replace(/\\/g, '/');
const normalizedKey = key.replace(/\\/g, '/').toLowerCase();
return normalized.endsWith(normalizedKey) || normalized.includes(normalizedKey);
})?.[1];
}
Expand Down
14 changes: 11 additions & 3 deletions src/ui/dashboardPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,17 @@ function colorClass(pct: number, thresholdGood: number, thresholdWarn: number):
function buildHtml(report: CoverageReport, webview?: vscode.Webview, extensionUri?: vscode.Uri): string {
const { thresholdGood, thresholdWarn, excludeTestFiles } = getConfig();

const workspaceRoot = (vscode.workspace.workspaceFolders?.[0]?.uri.fsPath ?? '').replace(/\\/g, '/');

const files = Object.entries(report.files)
.filter(([filePath]) => !excludeTestFiles || !isTestFile(filePath))
.map(([filePath, data]) => ({ filePath, ...data }))
.map(([filePath, data]) => {
const normalized = filePath.replace(/\\/g, '/');
const displayPath = workspaceRoot && normalized.toLowerCase().startsWith(workspaceRoot.toLowerCase())
? normalized.slice(workspaceRoot.length).replace(/^\//, '')
: normalized;
return ({ filePath, displayPath, ...data });
})
.sort((a, b) => a.percentCovered - b.percentCovered);

const coveredStatements = files.reduce((n, f) => n + f.executedLines.length, 0);
Expand All @@ -89,8 +97,8 @@ function buildHtml(report: CoverageReport, webview?: vscode.Webview, extensionUr
const cls = colorClass(f.percentCovered, thresholdGood, thresholdWarn);
const total = f.executedLines.length + f.missingLines.length;
return `
<tr class="file-row" data-path="${f.filePath}" data-name="${f.filePath.toLowerCase()}" data-pct="${f.percentCovered}">
<td class="filename">${f.filePath}</td>
<tr class="file-row" data-path="${f.filePath}" data-name="${f.displayPath.toLowerCase()}" data-pct="${f.percentCovered}">
<td class="filename">${f.displayPath}</td>
<td class="stat">${f.executedLines.length}/${total}</td>
<td class="bar-cell">
<div class="bar-track">
Expand Down
Loading