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

Commit

Permalink
Add progress info to status bar
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Bulatov <oleg@bulatov.me>
  • Loading branch information
dmage committed Feb 24, 2017
1 parent bdc5903 commit 886627c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/goBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function buildPkg(goConfig: vscode.WorkspaceConfiguration, pkg: string, c

export function buildTest(goConfig: vscode.WorkspaceConfiguration, pkg: string, cwd: string): Promise<string> {
let tmppath = path.normalize(path.join(os.tmpdir(), 'go-code-check'));
// FIXME: allow to disable -cover in some builds?
let args = ['test', '-c', '-cover', '-o', tmppath, ...buildFlags(goConfig), '.'];
// FIXME: -cover changes output if the source has syntax errors; can we still compile code only one time for buildOnSave and coverOnSave?
let args = ['test', '-c', '-o', tmppath, ...buildFlags(goConfig), '.'];
return runTool(args, cwd).then(result => tmppath);
}
18 changes: 16 additions & 2 deletions src/goCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { runTest } from './goTest';
import { buildPkg, buildTest } from './goBuild';
import { getBinPath, parseFilePrelude } from './util';

let statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);

export interface ICheckResult {
file: string;
line: number;
Expand Down Expand Up @@ -169,13 +171,24 @@ export function check(filename: string, goConfig: vscode.WorkspaceConfiguration)
runningToolsPromises.push(buildPromise);
}
if (!!goConfig['testOnSave']) {
statusBarItem.show();
statusBarItem.text = 'building';
buildCurrentTest().then(result => {
statusBarItem.text = 'testing';
// FIXME: args? can we be backward compatible with testFlags?
runTest(goConfig, result, [], cwd);
return runTest(goConfig, result, [], cwd);
}).then(success => {
if (success) {
statusBarItem.text = 'OK :-)';
} else {
statusBarItem.text = 'FAIL :-(';
}
}).catch(err => {
statusBarItem.text = 'syntax error';
// FIXME: failed to build, just ignore?
return [];
});
} else {
statusBarItem.hide();
}
if (!!goConfig['lintOnSave']) {
let lintTool = goConfig['lintTool'] || 'golint';
Expand Down Expand Up @@ -208,6 +221,7 @@ export function check(filename: string, goConfig: vscode.WorkspaceConfiguration)
}

if (!!goConfig['coverOnSave']) {
// FIXME: broken, test built without -cover flag
let coverPromise = buildCurrentTest().then(
result => getCoverage(result, cwd),
err => {
Expand Down
31 changes: 16 additions & 15 deletions src/goTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,22 @@ function goTest(testconfig: TestConfig): Thenable<boolean> {
*
* @param FIXME
*/
export function runTest(goConfig: vscode.WorkspaceConfiguration, command: string, args: any, cwd: string) {
outputChannel.clear();
let testEnvVars = Object.assign({}, process.env, goConfig['testEnvVars']);
let proc = cp.spawn(command, args, { env: testEnvVars, cwd: cwd });
proc.stdout.on('data', chunk => outputChannel.append(chunk.toString()));
proc.stderr.on('data', chunk => outputChannel.append(chunk.toString()));
proc.on('close', code => {
if (code) {
outputChannel.append('Error: Tests failed.');
outputChannel.show(true);
} else {
outputChannel.append('Success: Tests passed.');
}
// FIXME: return promise?
// resolve(code === 0);
export function runTest(goConfig: vscode.WorkspaceConfiguration, command: string, args: any, cwd: string): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
outputChannel.clear();
let testEnvVars = Object.assign({}, process.env, goConfig['testEnvVars']);
let proc = cp.spawn(command, args, { env: testEnvVars, cwd: cwd });
proc.stdout.on('data', chunk => outputChannel.append(chunk.toString()));
proc.stderr.on('data', chunk => outputChannel.append(chunk.toString()));
proc.on('close', code => {
if (code) {
outputChannel.append('Error: Tests failed.');
outputChannel.show(true);
} else {
outputChannel.append('Success: Tests passed.');
}
resolve(code === 0);
});
});
}

Expand Down

0 comments on commit 886627c

Please sign in to comment.