[vscode-go] package.json: add go.toolsManagement.go

55 views
Skip to first unread message

Hyang-Ah Hana Kim (Gerrit)

unread,
Mar 1, 2022, 2:30:53 PM3/1/22
to Hyang-Ah Hana Kim, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Suzy Mueller, kokoro, golang-co...@googlegroups.com

Hyang-Ah Hana Kim submitted this change.

View Change



2 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:

```
The name of the file: src/goInstallTools.ts
Insertions: 0, Deletions: 1.

@@ -13,7 +13,7 @@
import path = require('path');
import semver = require('semver');
import { ConfigurationTarget } from 'vscode';
-import { getGoConfig, getGoplsConfig } from './config';
+import { extensionInfo, getGoConfig, getGoplsConfig } from './config';
import { toolExecutionEnvironment, toolInstallationEnvironment } from './goEnv';
import { addGoRuntimeBaseToPATH, clearGoRuntimeBaseFromPATH } from './goEnvironmentStatus';
import { logVerbose } from './goLogging';
@@ -42,7 +42,6 @@
import { correctBinname, envPath, executableFileExists, getCurrentGoRoot, setCurrentGoRoot } from './utils/pathUtils';
import util = require('util');
import vscode = require('vscode');
-import { isInPreviewMode } from './goLanguageServer';

const STATUS_BAR_ITEM_NAME = 'Go Tools';

@@ -252,7 +251,7 @@
} else {
let version: semver.SemVer | string | undefined = tool.version;
if (!version) {
- if (tool.usePrereleaseInPreviewMode && isInPreviewMode()) {
+ if (tool.usePrereleaseInPreviewMode && extensionInfo.isPreview) {
version = await latestToolVersion(tool, true);
} else if (tool.defaultVersion) {
version = tool.defaultVersion;
```

Approvals: Suzy Mueller: Looks good to me, approved Hyang-Ah Hana Kim: Trusted
package.json: add go.toolsManagement.go

This new setting allows users to specify the go command
for tools installation.

The go version selected for go.toolsManagement.go is not yet
used for version check in goInstallTools.ts inspectGoToolVersion yet.

For golang/vscode-go#825

Change-Id: Ic7a401b2089fe1e412ede32be474ee0f309c32d4
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/387956
Trust: Hyang-Ah Hana Kim <hya...@gmail.com>
Reviewed-by: Suzy Mueller <suz...@golang.org>
---
M docs/settings.md
M package.json
M src/goEnvironmentStatus.ts
M src/goInstallTools.ts
4 files changed, 72 insertions(+), 18 deletions(-)

diff --git a/docs/settings.md b/docs/settings.md
index d45bb62..ab5e9c1 100644
--- a/docs/settings.md
+++ b/docs/settings.md
@@ -454,6 +454,11 @@


Default: `"proxy"`
+### `go.toolsManagement.go`
+
+The path to the `go` binary used to install the Go tools. If it's empty, the same `go` binary chosen for the project will be used for tool installation.
+
+Default: `""`
### `go.trace.server`

Trace the communication between VS Code and the Go language server.<br/>
diff --git a/package.json b/package.json
index e8ee774..8e3a162 100644
--- a/package.json
+++ b/package.json
@@ -116,7 +116,8 @@
"go.goroot",
"go.inferGopath",
"go.toolsGopath",
- "go.toolsEnvVars"
+ "go.toolsEnvVars",
+ "go.toolsManagement.go"
]
}
},
@@ -1528,6 +1529,12 @@
"description": "The logging level the extension logs at, defaults to 'error'",
"scope": "machine-overridable"
},
+ "go.toolsManagement.go": {
+ "type": "string",
+ "default": "",
+ "description": "The path to the `go` binary used to install the Go tools. If it's empty, the same `go` binary chosen for the project will be used for tool installation.",
+ "scope": "machine-overridable"
+ },
"go.toolsManagement.checkForUpdates": {
"type": "string",
"default": "proxy",
diff --git a/src/goEnvironmentStatus.ts b/src/goEnvironmentStatus.ts
index 7b45bb3..5c07bb6 100644
--- a/src/goEnvironmentStatus.ts
+++ b/src/goEnvironmentStatus.ts
@@ -213,18 +213,13 @@
outputChannel.clear();
outputChannel.show();
outputChannel.appendLine(`go install ${goOption.binpath}@latest`);
- const result = await installTool(
- {
- name: newExecutableName,
- importPath: goOption.binpath,
- modulePath: goOption.binpath,
- description: newExecutableName,
- isImportant: false
- },
- await getGoVersion(),
- toolInstallationEnvironment(),
- true
- );
+ const result = await installTool({
+ name: newExecutableName,
+ importPath: goOption.binpath,
+ modulePath: goOption.binpath,
+ description: newExecutableName,
+ isImportant: false
+ });
if (result) {
outputChannel.appendLine(`Error installing ${goOption.binpath}: ${result}`);
throw new Error('Could not install ${goOption.binpath}');
diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts
index 4b792f2..bfbbd38 100644
--- a/src/goInstallTools.ts
+++ b/src/goInstallTools.ts
@@ -39,7 +39,7 @@
GoVersion,
rmdirRecursive
} from './util';
-import { correctBinname, envPath, getCurrentGoRoot, setCurrentGoRoot } from './utils/pathUtils';
+import { correctBinname, envPath, executableFileExists, getCurrentGoRoot, setCurrentGoRoot } from './utils/pathUtils';
import util = require('util');
import vscode = require('vscode');

@@ -96,12 +96,30 @@
);
}

+export async function getGoForInstall(goVersion?: GoVersion, silent?: boolean): Promise<GoVersion> {
+ const configured = getGoConfig().get<string>('toolsManagement.go');
+ if (!configured) {
+ return goVersion;
+ }
+ if (executableFileExists(configured)) {
+ const go = await getGoVersion(configured);
+ if (go) return go;
+ }
+ if (!silent) {
+ outputChannel.appendLine(
+ `Ignoring misconfigured 'go.toolsManagement.go' (${configured}). Provide a valid Go command.`
+ );
+ }
+ return goVersion;
+}
+
/**
* Installs given array of missing tools. If no input is given, the all tools are installed
*
* @param missing array of tool names and optionally, their versions to be installed.
* If a tool's version is not specified, it will install the latest.
- * @param goVersion version of Go that affects how to install the tool. (e.g. modules vs legacy GOPATH mode)
+ * @param goVersion version of Go used in the project. If go used for tools installation
+ * is not configured or misconfigured, this is used as a fallback.
* @returns a list of tools that failed to install.
*/
export async function installTools(
@@ -118,6 +136,7 @@
}
outputChannel.clear();

+ const goForInstall = await getGoForInstall(goVersion);
const envForTools = toolInstallationEnvironment();
const toolsGopath = envForTools['GOPATH'];
let envMsg = `Tools environment: GOPATH=${toolsGopath}`;
@@ -162,7 +181,7 @@
for (const tool of missing) {
const modulesOffForTool = modulesOff;

- const failed = await installTool(tool, goVersion, envForTools, !modulesOffForTool);
+ const failed = await installToolWithGo(tool, goForInstall, envForTools, !modulesOffForTool);
if (failed) {
failures.push({ tool, reason: failed });
} else if (tool.name === 'gopls') {
@@ -201,9 +220,17 @@
return toolsTmpDir;
}

-export async function installTool(
+// installTool installs the specified tool.
+export async function installTool(tool: ToolAtVersion): Promise<string> {
+ const goVersion = await getGoForInstall(await getGoVersion());
+ const envForTools = toolInstallationEnvironment();
+
+ return await installToolWithGo(tool, goVersion, envForTools, true);
+}
+
+async function installToolWithGo(
tool: ToolAtVersion,
- goVersion: GoVersion,
+ goVersion: GoVersion, // go version to be used for installation.
envForTools: NodeJS.Dict<string>,
modulesOn: boolean
): Promise<string> {

To view, visit change 387956. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: vscode-go
Gerrit-Branch: master
Gerrit-Change-Id: Ic7a401b2089fe1e412ede32be474ee0f309c32d4
Gerrit-Change-Number: 387956
Gerrit-PatchSet: 4
Gerrit-Owner: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-Reviewer: Suzy Mueller <suz...@golang.org>
Gerrit-Reviewer: kokoro <noreply...@google.com>
Gerrit-MessageType: merged
Reply all
Reply to author
Forward
0 new messages