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

Commit

Permalink
Codelens for benchmarks #1522
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Sep 23, 2018
1 parent 7bdd766 commit 015e918
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
35 changes: 25 additions & 10 deletions src/goRunTestCodelens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getCurrentGoPath } from './util';
import { GoBaseCodeLensProvider } from './goBaseCodelens';

export class GoRunTestCodeLensProvider extends GoBaseCodeLensProvider {
private readonly benchmarkRegex = /^Benchmark.+/;
private readonly debugConfig: any = {
'name': 'Launch',
'type': 'go',
Expand Down Expand Up @@ -53,21 +54,35 @@ export class GoRunTestCodeLensProvider extends GoBaseCodeLensProvider {
private getCodeLensForPackage(document: TextDocument, token: CancellationToken): Thenable<CodeLens[]> {
let documentSymbolProvider = new GoDocumentSymbolProvider();
return documentSymbolProvider.provideDocumentSymbols(document, token)
.then(symbols => symbols.find(sym => sym.kind === vscode.SymbolKind.Package && !!sym.name))
.then(pkg => {
if (pkg) {
const range = pkg.location.range;
return [
.then(symbols => {
const pkg = symbols.find(sym => sym.kind === vscode.SymbolKind.Package && !!sym.name);
if (!pkg) {
return;
}
const range = pkg.location.range;
const packageCodeLens = [
new CodeLens(range, {
title: 'run package tests',
command: 'go.test.package'
}),
new CodeLens(range, {
title: 'run file tests',
command: 'go.test.file'
})
];
if (symbols.some(sym => sym.kind === vscode.SymbolKind.Function && this.benchmarkRegex.test(sym.name))) {
packageCodeLens.push(
new CodeLens(range, {
title: 'run package tests',
command: 'go.test.package'
title: 'run package benchmarks',
command: 'go.benchmark.package'
}),
new CodeLens(range, {
title: 'run file tests',
command: 'go.test.file'
title: 'run file benchmarks',
command: 'go.benchmark.file'
})
];
);
}
return packageCodeLens;
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const runningTestProcesses: cp.ChildProcess[] = [];

const testFuncRegex = /^Test.+|Example.+/;
const testMethodRegex = /^\(([^)]+)\)\.(Test.*)$/;
const benchmarkRegex = /^Benchmark$/;
const benchmarkRegex = /^Benchmark.+/;

/**
* Input to goTest.
Expand Down

0 comments on commit 015e918

Please sign in to comment.