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

Commit

Permalink
Skip using -i when using go modules #1532
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Sep 26, 2018
1 parent 2f6214b commit 3fd4343
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/goBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getNonVendorPackages } from './goPackages';
import { getTestFlags } from './testUtils';
import { getCurrentGoWorkspaceFromGOPATH } from './goPath';
import { diagnosticsStatusBarItem } from './goStatus';
import { isModSupported } from './goModules';
/**
* Builds current package or workspace.
*/
Expand All @@ -30,7 +31,8 @@ export function buildCode(buildWorkspace?: boolean) {
diagnosticsStatusBarItem.show();
diagnosticsStatusBarItem.text = 'Building...';

goBuild(documentUri, goConfig, buildWorkspace)
isModSupported(documentUri).then(isMod => {
goBuild(documentUri, isMod, goConfig, buildWorkspace)
.then(errors => {
handleDiagnosticErrors(editor ? editor.document : null, errors, vscode.DiagnosticSeverity.Error);
diagnosticsStatusBarItem.hide();
Expand All @@ -39,16 +41,18 @@ export function buildCode(buildWorkspace?: boolean) {
vscode.window.showInformationMessage('Error: ' + err);
diagnosticsStatusBarItem.text = 'Build Failed';
});
});
}

/**
* Runs go build -i or go test -i and presents the output in the 'Go' channel and in the diagnostic collections.
*
* @param fileUri Document uri.
* @param isMod Boolean denoting if modules are being used.
* @param goConfig Configuration for the Go extension.
* @param buildWorkspace If true builds code in all workspace.
*/
export function goBuild(fileUri: vscode.Uri, goConfig: vscode.WorkspaceConfiguration, buildWorkspace?: boolean): Promise<ICheckResult[]> {
export function goBuild(fileUri: vscode.Uri, isMod: boolean, goConfig: vscode.WorkspaceConfiguration, buildWorkspace?: boolean): Promise<ICheckResult[]> {
epoch++;
let closureEpoch = epoch;
if (tokenSource) {
Expand All @@ -75,7 +79,7 @@ export function goBuild(fileUri: vscode.Uri, goConfig: vscode.WorkspaceConfigura
const buildFlags: string[] = isTestFile ? getTestFlags(goConfig, null) : (Array.isArray(goConfig['buildFlags']) ? [...goConfig['buildFlags']] : []);
const buildArgs: string[] = isTestFile ? ['test', '-c'] : ['build'];

if (goConfig['installDependenciesWhenBuilding'] === true) {
if (goConfig['installDependenciesWhenBuilding'] === true && !isMod) {
buildArgs.push('-i');
// Remove the -i flag from user as we add it anyway
if (buildFlags.indexOf('-i') > -1) {
Expand Down
3 changes: 2 additions & 1 deletion src/goCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ICheckResult, getBinPath, getTempFilePath } from './util';
import { goLint } from './goLint';
import { goVet } from './goVet';
import { goBuild } from './goBuild';
import { isModSupported } from './goModules';

let statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
statusBarItem.command = 'go.test.showOutput';
Expand Down Expand Up @@ -83,7 +84,7 @@ export function check(fileUri: vscode.Uri, goConfig: vscode.WorkspaceConfigurati
};

if (!!goConfig['buildOnSave'] && goConfig['buildOnSave'] !== 'off') {
runningToolsPromises.push(goBuild(fileUri, goConfig, goConfig['buildOnSave'] === 'workspace'));
runningToolsPromises.push(isModSupported(fileUri).then(isMod => goBuild(fileUri, isMod, goConfig, goConfig['buildOnSave'] === 'workspace')));
}

if (!!goConfig['testOnSave']) {
Expand Down

0 comments on commit 3fd4343

Please sign in to comment.