Compare commits
No commits in common. "main" and "0.1.0" have entirely different histories.
25
package.json
25
package.json
@ -3,7 +3,7 @@
|
|||||||
"displayName": "Coverage Tool",
|
"displayName": "Coverage Tool",
|
||||||
"publisher": "justinbossis",
|
"publisher": "justinbossis",
|
||||||
"description": "Highlights coverage.py lines in VSCode",
|
"description": "Highlights coverage.py lines in VSCode",
|
||||||
"version": "0.2.1",
|
"version": "0.1.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"vscode": "^1.92.0"
|
"vscode": "^1.92.0"
|
||||||
},
|
},
|
||||||
@ -68,29 +68,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"viewsContainers": {
|
|
||||||
"activitybar": [
|
|
||||||
{
|
|
||||||
"id": "coveragetool",
|
|
||||||
"title": "Coverage Tool",
|
|
||||||
"icon": "resources/icon.svg"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"views": {
|
|
||||||
"coveragetool": [
|
|
||||||
{
|
|
||||||
"id": "coveragetoolView",
|
|
||||||
"name": "Coverage Tool",
|
|
||||||
"order": 10,
|
|
||||||
"icon": "resources/icon.svg"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"commands": [
|
"commands": [
|
||||||
{
|
{
|
||||||
"command": "coveragetool.refreshEntry",
|
"command": "coverage-tool.helloWorld",
|
||||||
"title": "Refresh Coverage"
|
"title": "Hello World"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,7 +0,0 @@
|
|||||||
<svg width="24" height="24" viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<rect x="12" y="10" width="40" height="48" rx="4" ry="4" fill="none" stroke="#000" stroke-width="4"/>
|
|
||||||
<line x1="18" y1="20" x2="46" y2="20" stroke="#000" stroke-width="4"/>
|
|
||||||
<line x1="18" y1="28" x2="40" y2="28" stroke="#000" stroke-width="4"/>
|
|
||||||
<line x1="18" y1="36" x2="34" y2="36" stroke="#000" stroke-width="4"/>
|
|
||||||
<path d="M24 44 L30 50 L44 36" fill="none" stroke="#000" stroke-width="4"/>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 492 B |
@ -16,7 +16,6 @@ function createDecor(bgColor: string) {
|
|||||||
isWholeLine: true,
|
isWholeLine: true,
|
||||||
overviewRulerLane: OverviewRulerLane.Full,
|
overviewRulerLane: OverviewRulerLane.Full,
|
||||||
overviewRulerColor: bgColor.replace(RegExp(/0\.(\d+)/), '0.8'),
|
overviewRulerColor: bgColor.replace(RegExp(/0\.(\d+)/), '0.8'),
|
||||||
rangeBehavior: 1,
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,19 +0,0 @@
|
|||||||
import { TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
|
|
||||||
|
|
||||||
export default class CoverageFile extends TreeItem {
|
|
||||||
constructor(
|
|
||||||
public readonly label: string,
|
|
||||||
public readonly relativePath: string,
|
|
||||||
public readonly filePath: string,
|
|
||||||
public readonly numberOfLines: number,
|
|
||||||
public readonly collapsibleState: TreeItemCollapsibleState,
|
|
||||||
) {
|
|
||||||
super(label, collapsibleState);
|
|
||||||
this.description = `${numberOfLines} missing lines | ${relativePath}`;
|
|
||||||
this.command = {
|
|
||||||
command: 'vscode.open',
|
|
||||||
title: '',
|
|
||||||
arguments: [Uri.file(this.filePath)],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -9,7 +9,6 @@ import CoverageStatusBarItem from './statusBar/CoverageStatusBarItem';
|
|||||||
import { CoverageStats, ICoverageCache, ICoverageStatsJson, IFileDecorationCache, IFileDecorationRange } from './models';
|
import { CoverageStats, ICoverageCache, ICoverageStatsJson, IFileDecorationCache, IFileDecorationRange } from './models';
|
||||||
import Logger from './util/Logger';
|
import Logger from './util/Logger';
|
||||||
import Configs from './config/Configs';
|
import Configs from './config/Configs';
|
||||||
import CoverageFile from './coverageitem';
|
|
||||||
|
|
||||||
// Promisified Functions
|
// Promisified Functions
|
||||||
const readFileAsync = promisify(readFile);
|
const readFileAsync = promisify(readFile);
|
||||||
@ -22,7 +21,6 @@ const isWindows = platform() === 'win32';
|
|||||||
let fileWatchers: vscode.FileSystemWatcher[] = [];
|
let fileWatchers: vscode.FileSystemWatcher[] = [];
|
||||||
let COV_CACHE: ICoverageCache = {};
|
let COV_CACHE: ICoverageCache = {};
|
||||||
let FILE_CACHE: IFileDecorationCache = {};
|
let FILE_CACHE: IFileDecorationCache = {};
|
||||||
let GLOBAL_COVERAGE: number = 0;
|
|
||||||
|
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
@ -64,7 +62,6 @@ function processJsonCoverage(json: any) {
|
|||||||
const covData: ICoverageCache = {};
|
const covData: ICoverageCache = {};
|
||||||
|
|
||||||
if (json && json.files) {
|
if (json && json.files) {
|
||||||
GLOBAL_COVERAGE = parseInt(json.totals.percent_covered_display);
|
|
||||||
// Look for the 'files' key in coverage JSON, and iterate through each file
|
// Look for the 'files' key in coverage JSON, and iterate through each file
|
||||||
Object.keys(json.files).forEach((file: string) => {
|
Object.keys(json.files).forEach((file: string) => {
|
||||||
// Create CoverageStats for each file and assign to covData
|
// Create CoverageStats for each file and assign to covData
|
||||||
@ -97,17 +94,17 @@ async function updateCache(files: vscode.Uri) {
|
|||||||
if (data && Object.keys(data).length > 0) {
|
if (data && Object.keys(data).length > 0) {
|
||||||
FILE_CACHE = {};
|
FILE_CACHE = {};
|
||||||
COV_CACHE = processJsonCoverage(data);
|
COV_CACHE = processJsonCoverage(data);
|
||||||
vscode.commands.executeCommand('coveragetool.refreshEntry');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.log('No data found, could not update cache');
|
Logger.log('No data found, could not update cache');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateDecorations(editor: vscode.TextEditor, coverage: IFileDecorationRange) {
|
function updateDecorations(editor: vscode.TextEditor, coverage: IFileDecorationRange) {
|
||||||
editor.setDecorations(config.excludedDecor, coverage.excludedRanges.filter(range => editor.document.validateRange(range)));
|
editor.setDecorations(config.excludedDecor, coverage.excludedRanges);
|
||||||
editor.setDecorations(config.missingDecor, coverage.missingRanges.filter(range => editor.document.validateRange(range)));
|
editor.setDecorations(config.missingDecor, coverage.missingRanges);
|
||||||
editor.setDecorations(config.executedDecor, coverage.executedRanges.filter(range => editor.document.validateRange(range)));
|
editor.setDecorations(config.executedDecor, coverage.executedRanges);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateFileHighlight(editor: vscode.TextEditor) {
|
function updateFileHighlight(editor: vscode.TextEditor) {
|
||||||
@ -207,63 +204,6 @@ async function setupCacheAndWatchers() {
|
|||||||
setupFileWatchers(files);
|
setupFileWatchers(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CoverageTreeViewProvider implements vscode.TreeDataProvider<CoverageFile> {
|
|
||||||
constructor(private workspaceRoot: string | undefined) {}
|
|
||||||
|
|
||||||
private _onDidChangeTreeData: vscode.EventEmitter<CoverageFile | undefined | null | void> = new vscode.EventEmitter<CoverageFile | undefined | null | void>();
|
|
||||||
readonly onDidChangeTreeData: vscode.Event<CoverageFile | undefined | null | void> = this._onDidChangeTreeData.event;
|
|
||||||
|
|
||||||
refresh(treeView: vscode.TreeView<CoverageFile>): void {
|
|
||||||
this._onDidChangeTreeData.fire();
|
|
||||||
this.updateBadge(treeView);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
getTreeItem(element: CoverageFile): vscode.TreeItem {
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
getChildren(element?: CoverageFile): Thenable<CoverageFile[]> {
|
|
||||||
if (!this.workspaceRoot) {
|
|
||||||
vscode.window.showInformationMessage('No missing coverage found');
|
|
||||||
return Promise.resolve([]);
|
|
||||||
}
|
|
||||||
if (element) {
|
|
||||||
return Promise.resolve([]);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return Promise.resolve(this.getFilesInCoverageJson());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private getFilesInCoverageJson(): CoverageFile[] {
|
|
||||||
if (COV_CACHE) {
|
|
||||||
const toFile = (fileName: string, relativePath: string, filePath: string, numberOfLines: number): CoverageFile => {
|
|
||||||
return new CoverageFile(fileName, relativePath, filePath, numberOfLines, vscode.TreeItemCollapsibleState.None);
|
|
||||||
};
|
|
||||||
|
|
||||||
const files = Object.keys(COV_CACHE).map((file) => {
|
|
||||||
const stats = COV_CACHE[file];
|
|
||||||
return toFile(stats.path.split("/").pop() || "", stats.path, `${this.workspaceRoot}/${stats.path}`, stats.summary.missingLines);
|
|
||||||
});
|
|
||||||
return files.filter((file) => file.numberOfLines !== 0);
|
|
||||||
} else {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private updateBadge(treeView: vscode.TreeView<CoverageFile>): void {
|
|
||||||
if (GLOBAL_COVERAGE !== 100){
|
|
||||||
treeView.badge = {
|
|
||||||
value: GLOBAL_COVERAGE,
|
|
||||||
tooltip: 'Coverage percentage'
|
|
||||||
};
|
|
||||||
}else{
|
|
||||||
treeView.badge = undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// This method is called when your extension is activated
|
// This method is called when your extension is activated
|
||||||
// Your extension is activated the very first time the command is executed
|
// Your extension is activated the very first time the command is executed
|
||||||
export async function activate(context: vscode.ExtensionContext) {
|
export async function activate(context: vscode.ExtensionContext) {
|
||||||
@ -282,25 +222,6 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||||||
updateFileHighlight(editor);
|
updateFileHighlight(editor);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
vscode.workspace.onDidChangeTextDocument(event => {
|
|
||||||
if (vscode.window.activeTextEditor && event.document === vscode.window.activeTextEditor.document) {
|
|
||||||
updateFileHighlight(vscode.window.activeTextEditor);
|
|
||||||
}
|
|
||||||
}, null, context.subscriptions);
|
|
||||||
|
|
||||||
const rootPath = vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0
|
|
||||||
? vscode.workspace.workspaceFolders[0].uri.fsPath
|
|
||||||
: undefined;
|
|
||||||
const coverageTreeViewProvider = new CoverageTreeViewProvider(rootPath);
|
|
||||||
// vscode.window.registerTreeDataProvider('coveragetoolView', coverageTreeViewProvider);
|
|
||||||
const treeView = vscode.window.createTreeView('coveragetoolView', {
|
|
||||||
treeDataProvider: coverageTreeViewProvider
|
|
||||||
});
|
|
||||||
|
|
||||||
context.subscriptions.push(treeView);
|
|
||||||
vscode.commands.registerCommand('coveragetool.refreshEntry', () =>
|
|
||||||
coverageTreeViewProvider.refresh(treeView)
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user