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

install tools with wildcards in module mode for Go >= 1.13 #2945

Merged
merged 2 commits into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/goInstallTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import cp = require('child_process');
import { getLanguageServerToolPath } from './goLanguageServer';
import { envPath, getToolFromToolPath } from './goPath';
import { hideGoStatus, outputChannel, showGoStatus } from './goStatus';
import { containsString, containsTool, getConfiguredTools, getImportPath, getTool, hasModSuffix, isGocode, isWildcard, Tool } from './goTools';
import { containsString, containsTool, getConfiguredTools, getImportPath, getTool, hasModSuffix, isGocode, Tool, disableModulesForWildcard } from './goTools';
import { getBinPath, getCurrentGoPath, getGoConfig, getGoVersion, getTempFilePath, getToolsGopath, GoVersion, resolvePath } from './util';

// declinedUpdates tracks the tools that the user has declined to update.
Expand Down Expand Up @@ -141,7 +141,8 @@ export function installTools(missing: Tool[], goVersion: GoVersion): Promise<voi
return missing.reduce((res: Promise<string[]>, tool: Tool) => {
// Disable modules for tools which are installed with the "..." wildcard.
// TODO: ... will be supported in Go 1.13, so enable these tools to use modules then.
if (modulesOff || isWildcard(tool, goVersion)) {
const modulesOffForTool = modulesOff || disableModulesForWildcard(tool, goVersion);
if (modulesOffForTool) {
envForTools['GO111MODULE'] = 'off';
} else {
envForTools['GO111MODULE'] = 'on';
Expand All @@ -155,7 +156,7 @@ export function installTools(missing: Tool[], goVersion: GoVersion): Promise<voi
const callback = (err: Error, stdout: string, stderr: string) => {
// Make sure to run `go mod tidy` between tool installations.
// This avoids us having to create a fresh go.mod file for each tool.
if (!modulesOff) {
if (!modulesOffForTool) {
cp.execFileSync(goRuntimePath, ['mod', 'tidy'], opts);
}
if (err) {
Expand Down Expand Up @@ -189,7 +190,7 @@ export function installTools(missing: Tool[], goVersion: GoVersion): Promise<voi
}
const args = ['get', '-v'];
// Only get tools at master if we are not using modules.
if (modulesOff) {
if (modulesOffForTool) {
args.push('-u');
}
// Tools with a "mod" suffix should not be installed,
Expand Down
8 changes: 6 additions & 2 deletions src/goTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ export function getImportPath(tool: Tool, goVersion: GoVersion): string {

/**
* Returns boolean denoting if the import path for the given tool ends with `/...`
* and if the version of Go supports installing wildcard paths in module mode.
* @param tool Object of type `Tool` for the Go tool.
* @param goVersion The current Go version.
*/
export function isWildcard(tool: Tool, goVersion: GoVersion): boolean {
export function disableModulesForWildcard(tool: Tool, goVersion: GoVersion): boolean {
const importPath = getImportPath(tool, goVersion);
return importPath.endsWith('...');
const isWildcard = importPath.endsWith('...');

// Only Go >= 1.13 supports installing wildcards in module mode.
return (isWildcard && goVersion.lt('1.13'));
}

export function containsTool(tools: Tool[], tool: Tool): boolean {
Expand Down