[release] prepare v0.18.0 release (2) @186ffe2

186ffe2 CHANGELOG: change log for v0.18.0
972fb46 src/goTools: update gopls latestVersion to 0.5.1
743aca1 docs: update documentation for Go status bar
222e0d0 package.json: recognize gopls.mod as a go.mod file
c9b9618 src/debugAdapter: log all the env vars passed to dlv
4af2ecc src/goInstallTools: use the 'go' command from GOROOT/bin for tool install
f0c87a6 src/util,goInstallTools: log 'cwd'
b712568 src/goMain: change gopls_gc_details to gopls.gc_details
76e3f4c src/goLanguageServer: add survey config inspection commands
b44ecdb Revert "src/goLanguageServer: enable survey for the go extension users"

Change-Id: I7d62cf3518d7847b5c2dda52af4eacf3a933a6d3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8370f9b..b1aee38 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,41 @@
+## v0.18.0 - 23rd Oct, 2020
+
+Unified Go status UI ⚡, many debugger feature improvements, and LSP 3.16 features! A list of all issues fixed with this release can be found in the [v0.18.0 milestone](https://github.com/golang/vscode-go/milestone/11).
+
+### New Features
+- The new Go status bar provides a menu to manage the go version, open the gopls trace, open the `go.mod` file, and more. The old `Go Modules` status bar was removed in favor of this new unified status bar. See [VS Code Go UI documentation](https://github.com/golang/vscode-go/blob/master/docs/ui.md) to learn more about this.
+- New `Go: Toggle gc details` command toggles the display of compiler optimization choice for the open Go source file ([CL 256658](https://go-review.googlesource.com/c/vscode-go/+/256658)).
+- Upgraded LSP to [`3.16`](https://microsoft.github.io/language-server-protocol/specifications/specification-3-16/#whatIsNew). Users of recent `gopls` can access new features such as [`Call hierarchy`](https://code.visualstudio.com/updates/v1_33#_call-hierarchy) and [`Semantic tokens`](https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#semantic-token-provider).
+
+### Enhancement
+
+- Debugging:
+  * Correctly presents the reason when the debugged program stops due to `panic` and `fatal error` ([Issue 648](https://github.com/golang/vscode-go/issues/649)).
+  * Be explicit about conditional breakpoint support ([Issue 781](https://github.com/golang/vscode-go/issues/781)).
+  * Debug Adapter logs all the environment variables passed to dlv when verbose logging is enabled.
+- Language Server Client: sends `gopls` config as LSP initialization options for correct workspace symbols computation ([CL 259138](https://go-review.googlesource.com/c/vscode-go/+/259138)).
+- Snippets: adds a placeholder for the `for` statement snippet ([Issue 734](https://github.com/golang/vscode-go/issues/734)).
+- Excludes `vendor` directories from `go.inferGopath` disable mechanism ([Issue 301](https://github.com/golang/vscode-go/issues/301)).
+- New `go.logging.level` setting allows extra logging to help debugging extension issues ([CL 256557](https://go-review.googlesource.com/c/vscode-go/+/256557)).
+- For Nightly extension users, `Go: Show Survey Config` and `Go: Reset Survey Config` commands are available.
+
+### Fixes
+- Fixed the bug that caused the debug adapter to leave bogus null items in the map type variable presentation ([Issue 199](https://github.com/golang/vscode-go/issues/199)).
+- Fixed several debug adapter bugs that caused remote debug to hang ([Issue 740](https://github.com/golang/vscode-go/issues/740), [766](https://github.com/golang/vscode-go/issues/766), [761](https://github.com/golang/vscode-go/issues/761), [764](https://github.com/golang/vscode-go/issues/764)).
+- Restored the correct handling of language server configuration change when users opt for enabling language server and installing `gopls`. ([CL 258997](https://go-review.googlesource.com/c/vscode-go/+/258997)).
+- Fixed a diagnostics error visualization issue when multiple files with errors are open ([Issue 743](https://github.com/golang/vscode-go/issues/743)).
+- Changed the dependency tool installation to use the `go` command chosen from the current `GOROOT/bin`. This helps avoid using a different version of `go` command for `asdf` or `direnv` users ([Issue 757](https://github.com/golang/vscode-go/issues/757)).
+
+### Documentation
+- Documented the current limitation of symlink support in debugging ([CL 257204](https://go-review.googlesource.com/c/vscode-go/+/257204)), improved the instruction for CLI application debugging ([CL 259677](https://go-review.googlesource.com/c/vscode-go/+/259677)), and fixed syntax errors in example task configuration snippets ([CL 259077](https://go-review.googlesource.com/c/vscode-go/+/259077)).
+
+### Code Health
+- Added an initial set of tests for debug adapters ([Issue 137](https://github.com/golang/vscode-go/issues/137)). We will keep working to improve our test coverage.
+
+### Thanks
+
+Thank you for your contributions, @suzmue, @vologab, @amitlevy21, @danielhelfand, @egonk, @quoctruong, @polinasok, @pjweinbgo, @stamblerre, @hyangah!
+
 ## v0.17.2 - 29th Sep, 2020
 
 ### Fixes
diff --git a/README.md b/README.md
index 2f47ff1..22dbea0 100644
--- a/README.md
+++ b/README.md
@@ -61,6 +61,8 @@
 
 If you see an error that looks like `command Go: Install/Update Tools not found`, it means that the extension has failed to activate and register its commands. Please uninstall and then reinstall the extension.
 
+When the extension is active, you should see the [Go status bar](docs/ui.md) in the bottom left corner.
+
 ### Start coding
 
 You're ready to Go!
diff --git a/docs/commands.md b/docs/commands.md
index 03a9919..e75e936 100644
--- a/docs/commands.md
+++ b/docs/commands.md
@@ -190,3 +190,11 @@
 ### `Go: Choose Go Environment`
 
 Choose a different Go version or binary for this project. (WIP)
+
+### `Go: Show Survey Configuration`
+
+Show the current Go survey configuration
+
+### `Go: Reset Survey Configuration`
+
+Reset the current Go survey configuration history
diff --git a/docs/go-version.md b/docs/go-version.md
deleted file mode 100644
index a7ac0aa..0000000
--- a/docs/go-version.md
+++ /dev/null
@@ -1,17 +0,0 @@
-# Managing Your Go Version
-
-## Using The Go Status Bar
-
-You can view the current Go version by looking at the status bar item in the bottom left corner of VS Code. Clicking this button and selecting `Choose Go Environment` will present you with a menu from which you can select any version of Go that exists in your $HOME/sdk directory or on <https://golang.org/dl>. This command is also available through the command pallette using `Go: Choose Go Environment`.
-
-Previously, the `go.goroot` and `go.alternateTools` settings controlled the Go version used by VS Code Go. If you have configured these settings, they are no longer needed and should be deleted.
-
-[](https://i.imgur.com/8qh2Tu2.png)
-
-The "Clear Selection" option resets your Go version to the one found first in either `go.alternateTools`, `go.goroot` or your PATH.
-
-## Installing a New Go Version
-
-After selecting any Go version that has not yet been installed (such as Go 1.14.6 in the screenshot above), the binary will be automatically installed in $HOME/sdk and put to use in your environment.
-
-Once the download completes, VS Code Go will make use of this new Go version.
diff --git a/docs/images/gopls.png b/docs/images/gopls.png
new file mode 100644
index 0000000..ea8ab07
--- /dev/null
+++ b/docs/images/gopls.png
Binary files differ
diff --git a/docs/images/selectGoVersion.png b/docs/images/selectGoVersion.png
new file mode 100644
index 0000000..85320df
--- /dev/null
+++ b/docs/images/selectGoVersion.png
Binary files differ
diff --git a/docs/images/statusbarmenu.png b/docs/images/statusbarmenu.png
new file mode 100644
index 0000000..ae9d65a
--- /dev/null
+++ b/docs/images/statusbarmenu.png
Binary files differ
diff --git a/docs/ui.md b/docs/ui.md
new file mode 100644
index 0000000..1287234
--- /dev/null
+++ b/docs/ui.md
@@ -0,0 +1,45 @@
+# Extension UI
+
+## Using The Go Status Bar
+
+The Go status bar appears in the lower left of the extension window. Clicking the Go status bar brings up a menu that provides easy access to see and update important information about your Go project. This includes information about the Go environment, the current Go version, the `gopls` trace, and about the current module.
+
+<div style="text-align: center;"><img src="images/statusbarmenu.png" alt="vscode extension after Go status bar item is clicked" style="width:75%" > </div>
+
+### Go Environment
+
+The `Go Locate Configured Go Tools` command will display the configured GOPATH, GOROOT, tool locations and the results of `go env` in the output window.
+
+### Managing Your Go Version
+
+You can view the current Go version by looking at the status bar item in the bottom left corner of VS Code. Clicking this button and selecting `Choose Go Environment` will present you with a menu from which you can select any version of Go that exists in your $HOME/sdk directory or on <https://golang.org/dl>. This command is also available through the command pallette using `Go: Choose Go Environment`.
+
+Previously, the `go.goroot` and `go.alternateTools` settings controlled the Go version used by VS Code Go. If you have configured these settings, they are no longer needed and should be deleted.
+
+<div style="text-align: center;"><img src="images/selectGoVersion.png" alt="command pallete menu for selecting a new Go version" style="width:75%" > </div>
+
+
+The "Clear Selection" option resets your Go version to the one found first in either `go.alternateTools`, `go.goroot` or your PATH.
+
+### Installing a New Go Version
+
+After selecting any Go version that has not yet been installed (such as Go 1.14.6 in the screenshot above), the binary will be automatically installed in $HOME/sdk and put to use in your environment.
+
+Once the download completes, VS Code Go will make use of this new Go version.
+
+### Language Server Status
+
+`gopls` is the official Go [language server](https://langserver.org/) developed by the Go team. It was developed in response to the release of [Go modules](docs/modules.md), and it is the recommended approach when working with [Go modules](docs/modules.md) in VS Code.
+
+When `gopls` is enabled, :zap: is displayed next to the Go version in the status bar and the `gopls` version is displayed in the menu.
+
+<div style="text-align: center;"><img src="images/gopls.png" alt="command pallete menu for selecting a new Go version" style="width:100px" > </div>
+
+Selecting `Open 'gopls' trace` will open the trace of the `gopls` server in the output window. Please include this trace when filing an issue related to the extension and `gopls` is enabled.
+
+### Modules Status
+
+When modules are enabled for the file you have open, you can navigate to the `go.mod` file for the project using the menu. If you do not see the `Open go.mod` item, then the extension does not think the file you have open belongs to a module.
+
+More information about [using Go modules](https://blog.golang.org/using-go-modules) is available on the Go blog.
+
diff --git a/package.json b/package.json
index d7cbf1c..f9b9fad 100644
--- a/package.json
+++ b/package.json
@@ -111,7 +111,8 @@
       {
         "id": "go.mod",
         "extensions": [
-          "go.mod"
+          "go.mod",
+          "gopls.mod"
         ],
         "aliases": [
           "Go Module File"
@@ -365,6 +366,16 @@
         "command": "go.environment.choose",
         "title": "Go: Choose Go Environment",
         "description": "Choose a different Go version or binary for this project. (WIP)"
+      },
+      {
+        "command": "go.survey.showConfig",
+        "title": "Go: Show Survey Configuration",
+        "description": "Show the current Go survey configuration"
+      },
+      {
+        "command": "go.survey.resetConfig",
+        "title": "Go: Reset Survey Configuration",
+        "description": "Reset the current Go survey configuration history"
       }
     ],
     "breakpoints": [
diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts
index 8dee3d8..226f87f 100644
--- a/src/debugAdapter/goDebug.ts
+++ b/src/debugAdapter/goDebug.ts
@@ -38,7 +38,7 @@
 	getCurrentGoWorkspaceFromGOPATH,
 	getInferredGopath,
 } from '../utils/pathUtils';
-import {killProcessTree} from '../utils/processUtils';
+import { killProcessTree } from '../utils/processUtils';
 
 const fsAccess = util.promisify(fs.access);
 const fsUnlink = util.promisify(fs.unlink);
@@ -473,7 +473,11 @@
 				log(`Using GOPATH: ${env['GOPATH']}`);
 				log(`Using GOROOT: ${this.goroot}`);
 				log(`Using PATH: ${env['PATH']}`);
-
+				if (launchArgs.trace === 'verbose') {
+					Object.keys(env).forEach((key) => {
+						log('  export ' + key + '="' + env[key] + '"');
+					});
+				}
 				if (!!launchArgs.noDebug) {
 					if (mode === 'debug') {
 						this.noDebug = true;
@@ -529,8 +533,7 @@
 
 				if (!existsSync(launchArgs.dlvToolPath)) {
 					log(
-						`Couldn't find dlv at the Go tools path, ${process.env['GOPATH']}${
-						env['GOPATH'] ? ', ' + env['GOPATH'] : ''
+						`Couldn't find dlv at the Go tools path, ${process.env['GOPATH']}${env['GOPATH'] ? ', ' + env['GOPATH'] : ''
 						} or ${envPath}`
 					);
 					return reject(
diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts
index 34b7b4f..691c42b 100644
--- a/src/goInstallTools.ts
+++ b/src/goInstallTools.ts
@@ -39,7 +39,7 @@
 	GoVersion,
 	rmdirRecursive,
 } from './util';
-import { envPath, getCurrentGoRoot, getToolFromToolPath, setCurrentGoRoot } from './utils/pathUtils';
+import { correctBinname, envPath, getCurrentGoRoot, getToolFromToolPath, setCurrentGoRoot } from './utils/pathUtils';
 
 // declinedUpdates tracks the tools that the user has declined to update.
 const declinedUpdates: Tool[] = [];
@@ -201,6 +201,11 @@
 	} else {
 		envForTools['GO111MODULE'] = 'off';
 	}
+	// Some users use direnv-like setup where the choice of go is affected by
+	// the current directory path. In order to avoid choosing a different go,
+	// we will explicitly use `GOROOT/bin/go` instead of goVersion.binaryPath
+	// (which can be a wrapper script that switches 'go').
+	const goBinary = path.join(getCurrentGoRoot(), 'bin', correctBinname('go'));
 
 	// Build the arguments list for the tool installation.
 	const args = ['get', '-v'];
@@ -231,8 +236,9 @@
 			cwd: toolsTmpDir,
 		};
 		const execFile = util.promisify(cp.execFile);
-		const { stdout, stderr } = await execFile(goVersion.binaryPath, args, opts);
+		const { stdout, stderr } = await execFile(goBinary, args, opts);
 		output = `${stdout} ${stderr}`;
+		logVerbose(`install: %s %s\n%s%s`, goBinary, args.join(' '), stdout, stderr);
 
 		// TODO(rstambler): Figure out why this happens and maybe delete it.
 		if (stderr.indexOf('unexpected directory layout:') > -1) {
@@ -368,7 +374,7 @@
 			{ env: toolExecutionEnvironment(), cwd: getWorkspaceFolderPath() },
 			(err, stdout, stderr) => {
 				if (err) {
-					outputChannel.append(`Failed to run '${goRuntimePath} env' : ${err}\n${stderr}`);
+					outputChannel.append(`Failed to run '${goRuntimePath} env' (cwd: ${getWorkspaceFolderPath()}): ${err}\n${stderr}`);
 					outputChannel.show();
 
 					vscode.window.showErrorMessage(`Failed to run '${goRuntimePath} env. The config change may not be applied correctly.`);
diff --git a/src/goLanguageServer.ts b/src/goLanguageServer.ts
index c8fc4e9..e229a39 100644
--- a/src/goLanguageServer.ts
+++ b/src/goLanguageServer.ts
@@ -45,7 +45,7 @@
 import { GoReferenceProvider } from './goReferences';
 import { GoRenameProvider } from './goRename';
 import { GoSignatureHelpProvider } from './goSignature';
-import { updateLanguageServerIconGoStatusBar } from './goStatus';
+import { outputChannel, updateLanguageServerIconGoStatusBar } from './goStatus';
 import { GoCompletionItemProvider } from './goSuggest';
 import { GoWorkspaceSymbolProvider } from './goSymbol';
 import { getTool, Tool } from './goTools';
@@ -86,6 +86,10 @@
 // server.
 let restartCommand: vscode.Disposable;
 
+// When enabled, users may be prompted to fill out the gopls survey.
+// For now, we turn it on in the Nightly extension to test it.
+const goplsSurveyOn: boolean = extensionId === 'golang.go-nightly';
+
 // lastUserAction is the time of the last user-triggered change.
 // A user-triggered change is a didOpen, didChange, didSave, or didClose event.
 let lastUserAction: Date = new Date();
@@ -138,7 +142,7 @@
 		setTimeout(survey, timeDay);
 
 		const cfg = buildLanguageServerConfig();
-		if (!cfg.enabled) {
+		if (!goplsSurveyOn || !cfg.enabled) {
 			return;
 		}
 		maybePromptForGoplsSurvey();
@@ -1001,8 +1005,31 @@
 	}
 }
 
+export async function showSurveyConfig() {
+	outputChannel.appendLine('Gopls Survey Configuration');
+	outputChannel.appendLine(JSON.stringify(getSurveyConfig(), null, 2));
+	outputChannel.show();
+
+	const selected = await vscode.window.showInformationMessage(`Maybe prompt for survey?`, 'Yes', 'No');
+	switch (selected) {
+		case 'Yes':
+			maybePromptForGoplsSurvey();
+			break;
+		default:
+			break;
+	}
+}
+
+export function resetSurveyConfig() {
+	flushSurveyConfig(null);
+}
+
 function flushSurveyConfig(cfg: SurveyConfig) {
-	updateGlobalState(goplsSurveyConfig, JSON.stringify(cfg));
+	if (cfg) {
+		updateGlobalState(goplsSurveyConfig, JSON.stringify(cfg));
+	} else {
+		updateGlobalState(goplsSurveyConfig, null);  // reset
+	}
 }
 
 // errorKind refers to the different possible kinds of gopls errors.
diff --git a/src/goMain.ts b/src/goMain.ts
index b8b520f..9449fb1 100644
--- a/src/goMain.ts
+++ b/src/goMain.ts
@@ -34,6 +34,8 @@
 import {
 	languageServerIsRunning,
 	promptForLanguageServerDefaultChange,
+	resetSurveyConfig,
+	showSurveyConfig,
 	startLanguageServerWithFallback, watchLanguageServerConfiguration
 } from './goLanguageServer';
 import { lintCode } from './goLint';
@@ -462,7 +464,7 @@
 		}
 		vscode.commands.executeCommand('gc_details', doc)
 			.then(undefined, (reason0) => {
-				vscode.commands.executeCommand('gopls_gc_details', doc)
+				vscode.commands.executeCommand('gopls.gc_details', doc)
 					.then(undefined, (reason1) => {
 						vscode.window.showErrorMessage(`"Go: Toggle gc details" command failed: gc_details:${reason0} gopls_gc_details:${reason1}`);
 					});
@@ -507,6 +509,12 @@
 		})
 	);
 
+	// Survey related commands
+	ctx.subscriptions.push(
+		vscode.commands.registerCommand('go.survey.showConfig', () => showSurveyConfig()));
+	ctx.subscriptions.push(
+		vscode.commands.registerCommand('go.survey.resetConfig', () => resetSurveyConfig()));
+
 	vscode.languages.setLanguageConfiguration(GO_MODE.language, {
 		wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g
 	});
diff --git a/src/goTools.ts b/src/goTools.ts
index 0e1941a..9aad76c 100644
--- a/src/goTools.ts
+++ b/src/goTools.ts
@@ -341,10 +341,10 @@
 		isImportant: false,
 		description: 'Language Server from Google',
 		minimumGoVersion: semver.coerce('1.12'),
-		latestVersion: semver.coerce('0.4.1'),
-		latestVersionTimestamp: moment('2020-05-13', 'YYYY-MM-DD'),
-		latestPrereleaseVersion: semver.coerce('0.4.1'),
-		latestPrereleaseVersionTimestamp: moment('2020-05-13', 'YYYY-MM-DD'),
+		latestVersion: semver.coerce('0.5.1'),
+		latestVersionTimestamp: moment('2020-09-30', 'YYYY-MM-DD'),
+		latestPrereleaseVersion: semver.coerce('0.5.1'),
+		latestPrereleaseVersionTimestamp: moment('2020-09-30', 'YYYY-MM-DD'),
 	},
 	'dlv': {
 		name: 'dlv',
diff --git a/src/util.ts b/src/util.ts
index 083fcf9..9f9476c 100644
--- a/src/util.ts
+++ b/src/util.ts
@@ -348,11 +348,12 @@
 		}
 		warn(`cached Go version (${JSON.stringify(cachedGoVersion)}) is invalid, recomputing`);
 	}
+	const docUri = vscode.window.activeTextEditor?.document.uri;
+	const cwd = getWorkspaceFolderPath(docUri && docUri.fsPath.endsWith('.go') ? docUri : undefined);
+
 	let goVersion: GoVersion;
 	try {
 		const env = toolExecutionEnvironment();
-		const docUri = vscode.window.activeTextEditor?.document.uri;
-		const cwd = getWorkspaceFolderPath(docUri && docUri.fsPath.endsWith('.go') ? docUri : undefined);
 		const execFile = util.promisify(cp.execFile);
 		const { stdout, stderr } = await execFile(goRuntimePath, ['version'], { env, cwd });
 		if (stderr) {
@@ -361,7 +362,7 @@
 		}
 		goVersion = new GoVersion(goRuntimePath, stdout);
 	} catch (err) {
-		warn(`failed to run "${goRuntimePath} version": ${err}`);
+		warn(`failed to run "${goRuntimePath} version": ${err} cwd: ${cwd}`);
 		return;
 	}
 	if (!goBinPath) {  // if getGoVersion was called with a given goBinPath, don't cache the result.