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

Commit

Permalink
Skip empty pkg when building workspace. Fixes #1470
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Jan 20, 2018
1 parent 37570ab commit ceaf023
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
20 changes: 11 additions & 9 deletions src/goBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import { getCurrentGoWorkspaceFromGOPATH } from './goPath';
*/
export function buildCode(buildWorkspace?: boolean) {
let editor = vscode.window.activeTextEditor;
if (!editor && !buildWorkspace) {
vscode.window.showInformationMessage('No editor is active, cannot find current package to build');
return;
}
if (editor.document.languageId !== 'go' && !buildWorkspace) {
vscode.window.showInformationMessage('File in the active editor is not a Go file, cannot find current package to build');
return;
if (!buildWorkspace) {
if (!editor) {
vscode.window.showInformationMessage('No editor is active, cannot find current package to build');
return;
}
if (editor.document.languageId !== 'go') {
vscode.window.showInformationMessage('File in the active editor is not a Go file, cannot find current package to build');
return;
}
}

let documentUri = editor ? editor.document.uri : null;
Expand All @@ -43,9 +45,9 @@ export function buildCode(buildWorkspace?: boolean) {
export function goBuild(fileUri: vscode.Uri, goConfig: vscode.WorkspaceConfiguration, buildWorkspace?: boolean): Promise<ICheckResult[]> {
const buildEnv = Object.assign({}, getToolsEnvVars());
const currentWorkspace = getWorkspaceFolderPath(fileUri);
const cwd = path.dirname(fileUri.fsPath);
const cwd = buildWorkspace ? currentWorkspace : path.dirname(fileUri.fsPath);
const tmpPath = path.normalize(path.join(os.tmpdir(), 'go-code-check'));
const isTestFile = fileUri.fsPath.endsWith('_test.go');
const isTestFile = fileUri && fileUri.fsPath.endsWith('_test.go');

let buildFlags: string[] = isTestFile ? getTestFlags(goConfig, null) : (Array.isArray(goConfig['buildFlags']) ? [...goConfig['buildFlags']] : []);
// Remove the -i flag as it will be added later anyway
Expand Down
5 changes: 4 additions & 1 deletion src/goPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function getImportablePackages(filePath: string, useCache: boolean = fals
getAllPackagesPromise = getAllPackages();
}

// Workaround for issue in https://github.com/Microsoft/vscode/issues/9448#issuecomment-244804026
// Workaround for issue in https://github.com/Microsoft/vscode/issues/9448#issuecomment-244804026
if (process.platform === 'win32' && filePath) {
filePath = filePath.substr(0, 1).toUpperCase() + filePath.substr(1);
}
Expand Down Expand Up @@ -209,6 +209,9 @@ export function getNonVendorPackages(folderPath: string): Promise<string[]> {

childProcess.on('close', (status) => {
let pkgs = chunks.join('').toString().split('\n');
if (!pkgs[pkgs.length - 1]) {
pkgs.splice(pkgs.length - 1);
}
getGoVersion().then((ver: SemVersion) => {
if (ver && (ver.major > 1 || (ver.major === 1 && ver.minor >= 9))) {
resolve(pkgs);
Expand Down

0 comments on commit ceaf023

Please sign in to comment.