Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Fixes #601 Toggle test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed May 3, 2017
1 parent 2e50f2d commit cc661da
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
## Test Coverage
* [Thomas Bradford (@kode4food)](https://github.com/kode4food)
* New setting `go.coverageOptions` to control whether you want to highlight only covered code or only uncovered code or both when code coverage is run.


* [Ramya Rao (@ramya-rao-a)](https://github.com/ramya-rao-a)
* The command `Go: Test Coverage In Current Package` is renamed to `Go: Toggle Test Coverage In Current Package` and it does exactly what the name suggests. Toggles test coverage.

### Bug Fixes
* [Ramya Rao (@ramya-rao-a)](https://github.com/ramya-rao-a)
* Fix for [Bug 529](https://github.com/Microsoft/vscode-go/issues/529) Code completion for unimported packages now works on unsaved file after deleting imports.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
},
{
"command": "go.test.coverage",
"title": "Go: Test Coverage In Current Package",
"title": "Go: Toggle Test Coverage In Current Package",
"description": "Displays test coverage in the current package."
},
{
Expand Down
10 changes: 9 additions & 1 deletion src/goCover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,21 @@ export function removeCodeCoverage(e: vscode.TextDocumentChangeEvent) {
}
}

export function coverageCurrentPackage() {
export function toggleCoverageCurrentPackage() {
let editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showInformationMessage('No editor is active.');
return;
}

// If current file has highlights, then remove coverage, else add coverage
for (let filename in coverageFiles) {
if (editor.document.uri.fsPath.endsWith(filename)) {
clearCoverage();
return;
}
}

// FIXME: is there a better way to get goConfig?
let goConfig = vscode.workspace.getConfiguration('go');
let cwd = path.dirname(editor.document.uri.fsPath);
Expand Down
4 changes: 2 additions & 2 deletions src/goMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { check, ICheckResult, removeTestStatus } from './goCheck';
import { updateGoPathGoRootFromConfig, offerToInstallTools } from './goInstallTools';
import { GO_MODE } from './goMode';
import { showHideStatus } from './goStatus';
import { coverageCurrentPackage, getCodeCoverage, removeCodeCoverage } from './goCover';
import { toggleCoverageCurrentPackage, getCodeCoverage, removeCodeCoverage } from './goCover';
import { testAtCursor, testCurrentPackage, testCurrentFile, testPrevious, showTestOutput, testWorkspace } from './goTest';
import * as goGenerateTests from './goGenerateTests';
import { addImport } from './goImport';
Expand Down Expand Up @@ -141,7 +141,7 @@ export function activate(ctx: vscode.ExtensionContext): void {
}));

ctx.subscriptions.push(vscode.commands.registerCommand('go.test.coverage', () => {
coverageCurrentPackage();
toggleCoverageCurrentPackage();
}));

ctx.subscriptions.push(vscode.commands.registerCommand('go.test.showOutput', () => {
Expand Down

0 comments on commit cc661da

Please sign in to comment.