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

Commit

Permalink
Fixes #879 Debug test via codelens
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed May 3, 2017
1 parent ca11577 commit 5b1ced7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/goCover.ts
Expand Up @@ -62,7 +62,7 @@ export function toggleCoverageCurrentPackage() {

// If current file has highlights, then remove coverage, else add coverage
for (let filename in coverageFiles) {
if (editor.document.uri.fsPath.endsWith(filename)) {
if (editor.document.uri.fsPath.endsWith(filename)) {
clearCoverage();
return;
}
Expand Down
29 changes: 26 additions & 3 deletions src/goRunTestCodelens.ts
Expand Up @@ -6,11 +6,22 @@
'use strict';

import vscode = require('vscode');
import path = require('path');
import { CodeLensProvider, TextDocument, CancellationToken, CodeLens, Command } from 'vscode';
import { getTestFunctions } from './goTest';
import { GoDocumentSymbolProvider } from './goOutline';

export class GoRunTestCodeLensProvider implements CodeLensProvider {
private readonly debugConfig: any = {
'name': 'Launch',
'type': 'go',
'request': 'launch',
'mode': 'test',
'env': {
'GOPATH': process.env['GOPATH']
}
};

public provideCodeLenses(document: TextDocument, token: CancellationToken): CodeLens[] | Thenable<CodeLens[]> {
if (!document.fileName.endsWith('_test.go')) {
return;
Expand Down Expand Up @@ -47,14 +58,26 @@ export class GoRunTestCodeLensProvider implements CodeLensProvider {

private getCodeLensForFunctions(document: TextDocument): Thenable<CodeLens[]> {
return getTestFunctions(document).then(testFunctions => {
return testFunctions.map(func => {
let command: Command = {
let codelens = [];

testFunctions.forEach(func => {
let runTestCmd: Command = {
title: 'run test',
command: 'go.test.cursor',
arguments: [ { functionName: func.name} ]
};
return new CodeLens(func.location.range, command);

let config = Object.assign({}, this.debugConfig, { args: ['-test.run', func.name], program: path.dirname(document.fileName) });
let debugTestCmd: Command = {
title: 'debug test',
command: 'vscode.startDebug',
arguments: [ config ]
};

codelens.push(new CodeLens(func.location.range, runTestCmd));
codelens.push(new CodeLens(func.location.range, debugTestCmd));
});
return codelens;
});
}
}

0 comments on commit 5b1ced7

Please sign in to comment.