[release] src/goPath: remove dependency on util that depends on vscode

golang.org/cl/239697 accidentally added the new dependency on util - to find
the value of go.goroot, which broke the debug adapter that runs outside
vscode.

Made getBinPathWithPreferredGopath accept a preferredGoroot param,
and renamed the function to reflect this change.

We need to remove any dependency from src/debugAdapter to src to avoid
a similar bug in the future.

We need to have a test, using the built extension.

Updates golang/vscode-go#137.

Change-Id: I586438f1f391aaff0c0cdc806de1e9f3fd5deba9
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/240097
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
(cherry picked from commit b9d1badbbd1eefba4340764c67b39e33accb6d88)
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/240117
diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts
index a2b3c49..0dc9901 100644
--- a/src/debugAdapter/goDebug.ts
+++ b/src/debugAdapter/goDebug.ts
@@ -33,7 +33,7 @@
 import {
 	envPath,
 	fixDriveCasingInWindows,
-	getBinPathWithPreferredGopath,
+	getBinPathWithPreferredGopathGoroot,
 	getCurrentGoWorkspaceFromGOPATH,
 	getInferredGopath,
 	parseEnvFile
@@ -471,7 +471,7 @@
 							runArgs.push(...launchArgs.args);
 						}
 
-						const goExe = getBinPathWithPreferredGopath('go', []);
+						const goExe = getBinPathWithPreferredGopathGoroot('go', []);
 						log(`Current working directory: ${dirname}`);
 						log(`Running: ${goExe} ${runArgs.join(' ')}`);
 
@@ -1934,7 +1934,7 @@
 		}
 		return new Promise((resolve) => {
 			execFile(
-				getBinPathWithPreferredGopath('go', []),
+				getBinPathWithPreferredGopathGoroot('go', []),
 				['list', '-f', '{{.Name}} {{.ImportPath}}'],
 				{ cwd: dir, env: this.delve.dlvEnv },
 				(err, stdout, stderr) => {
@@ -2335,7 +2335,7 @@
 function queryGOROOT(cwd: any, env: any): Promise<string> {
 	return new Promise<string>((resolve) => {
 		execFile(
-			getBinPathWithPreferredGopath('go', []),
+			getBinPathWithPreferredGopathGoroot('go', []),
 			['env', 'GOROOT'],
 			{ cwd, env },
 			(err, stdout, stderr) => {
diff --git a/src/goPath.ts b/src/goPath.ts
index 1e07c2b..f85e49e 100644
--- a/src/goPath.ts
+++ b/src/goPath.ts
@@ -12,7 +12,6 @@
 import fs = require('fs');
 import os = require('os');
 import path = require('path');
-import { getGoConfig } from './util';
 
 let binPathCache: { [bin: string]: string } = {};
 
@@ -32,9 +31,10 @@
 	return null;
 }
 
-export function getBinPathWithPreferredGopath(
+export function getBinPathWithPreferredGopathGoroot(
 	toolName: string,
 	preferredGopaths: string[],
+	preferredGoroot?: string,
 	alternateTool?: string,
 	useCache = true,
 ) {
@@ -67,7 +67,7 @@
 	}
 
 	// Check GOROOT (go, gofmt, godoc would be found here)
-	const pathFromGoRoot = getBinPathFromEnvVar(binname, getGoConfig().get('goroot') || getCurrentGoRoot(), true);
+	const pathFromGoRoot = getBinPathFromEnvVar(binname, preferredGoroot || getCurrentGoRoot(), true);
 	if (pathFromGoRoot) {
 		binPathCache[toolName] = pathFromGoRoot;
 		return pathFromGoRoot;
diff --git a/src/util.ts b/src/util.ts
index ba5b760..fc24810 100644
--- a/src/util.ts
+++ b/src/util.ts
@@ -19,7 +19,7 @@
 import {
 	envPath,
 	fixDriveCasingInWindows,
-	getBinPathWithPreferredGopath,
+	getBinPathWithPreferredGopathGoroot,
 	getCurrentGoRoot,
 	getInferredGopath,
 	resolveHomeDir,
@@ -436,12 +436,14 @@
 }
 
 export function getBinPath(tool: string, useCache = true): string {
-	const alternateTools: { [key: string]: string } = getGoConfig().get('alternateTools');
+	const cfg = getGoConfig();
+	const alternateTools: { [key: string]: string } = cfg.get('alternateTools');
 	const alternateToolPath: string = alternateTools[tool];
 
-	return getBinPathWithPreferredGopath(
+	return getBinPathWithPreferredGopathGoroot(
 		tool,
 		tool === 'go' ? [] : [getToolsGopath(), getCurrentGoPath()],
+		tool === 'go' && cfg.get('goroot') ? cfg.get('goroot') : undefined,
 		resolvePath(alternateToolPath),
 		useCache
 	);