Skip to content

Commit

Permalink
Add extension commands
Browse files Browse the repository at this point in the history
  • Loading branch information
dewski committed Nov 1, 2024
1 parent 7c28278 commit bea7bcf
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ The coverage is also displayed as a percentage in the editor's status bar:
- `uncoveredBranchHighlightColor`: The highlight color to use for highlighting uncovered branches.
- `uncoveredBranchGutterStyle`: The style to use for the gutter indicator for uncovered branches.

## Commands

- `simplecov.coverage.toggle`: Toggle the display of code coverage.
- `simplecov.coverage.apply`: Apply the coverage to the currently active file.
- `simplecov.coverage.remove`: Remove the coverage from the currently active file.

## Requirements

Expand Down
16 changes: 15 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,21 @@
"scope": "resource"
}
}
}
},
"commands": [
{
"command": "simplecov.coverage.toggle",
"title": "SimpleCov: Toggle Coverage"
},
{
"command": "simplecov.coverage.apply",
"title": "SimpleCov: Apply Coverage"
},
{
"command": "simplecov.coverage.remove",
"title": "SimpleCov: Remove Coverage"
}
]
},
"scripts": {
"vscode:prepublish": "npm run compile",
Expand Down
40 changes: 39 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,51 @@ export function activate(context: vscode.ExtensionContext) {
initCoverageDecorators(context);

addWorkspaceFileSystemWatchers(context);
addExtensionCommandListeners(context);
addOnDidChangeConfigListeners(context);
addOnChangeActiveTextEditorListeners(context);
addOnSaveTextDocumentListeners(context);

console.debug("simplecov extension activated");
}

function addExtensionCommandListeners(context: vscode.ExtensionContext) {
let toggleCoverageCommand = vscode.commands.registerCommand(
"simplecov.coverage.toggle",
toggleCoverage
);

let applyCoverageCommand = vscode.commands.registerCommand(
"simplecov.coverage.apply",
applyCoverage
);

let removeCoverageCommand = vscode.commands.registerCommand(
"simplecov.coverage.remove",
clearCoverage
);

context.subscriptions.push(toggleCoverageCommand);
context.subscriptions.push(applyCoverageCommand);
context.subscriptions.push(removeCoverageCommand);
}

function toggleCoverage() {
if (isCoverageApplied) {
console.debug(`toggleCoverage: removing coverage`);
clearCoverage();
} else {
console.debug(`toggleCoverage: applying coverage`);
applyCoverage();
}
}

function applyCoverage() {
console.debug(`applyCoverage: applying coverage`);
reloadCoverage();
vscode.window.visibleTextEditors.forEach(applyCodeCoverage);
}

// This method is called when your extension is deactivated
export function deactivate() {
statusBarItem.dispose();
Expand Down Expand Up @@ -305,7 +343,6 @@ function clearCoverage() {
}

function reloadCoverage() {
console.debug("clearCoverage");
outputChannel.appendLine(`Reloading coverage`);

clearCoverage();
Expand Down Expand Up @@ -339,6 +376,7 @@ function removeCodeCoverageOnFileSave(e: vscode.TextDocument) {

function applyCodeCoverage(editor: vscode.TextEditor | undefined) {
if (!editor) {
console.debug(`applyCodeCoverage: no active text editor`);
return;
}

Expand Down

0 comments on commit bea7bcf

Please sign in to comment.