src/goMain: let go.locate.tools print tools versions
The output will look like
Checking configured tools....
GOBIN: undefined
toolsGopath:
gopath: /Users/hakim/go
GOROOT: /Users/hakim/sdk/go1.17beta1
PATH: /Users/hakim/sdk/go1.17beta1/bin:/Users/hakim/google-cloud-sdk/bin:/Users/hakim/bin:/Users/hakim/go/bin:/usr/local/git/current/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/go/bin:/Users/hakim/.npm-packages/bin
PATH (vscode launched with): /Users/hakim/google-cloud-sdk/bin:/Users/hakim/bin:/Users/hakim/go/bin:/usr/local/git/current/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/go/bin:/Users/hakim/.npm-packages/bin
go: /Users/hakim/sdk/go1.17beta1/bin/go: go version go1.17beta1 darwin/amd64
go-outline: /Users/hakim/go/bin/go-outline: go1.16.4
path github.com/ramya-rao-a/go-outline
mod github.com/ramya-rao-a/go-outline v0.0.0-20210608161538-9736a4bde949 h1:iaD+iVf9xGfajsJp+zYrg9Lrk6gMJ6/hZHO4cYq5D5o=
dep golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs=
gotests: not installed
gomodifytags: not installed
....
Change-Id: Ia4796adf38e7888d1356a42d4460f4c0a94e7ea3
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/337989
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
diff --git a/src/goMain.ts b/src/goMain.ts
index b215f07..3b1fda2 100644
--- a/src/goMain.ts
+++ b/src/goMain.ts
@@ -93,11 +93,20 @@
getGoVersion,
getToolsGopath,
getWorkspaceFolderPath,
+ GoVersion,
handleDiagnosticErrors,
isGoPathSet,
- resolvePath
+ resolvePath,
+ runGoVersionM
} from './util';
-import { clearCacheForTools, fileExists, getCurrentGoRoot, dirExists, setCurrentGoRoot } from './utils/pathUtils';
+import {
+ clearCacheForTools,
+ fileExists,
+ getCurrentGoRoot,
+ dirExists,
+ setCurrentGoRoot,
+ envPath
+} from './utils/pathUtils';
import { WelcomePanel } from './welcome';
import semver = require('semver');
import vscode = require('vscode');
@@ -954,22 +963,40 @@
outputChannel.appendLine('toolsGopath: ' + getToolsGopath());
outputChannel.appendLine('gopath: ' + getCurrentGoPath());
outputChannel.appendLine('GOROOT: ' + getCurrentGoRoot());
- outputChannel.appendLine('PATH: ' + process.env['PATH']);
+ const currentEnvPath = process.env['PATH'] || (process.platform === 'win32' ? process.env['Path'] : null);
+ outputChannel.appendLine('PATH: ' + currentEnvPath);
+ if (currentEnvPath !== envPath) {
+ outputChannel.appendLine(`PATH (vscode launched with): ${envPath}`);
+ }
outputChannel.appendLine('');
const goVersion = await getGoVersion();
const allTools = getConfiguredTools(goVersion, getGoConfig(), getGoplsConfig());
+ const goVersionTooOld = goVersion?.lt('1.12') || false;
- allTools.forEach((tool) => {
- const toolPath = getBinPath(tool.name);
- // TODO(hyangah): print alternate tool info if set.
- let msg = 'not installed';
- if (path.isAbsolute(toolPath)) {
- // getBinPath returns the absolute path is the tool exists.
- // (See getBinPathWithPreferredGopath which is called underneath)
- msg = 'installed';
- }
- outputChannel.appendLine(` ${tool.name}: ${toolPath} ${msg}`);
+ outputChannel.appendLine(`\tgo:\t${goVersion?.binaryPath}: ${goVersion?.version}`);
+ const toolsInfo = await Promise.all(
+ allTools.map(async (tool) => {
+ const toolPath = getBinPath(tool.name);
+ // TODO(hyangah): print alternate tool info if set.
+ if (!path.isAbsolute(toolPath)) {
+ // getBinPath returns the absolute path is the tool exists.
+ // (See getBinPathWithPreferredGopath which is called underneath)
+ return `\t${tool.name}:\tnot installed`;
+ }
+ if (goVersionTooOld) {
+ return `\t${tool.name}:\t${toolPath}: unknown version`;
+ }
+ try {
+ const out = await runGoVersionM(toolPath);
+ return `\t${tool.name}:${out.replace(/^/gm, '\t')}`;
+ } catch (e) {
+ return `\t${tool.name}:\t${toolPath}: go version -m failed: ${e}`;
+ }
+ })
+ );
+ toolsInfo.forEach((info) => {
+ outputChannel.appendLine(info);
});
let folders = vscode.workspace.workspaceFolders?.map((folder) => {
diff --git a/src/util.ts b/src/util.ts
index b68f378..28270cf 100644
--- a/src/util.ts
+++ b/src/util.ts
@@ -391,6 +391,20 @@
}
/**
+ * Returns the output of `go version -m` with the toolPath.
+ */
+export async function runGoVersionM(toolPath: string): Promise<string> {
+ const goRuntime = getBinPath('go');
+ const execFile = util.promisify(cp.execFile);
+ const opts = { env: toolExecutionEnvironment() };
+ const { stdout, stderr } = await execFile(goRuntime, ['version', '-m', toolPath], opts);
+ if (stderr) {
+ throw new Error(`failed to run 'go version -m ${toolPath}': ${stderr}`);
+ }
+ return stdout;
+}
+
+/**
* Returns boolean denoting if current version of Go supports vendoring
*/
export async function isVendorSupported(): Promise<boolean> {