diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
index 7edb98f6fe..508a663045 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -8,7 +8,8 @@ assignees: ''
---
For asking questions, see:
-- [GitHub Discussions (Q&A)](https://github.com/golang/vscode-go/discussions/categories/q-a)
+- [Stack Overflow](https://stackoverflow.com/questions/tagged/go+visual-studio-code)
+- [GitHub Discussions (Help)](https://github.com/golang/vscode-go/discussions/categories/help)
- [`#vscode` channel in Gophers Slack](https://invite.slack.golangbridge.org/messages/vscode)
Before filing an issue, please review our troubleshooting guides
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
index 064afa8275..fe86b8b28f 100644
--- a/.github/ISSUE_TEMPLATE/config.yml
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -1,5 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Question
- url: https://invite.slack.golangbridge.org/
- about: Ask and answer questions on the `#vscode` channel in Gophers Slacks.
+ url: https://stackoverflow.com/questions/tagged/go+visual-studio-code
+ about: Ask and answer questions on Stack Overflow.
diff --git a/.github/SUPPORT.md b/.github/SUPPORT.md
index 914c4f4460..76776cc5ed 100644
--- a/.github/SUPPORT.md
+++ b/.github/SUPPORT.md
@@ -1,6 +1,6 @@
For asking questions, visit:
-* `#vscode` channel in [Gophers Slack](https://gophers.slack.com) for general questions.
-* `#vscode-dev` channel in [Gophers Slack](https://gophers.slack.com) for extension development-related questions.
-
-Use the [invite app](https://invite.slack.golangbridge.org/) for access.
+* [Stack Overflow](https://stackoverflow.com/questions/tagged/go+visual-studio-code)
+* [Gophers Slack](https://gophers.slack.com) - Use the [invite app](https://invite.slack.golangbridge.org/) for access.
+ * `#vscode` channel for general questions
+ * `#vscode-dev` channel for extension development-related questions
diff --git a/.github/release_plan.md b/.github/release_plan.md
index 571894e0af..0abb349a5e 100644
--- a/.github/release_plan.md
+++ b/.github/release_plan.md
@@ -4,15 +4,15 @@
- [ ] Create a milestone with the issues that are fixed by this release
- [ ] Update `master` for the release
- [ ] Update hardcoded latest version for `dlv-dap` and `gopls`
+ - [ ] Update [`CHANGELOG.md`](https://github.com/golang/vscode-go/blob/master/CHANGELOG.md)
+ - [ ] Make sure the "Thanks" section is up-to-date
+ - [ ] Check the Markdown rendering to make sure everything looks good
- [ ] Update `release` for the release
- [ ] Create a branch against `release` for a pull request
- [ ] Merge changes from `master` to prepare for the release
- [ ] Change the version in [`package.json`](https://github.com/golang/vscode-go/blob/master/package.json) from a `-dev` suffix
- [ ] Run `npm install` to make sure [`package-lock.json`](https://github.com/golang/vscode-go/blob/master/package.json) is up-to-date
- [ ] Update the license file (`$ tools/license.sh; mv LICENSE.prod LICENSE`)
- - [ ] Update [`CHANGELOG.md`](https://github.com/golang/vscode-go/blob/master/CHANGELOG.md)
- - [ ] Make sure the "Thanks" section is up-to-date
- - [ ] Check the Markdown rendering to make sure everything looks good
- [ ] Check the [Long Tests status](https://github.com/golang/vscode-go/actions?query=workflow%3A%22Long+Tests%22) is green. Otherwise, fix the tests, send cls for review, submit them, and repeat.
- [ ] Perform manual [smoke tests]( https://github.com/golang/vscode-go/blob/master/docs/smoke-test.md)
- [ ] Create new version tag for X.XX.X-rc.1 at gerrit’s vscode-go [repo management page](https://go-review.googlesource.com/admin/repos/vscode-go,tags)
@@ -20,7 +20,7 @@
- [ ] Ask editor team and contributors to this release to test the release candidate
# Release Candidate >1 (if necessary)
-- ] Fix any bugs on `master` and cherry pick changes to `release
+- [ ] Fix any bugs on `master` and cherry pick changes to `release
- [ ] Create new version tag for X.XX.X-rc.1 at gerrit’s vscode-go [repo management page](https://go-review.googlesource.com/admin/repos/vscode-go,tags)
- [ ] Go to the release page https://github.com/golang/vscode-go/releases and check if the new release candidate is up. If necessary, you can manually edit the comment by clicking the “Edit” button. Don’t mutate uploaded vsix.
- [ ] Ask editor team and contributors to this release to test the release candidate
@@ -36,4 +36,3 @@
- [ ] Bump the version number to the next monthly ("X.XX.X-dev") release in the `master` branch
- [ ] `package.json`
- [ ] `package-lock.json`
- - [ ] Cherry pick CHANGELOG.md back to master
diff --git a/.github/workflows/test-long-all.yml b/.github/workflows/test-long-all.yml
index 6a1bbad14d..4da59bca52 100644
--- a/.github/workflows/test-long-all.yml
+++ b/.github/workflows/test-long-all.yml
@@ -17,7 +17,7 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
version: ['stable', 'insiders']
- go: ['1.15', '1.16']
+ go: ['1.15', '1.16', '1.17.0-rc1']
steps:
- name: Clone repository
diff --git a/.github/workflows/test-long.yml b/.github/workflows/test-long.yml
index e26ef7dd12..0ef3361182 100644
--- a/.github/workflows/test-long.yml
+++ b/.github/workflows/test-long.yml
@@ -16,7 +16,7 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest] # TODO: reenable macos-latest
version: ['stable']
- go: ['1.15', '1.16']
+ go: ['1.15', '1.16', '1.17.0-rc1']
steps:
- name: Clone repository
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 25075bc9c9..e01b1df458 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -1,6 +1,14 @@
{
"version": "0.2.0",
"configurations": [
+ {
+ "name": "Launch tools/generate",
+ "type": "go",
+ "request": "launch",
+ "mode": "debug",
+ "program": "${workspaceFolder}/tools/generate.go",
+ "cwd": "${workspaceFolder}"
+ },
{
"name": "Launch Extension",
"type": "extensionHost",
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d2f8be8729..9f53ac6f63 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,45 @@
-## V0.26.0 - 17 Jun, 2021
+## v0.27.0 - 9 Aug, 2021
+
+📣 Delve's native DAP implementation ([`dlv-dap`](https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_dap.md))
+is enabled by default for local debugging. We updated the [Documentation for Debugging](https://github.com/golang/vscode-go/blob/master/docs/debugging.md)
+to show the new features available with dlv-dap. This change does not apply to remote debugging yet.
+For remote debugging, keep following the instruction in the
+[legacy debug adapter documentation](https://github.com/golang/vscode-go/blob/master/docs/debugging-legacy.md).
+
+A list of all issues and changes can be found in the [v0.27.0 milestone](https://github.com/golang/vscode-go/milestone/33?closed=1) and [commit history](https://github.com/golang/vscode-go/compare/v0.26.0...v0.27.0).
+
+### Enhancements
+- The new [`go.terminal.activateEnvironment`](https://github.com/golang/vscode-go/blob/master/docs/settings.md#goterminalactivateenvironment)
+allows to prevent the extension from changing integrated terminal's environment variables. ([Issue 1558](https://github.com/golang/vscode-go/issues/1558), [1098](https://github.com/golang/vscode-go/issues/1098))
+- The [`Go: Locate Configured Go Tools`](https://github.com/golang/vscode-go/blob/master/docs/commands.md#go-locate-configured-go-tools)
+command prints the build information of detected tools.
+- Use `dlv-dap` as the default debug adapter for local debugging. The new debug adapter offers
+[many new features and improvements](https://github.com/golang/vscode-go/issues?q=is%3Aissue+is%3Aclosed+label%3AFixedInDlvDAPOnly).
+- Added Gitpod to a recognized Cloud-based IDE, for which the extension will minimize the number of toast or notification messages. ([Issue 1616](https://github.com/golang/vscode-go/issues/1616))
+- The [`Go: Subtest At Cursor`](https://github.com/golang/vscode-go/blob/master/docs/commands.md#go-subtest-at-cursor) command prompts for subtest name if there is no subtest at cursor ([Issue 1602](https://github.com/golang/vscode-go/issues/1602)).
+
+### Fixes
+- Debugging
+ - Setting the `logOutput` property without `showLog: true` does not break debugging any more.
+ - Fixed a bug in the legacy debug adapter that caused jumping at each step after upgrading to VS Code 1.58+. ([Issue 1617](https://github.com/golang/vscode-go/issues/1617), [1647](https://github.com/golang/vscode-go/issues/1647))
+ - Fixed a bug that broke Attach mode debugging using the legacy debug adapter if `cwd` is not set. ([Issue 1608](https://github.com/golang/vscode-go/issues/1608))
+ - Made the `dlv-dap` mode ignore the `port` property. It was initially suggested as a temporary alternative
+ to the remote debugging, but we decided to revisit the functionality for better remote debugging support.
+ Use the `debugServer` property if you want to connect to a manually launched `dlv dap` server.
+
+### Code Health
+- The version of `dlv-dap` is pinned to [v1.7.1-0.20210804080032-f95340ae1bf9](https://github.com/go-delve/delve/tree/f95340ae1bf9fed8740d5fd39f5758d41770d967) and `dlv-dap` is marked as a required tool.
+- Updated the hard-coded default gopls version string to v0.7.1.
+- Added `tools/relnotes`, a script to help generate CHANGELOG.md.
+- Added go1.17 RC to CI. ([Issue 1640](https://github.com/golang/vscode-go/issues/1640))
+- Enabled tests that were skipped in dlv-dap mode since dlv-dap reached feature parity.
+- Use StackOverflow as the channel for Q&A.
+
+### Thanks
+
+Thank you for your contribution, Ahmed W, Hana, Michael Currin, Polina Sokolova, Rebecca Stambler, Suzy Mueller, and Sven Efftinge!
+
+## v0.26.0 - 17 Jun, 2021
📣 [`Delve`'s native DAP implementation](https://github.com/golang/vscode-go/blob/master/docs/dlv-dap.md) is now available for use. In order to use this new debug adapter (`dlv-dap`) when debugging Go programs, add the following settings in your `settings.json`:
diff --git a/README.md b/README.md
index d68e749339..f77ecae818 100644
--- a/README.md
+++ b/README.md
@@ -8,8 +8,8 @@
provides rich language support for the
[Go programming language](https://golang.org/).
-> 📣 Debugging using [`Delve`'s native DAP implementation](https://github.com/golang/vscode-go/blob/master/docs/dlv-dap.md) is now available for use.
-> Please test it by following [the instruction to enable this new feature](https://github.com/golang/vscode-go/blob/master/docs/dlv-dap.md#getting-started) and share your feedback!
+
+> 📣 Debugging using [`Delve`'s native DAP implementation](https://github.com/golang/vscode-go/blob/master/docs/debugging.md) is enabled by default in v0.27.0.
## Quick Start
@@ -130,8 +130,7 @@ troubleshooting](docs/troubleshooting.md), and another specifically for
If the troubleshooting guides did not resolve the issue, please reach out to us
by [filing an issue](https://github.com/golang/vscode-go/issues/new/choose),
[starting a GitHub discussion](https://github.com/golang/vscode-go/discussions),
-or by asking a question in the [Gophers Slack]. We hang out in the `#vscode`
-channel!
+or by asking a question on [Stack Overflow].
Also, you can take a look at [learn.go.dev](https://learn.go.dev) and
[golang.org/help](https://golang.org/help) for more general guidance on using
@@ -161,7 +160,7 @@ conduct-related issue, please mail conduct@golang.org.
[MIT](LICENSE)
-[Gophers Slack]: https://gophers.slack.com/
+[Stack Overflow]: https://stackoverflow.com/questions/tagged/go+visual-studio-code
[`gopls`]: https://golang.org/s/gopls
[`go`]: https://golang.org/cmd/go
[Managing extensions in VS Code]: https://code.visualstudio.com/docs/editor/extension-gallery
diff --git a/docs/contributing.md b/docs/contributing.md
index 5fe1cad0bc..a7d37b7bf6 100644
--- a/docs/contributing.md
+++ b/docs/contributing.md
@@ -34,7 +34,7 @@ Please note that extra configuration is required to build and run the [Debug Ada
### Setup
-1) Install [node](https://nodejs.org/en/).
+1) Install [node](https://nodejs.org/en/). Note: make sure that you are using `npm v7` or higher. The file format for `package-lock.json` (changed significantly)[https://docs.npmjs.com/cli/v7/configuring-npm/package-lock-json#file-format] in `npm v7`.
2) Clone the repository, run `npm install`, and open VS Code:
```bash
diff --git a/docs/debugging-legacy.md b/docs/debugging-legacy.md
new file mode 100644
index 0000000000..f19622114b
--- /dev/null
+++ b/docs/debugging-legacy.md
@@ -0,0 +1,458 @@
+# Debugging with Legacy Debug Adapter
+
+The Go extension historically used a small adapter program to work with the Go debugger, [Delve].
+The extension transitioned to communicate with [Delve] directly but there are still cases you may
+need to use the legacy debug adapter (e.g. remote debugging). This document explains how to use the
+***legacy*** debug adapter.
+
+
+* [Set up](#set-up)
+ * [Installation](#installation)
+ * [Configuration](#configuration)
+* [Launch Configurations](#launch-configurations)
+ * [Specifying build tags](#specifying-build-tags)
+ * [Specifying other build flags](#specifying-other-build-flags)
+ * [Using VS Code Variables](#using-vs-code-variables)
+ * [Snippets](#snippets)
+* [Debugging on Windows Subsystem for Linux (WSL)](#debugging-on-windows-subsystem-for-linux-wsl)
+* [Remote Debugging](#remote-debugging)
+* [Troubleshooting](#troubleshooting)
+ * [Read documentation and common issues](#read-documentation-and-common-issues)
+ * [Update Delve](#update-delve)
+ * [Check for multiple versions of Delve](#check-for-multiple-versions-of-delve)
+ * [Check your launch configuration](#check-your-launch-configuration)
+ * [Check your GOPATH](#check-your-gopath)
+ * [Enable logging](#enable-logging)
+ * [Optional: Debug the debugger](#optional-debug-the-debugger)
+ * [Ask for help](#ask-for-help)
+* [Common issues](#common-issues)
+
+## Set up
+
+[Delve] (`dlv`) should be installed by default when you install this extension.
+You may need to update `dlv` to the latest version to support the latest version
+of Go. To install or update `dlv`, open the [Command Palette][]
+(Windows/Linux: Ctrl+Shift+P; OSX: Shift+Command+P), select [`Go: Install/Update Tools`](settings.md#go-installupdate-tools), and select [`dlv`](tools.md#dlv).
+
+## Selecting `legacy` debug adapter
+
+To opt in to use the legacy debug adapter (`legacy`) by default, add the following in your VSCode settings.json.
+
+```
+ "go.delveConfig": {
+ "debugAdapter": "legacy",
+ }
+```
+
+If you want to use the legacy mode for only a subset of your launch configurations, you can use [the `debugAdapter` attribute](#launchjson-attributes) to switch between `"dlv-dap"` and `"legacy"` mode.
+For [Remote Debugging](#remote-debugging) (launch configuration with `"mode": "remote"` attribute),
+the extension will use the `"legacy"` mode by default, so setting this attribute won't be necessary.
+
+Throughout this document, we assume that you opted in to use the legacy debug adapter.
+For debugging using the new debug adapter (default, `"dlv-dap"` mode), please see the documentation about [Debugging](https://github.com/golang/vscode-go/tree/master/docs/debugging-legacy.md).
+
+### Configuration
+
+You may not need to configure any settings to start debugging your programs, but you should be aware that the debugger looks at the following settings.
+
+* Related to [`GOPATH`](gopath.md):
+ * [`go.gopath`](settings.md#go.gopath)
+ * [`go.inferGopath`](settings.md#go.inferGopath)
+* [`go.delveConfig`](settings.md#go.delveConfig)
+ * `apiVersion`: Controls the version of the Delve API used (default: `2`).
+ * `dlvLoadConfig`: The configuration passed to Delve, which controls how variables are shown in the Debug pane. Not applicable when `apiVersion` is 1.
+ * `maxStringLen`: Maximum number of bytes read from a string (default: `64`).
+ * `maxArrayValues`: Maximum number of elements read from an array, slice, or map (default: `64`).
+ * `maxStructFields`: Maximum number of fields read from a struct. A setting of `-1` indicates that all fields should be read (default: `-1`).
+ * `maxVariableRecurse`: How far to recurse when evaluating nested types (default: `1`).
+ * `followPointers`: Automatically dereference pointers (default: `true`).
+ * `showGlobalVariables`: Show global variables in the Debug view (default: `false`).
+ * `debugAdapter`: Controls which debug adapter to use (default: `legacy`).
+ * `substitutePath`: Path mappings to apply to get from a path in the editor to a path in the compiled program (default: `[]`).
+
+There are some common cases when you might want to tweak the Delve configurations.
+
+* To change the default cap of 64 on string and array length when inspecting variables in the Debug view, set `maxStringLen`. (See a related known issue: [golang/vscode-go#126](https://github.com/golang/vscode-go/issues/126)).
+* To evaluate nested variables in the Run view, set `maxVariableRecurse`.
+
+## Launch Configurations
+
+To get started debugging, run the command `Debug: Open launch.json`. If you did not already have a `launch.json` file for your project, this will create one for you. It will contain this default configuration, which can be used to debug the current package. With mode `auto`, the file that is currently open will determine whether to debug the program as a test. If `program` is instead set to a Go file, that file will determine which mode to run in.
+
+```json5
+{
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "Launch",
+ "type": "go",
+ "request": "launch",
+ "mode": "auto",
+ "program": "${fileDirname}",
+ "debugAdapter": "legacy",
+ "env": {},
+ "args": []
+ }
+ ]
+}
+```
+
+There are some more properties that you can adjust in the debug configuration:
+
+Property | Description
+-------- | -----------
+name | The name for your configuration as it appears in the drop-down in the Run view.
+type | Always leave this set to `"go"`. VS Code uses this setting to determine which extension should be used for debugging.
+request | One of `launch` or `attach`. Use `attach` when you want to attach to a running process.
+mode | For `launch` requests, one of `auto`, `debug`, `remote`, `test`, or `exec`. For `attach` requests, use `local` or `remote`.
+program | In `test` or `debug` mode, this refers to the absolute path to the package or file to debug. In `exec` mode, this is the existing binary file to debug. Not applicable to `attach` requests.
+env | Environment variables to use when debugging. Use the format: `{ "NAME": "VALUE" }`. Not applicable to `attach` requests.
+envFile | Absolute path to a file containing environment variable definitions. The environment variables passed in via the `env` property override the ones in this file.
+args | Array of command-line arguments to pass to the program being debugged.
+showLog | If `true` and `logDest` is not set, Delve logs will be printed in the Debug Console panel. If `true` and `logDest` is set, logs will be written to the `logDest` file. This corresponds to `dlv`'s `--log` flag.
+logOutput | Comma-separated list of Delve components (`debugger`, `gdbwire`, `lldbout`, `debuglineerr`, `rpc`) that should produce debug output when `showLog` is `true`. This corresponds to `dlv`'s `--log-output` flag.
+logDest | Absolute path to the delve log output file. This corresponds to `dlv`'s `--log-dest` flag, but number (used for file descriptor) is disallowed. Supported only in dlv-dap mode on Linux and Mac.
+buildFlags | Build flags to pass to the Go compiler. This corresponds to `dlv`'s `--build-flags` flag.
+dlvFlags | Extra flags passed to `dlv`. See `dlv help` for the full list of supported flags. This is useful when users need to pass less commonly used or new flags such as `--only-same-user`, `--check-go-version`. Note that some flags such as `--log-output`, `--log`, `--log-dest`, `--api-version` already have corresponding properties in the debug configuration, and flags such as `--listen` and `--headless` are used internally. If they are specified in `dlvFlags`, they may be ignored or cause an error.
+remotePath | If remote debugging (`mode`: `remote`), this should be the absolute path to the package being debugged on the remote machine. See the section on [Remote Debugging](#remote-debugging) for further details. [golang/vscode-go#45](https://github.com/golang/vscode-go/issues/45) is also relevant. Becomes the first mapping in substitutePath.
+substitutePath | An array of mappings from an absolute local path to an absolute remote path that is used by the debuggee. The debug adapter will replace the local path with the remote path in all of the calls. The mappings are applied in order, and the first matching mapping is used. This can be used to map files that have moved since the program was built, different remote paths, and symlinked files or directories. This is intended to be equivalent to the [substitute-path](https://github.com/go-delve/delve/tree/master/Documentation/cli#config) configuration, and will eventually configure substitute-path in Delve directly.
+cwd | The working directory to be used in running the program. If remote debugging (`mode`: `remote`), this should be the absolute path to the working directory being debugged on the local machine. The extension defaults to the workspace folder, or the workspace folder of the open file in multi root workspaces. See the section on [Remote Debugging](#remote-debugging) for further details. [golang/vscode-go#45](https://github.com/golang/vscode-go/issues/45) is also relevant.
+processId | This is the process ID of the executable you want to debug. Applicable only when using the `attach` request in `local` mode. By setting this to the command name of the process, `${command:pickProcess}`, or`${command:pickGoProcess}` a quick pick menu will show a list of processes to choose from.
+
+### Specifying [build tags](https://golang.org/pkg/go/build/#hdr-Build_Constraints)
+
+If your program contains [build tags](https://golang.org/pkg/go/build/#hdr-Build_Constraints), you can use the `buildFlags` property. For example, if you build your code with:
+
+```bash
+go build -tags=whatever
+```
+
+Then, set:
+
+```json5
+"buildFlags": "-tags=whatever"
+```
+
+in your launch configuration. This property supports multiple tags, which you can set by using single quotes. For example:
+
+```json5
+"buildFlags": "-tags='first,second,third'"
+```
+
+
+
+### Specifying other build flags
+
+The flags specified in `buildFlags` and `env.GOFLAGS` are passed to the Go compiler when building your program for debugging. Delve adds `-gcflags='all=-N -l'` to the list of build flags to disable optimizations. User specified buildFlags conflict with this setting, so the extension removes them ([Issue #117](https://github.com/golang/vscode-go/issues/117)). If you wish to debug a program using custom `-gcflags`, build the program using `go build` and launch using `exec` mode:
+
+```json
+{
+ "name": "Launch executable",
+ "type": "go",
+ "request": "launch",
+ "mode": "exec",
+ "program": "/absolute/path/to/executable"
+}
+```
+
+Note that it is not recommended to debug optimized executables as Delve may not have the information necessary to properly debug your program.
+
+### Using [VS Code variables]
+
+Any property in the launch configuration that requires a file path can be specified in terms of [VS Code variables]. Here are some useful ones to know:
+
+* `${workspaceFolder}` refers to the root of the workspace opened in VS Code. If using a multi root workspace, you must specify the folder name `${workspaceFolder:folderName}`
+* `${fileWorkspaceFolder}` refers to the the current opened file's workspace folder.
+* `${file}` refers to the currently opened file.
+* `${fileDirname}` refers to the directory containing the currently opened file. This is typically also the name of the Go package containing this file, and as such, can be used to debug the currently opened package.
+
+### Snippets
+
+In addition to [VS Code variables], you can make use of [snippets] when editing the launch configuration in `launch.json`.
+
+When you type `go` in the `launch.json` file, you will see snippet suggestions for debugging the current file or package or a given test function.
+
+Below are the available sample configurations:
+
+#### Debug the current file (`Go: Launch file`)
+
+Recall that `${file}` refers to the currently opened file (see [Using VS Code Variables](#using-vs-code-variables)). For debugging a package that consists with multiple files, use `${fileDirname}` instead.
+
+```json5
+{
+ "name": "Launch file",
+ "type": "go",
+ "request": "launch",
+ "mode": "auto",
+ "program": "${file}"
+}
+```
+
+#### Debug a single test function (`Go: Launch test function`)
+
+Recall that `${workspaceFolder}` refers to the current workspace (see [Using VS Code Variables](#using-vs-code-variables)). You will need to manually specify the function name instead of `"MyTestFunction"`.
+
+```json5
+{
+ "name": "Launch test function",
+ "type": "go",
+ "request": "launch",
+ "mode": "test",
+ "program": "${workspaceFolder}",
+ "args": [
+ "-test.run",
+ "MyTestFunction"
+ ]
+}
+```
+
+#### Debug all tests in the given package (`Go: Launch test package`)
+
+A package is a collection of source files in the same directory that are compiled together.
+Recall that `${fileDirname}` refers to the directory of the open file (see [Using VS Code Variables](#using-vs-code-variables)).
+
+```json5
+{
+ "name": "Launch test package",
+ "type": "go",
+ "request": "launch",
+ "mode": "test",
+ "program": "${workspaceFolder}"
+}
+```
+
+#### Attach to a running local process via its process ID (`Go: Attach to local process`)
+
+Substitute `processName` with the name of the local process.
+
+```json5
+{
+ "name": "Attach to local process",
+ "type": "go",
+ "request": "attach",
+ "mode": "local",
+ "processId": "processName"
+}
+```
+
+#### Attach to a running server (`Go: Connect to Server`)
+
+```json5
+{
+ "name": "Connect to server",
+ "type": "go",
+ "request": "attach",
+ "mode": "remote",
+ "remotePath": "${workspaceFolder}",
+ "port": 2345,
+ "host": "127.0.0.1"
+}
+```
+
+#### Debug an existing binary
+
+There is no snippet suggestion for this configuration.
+
+```json
+{
+ "name": "Launch executable",
+ "type": "go",
+ "request": "launch",
+ "mode": "exec",
+ "program": "/absolute/path/to/executable"
+}
+```
+
+If passing arguments to or calling subcommands and flags from a binary, the `args` property can be used.
+
+```json
+{
+ "name": "Launch executable",
+ "type": "go",
+ "request": "launch",
+ "mode": "exec",
+ "program": "/absolute/path/to/executable",
+ "args": ["subcommand", "arg", "--flag"],
+}
+```
+
+## Debugging on [Windows Subsystem for Linux (WSL)](https://docs.microsoft.com/en-us/windows/wsl/)
+
+If you are using using WSL, you will need the WSL 2 Linux kernel. See [WSL 2 Installation](https://docs.microsoft.com/en-us/windows/wsl/wsl2-install) and note the Window 10 build version requirements.
+
+## Remote Debugging
+
+
+
+To debug on a remote machine, you must first run a headless Delve server on the target machine. The examples below assume that you are in the same folder as the package you want to debug. If not, please refer to the [`dlv debug` documentation](https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_debug.md).
+
+To start the headless Delve server:
+
+```bash
+dlv debug --headless --listen=:2345 --log --api-version=2
+```
+
+Any arguments that you want to pass to the program you are debugging must also be passed to this Delve server. For example:
+
+```bash
+dlv debug --headless --listen=:2345 --log -- -myArg=123
+```
+
+Then, create a remote debug configuration in your `launch.json`.
+
+```json5
+{
+ "name": "Launch remote",
+ "type": "go",
+ "request": "attach",
+ "mode": "remote",
+ "remotePath": "/absolute/path/dir/on/remote/machine",
+ "port": 2345,
+ "host": "127.0.0.1",
+ "cwd": "/absolute/path/dir/on/local/machine",
+}
+```
+
+In the example, the VS Code debugger will run on the same machine as the headless `dlv` server. Make sure to update the `port` and `host` settings to point to your remote machine.
+
+`remotePath` should point to the absolute path of the program being debugged in the remote machine. `cwd` should point to the absolute path of the working directory of the program being debugged on your local machine. This should be the counterpart of the folder in `remotePath`. See [golang/vscode-go#45](https://github.com/golang/vscode-go/issues/45) for updates regarding `remotePath` and `cwd`. You can also use the equivalent `substitutePath` configuration.
+
+```json5
+{
+ "name": "Launch remote",
+ "type": "go",
+ "request": "attach",
+ "mode": "remote",
+ "substitutePath": [
+ {
+ "from": "/absolute/path/dir/on/local/machine",
+ "to": "/absolute/path/dir/on/remote/machine",
+ },
+ ],
+ "port": 2345,
+ "host": "127.0.0.1",
+ "cwd": "/absolute/path/dir/on/local/machine",
+}
+```
+
+If you do not set, `remotePath` or `substitutePath`, then the debug adapter will attempt to infer the path mappings. See [golang/vscode-go#45](https://github.com/golang/vscode-go/issues/45) for more information.
+
+When you run the `Launch remote` target, VS Code will send debugging commands to the `dlv` server you started, instead of launching it's own `dlv` instance against your program.
+
+For further examples, see [this launch configuration for a process running in a Docker host](https://github.com/lukehoban/webapp-go/tree/debugging).
+
+## Troubleshooting
+
+Debugging is one of the most complex features offered by this extension. The features are not complete, and a new implementation is currently being developed (see [golang/vscode-go#23](https://github.com/golang/vscode-go/issues/23)).
+
+The suggestions below are intended to help you troubleshoot any problems you encounter. If you are unable to resolve the issue, please take a look at the [current known debugging issues](https://github.com/golang/vscode-go/issues?q=is%3Aissue+is%3Aopen+label%3Adebug) or [file a new issue](https://github.com/golang/vscode-go/issues/new/choose).
+
+### Read documentation and [common issues](#common-issues)
+
+Start by taking a quick glance at the [common issues](#common-issues) described below. You can also check the [Delve FAQ](https://github.com/go-delve/delve/blob/master/Documentation/faq.md) in case the problem is mentioned there.
+
+### Update Delve
+
+If the problem persists, it's time to start troubleshooting. A good first step is to make sure that you are working with the latest version of Delve. You can do this by running the [`Go: Install/Update Tools`](settings.md#go-installupdate-tools) command and selecting [`dlv`](tools.md#dlv).
+
+### Check your [launch configuration](#launch-configurations)
+
+Next, confirm that your [launch configuration](#launch-configurations) is correct.
+
+One common error is `could not launch process: stat ***/debug.test: no such file or directory`. You may see this while running in the `test` mode. This happens when the `program` attribute points to a folder with no test files, so ensure that the `program` attribute points to a directory containing the test files you wish to debug.
+
+Also, check the version of the Delve API used in your [launch configuration](#launch-configurations). This is handled by the `–api-version` flag, `2` is the default. If you are debugging on a remote machine, this is particularly important, as the versions on the local and remote machines much match. You can change the API version by editing the [`launch.json` file](#launch-configurations).
+
+### Check for multiple versions of Delve
+
+You might have multiple different versions of [`dlv`](tools.md#dlv) installed, and VS Code Go could be using a wrong or old version. Run the [`Go: Locate Configured Go Tools`](settings.md#go-locate-configured-go-tools) command and see where VS Code Go has found `dlv` on your machine. You can try running `which dlv` to see which version of `dlv` you are using on the [command-line](https://github.com/go-delve/delve/tree/master/Documentation/cli).
+
+To fix the issue, simply delete the version of `dlv` used by the Go extension. Note that the extension first searches for binaries in your `$GOPATH/bin` and then looks on your `$PATH`.
+
+If you see the error message `Failed to continue: "Error: spawn EACCES"`, the issue is probably multiple versions of `dlv`.
+
+### Try building your binary **without** compiler optimizations
+
+If you notice `Unverified breakpoints` or missing variables, ensure that your binary was built **without** compiler optimizations. Try building the binary with `-gcflags="all=-N -l"`.
+
+### Check your `GOPATH`
+
+Make sure that the debugger is using the right [`GOPATH`](gopath.md). This is probably the issue if you see `Cannot find package ".." in any of ...` errors. Read more about configuring your [GOPATH](gopath.md) or [file an issue report](https://github.com/golang/vscode-go/issues/new/choose).
+
+**As a work-around**, add the correct `GOPATH` as an environment variable in the `env` property in the `launch.json` file.
+
+### Enable logging
+
+Next, check the logs produced by Delve. These will need to be manually enabled. Follow these steps:
+
+* Set `"showLog": true` in your launch configuration. This will show Delve logs in the Debug Console pane (Ctrl+Shift+Y).
+* Set `"trace": "log"` in your launch configuration. Again, you will see logs in the Debug Console pane (Ctrl+Shift+Y). These logs will also be saved to a file and the path to this file will be printed at the top of the Debug Console.
+* Set `"logOutput": "rpc"` in your launch configuration. You will see logs of the RPC messages going between VS Code and Delve. Note that for this to work, you must also have set `"showLog": true`.
+ * The `logOutput` attribute corresponds to the `--log-output` flag used by Delve. It is a comma-separated list of components that should produce debug output.
+
+See [common issues](#common-issues) below to decipher error messages you may find in your logs.
+
+With `"trace": "log"`, you will see the actual call being made to `dlv`. To aid in your investigation, you can copy that and run it in your terminal.
+
+### **Optional**: Debug the debugger
+
+This is not a required step, but if you want to continue digging deeper, you can, in fact, debug the debugger. The code for the debugger can be found in the [debug adapter module](../src/debugAdapter). See our [contribution guide](contributing.md) to learn how to [run](contributing.md#run) and [sideload](contributing.md#sideload) the Go extension.
+
+### Ask for help
+
+At this point, it's time to look at the [common issues](#common-issues) below or the [existing debugging issues](https://github.com/golang/vscode-go/issues?q=is%3Aissue+is%3Aopen+label%3Adebug) on the [issue tracker](https://github.com/golang/vscode-go/issues). If that still doesn't solve your problem, [file a new issue](https://github.com/golang/vscode-go/issues/new/choose).
+
+## Common Issues
+
+### delve/launch hangs with no messages on WSL
+
+Try running ```delve debug ./main``` in the WSL command line and see if you get a prompt.
+
+**_Solution_**: Ensure you are running the WSL 2 Kernel, which (as of 4/15/2020) requires an early release of the Windows 10 OS. This is available to anyone via the Windows Insider program. See [Debugging on WSL](#debugging-on-windows-subsystem-for-linux-wsl).
+
+### could not launch process: could not fork/exec
+
+The solution this issue differs based on your OS.
+
+#### OSX
+
+This usually happens on OSX due to signing issues. See the discussions in [Microsoft/vscode-go#717](https://github.com/Microsoft/vscode-go/issues/717), [Microsoft/vscode-go#269](https://github.com/Microsoft/vscode-go/issues/269) and [go-delve/delve#357](https://github.com/go-delve/delve/issues/357).
+
+**_Solution_**: You may have to uninstall dlv and install it manually as described in the [Delve instructions](https://github.com/go-delve/delve/blob/master/Documentation/installation/osx/install.md#manual-install).
+
+#### Linux/Docker
+
+Docker has security settings preventing `ptrace(2)` operations by default within the container.
+
+**_Solution_**: To run your container insecurely, pass `--security-opt=seccomp:unconfined` to `docker run`. See [go-delve/delve#515](https://github.com/go-delve/delve/issues/515) for references.
+
+#### could not launch process: exec: "lldb-server": executable file not found in $PATH
+
+This error can show up for Mac users using Delve versions 0.12.2 and above. `xcode-select --install` has solved the problem for a number of users.
+
+### Debugging symlink directories
+
+Since the debugger and go compiler use the actual filenames, extra configuration is required to debug symlinked directories. Use the `substitutePath` property to tell the debugAdapter how to properly translate the paths. For example, if your project lives in `/path/to/actual/helloWorld`, but the project is open in vscode under the linked folder `/path/to/hello`, you can add the following to your config to set breakpoints in the files in `/path/to/hello`:
+
+```json5
+{
+ "name": "Launch remote",
+ "type": "go",
+ "request": "launch",
+ "mode": "debug",
+ "program": "/path/to/hello",
+ "substitutePath": [
+ {
+ "from": "/path/to/hello",
+ "to": "/path/to/actual/helloWorld",
+ },
+ ],
+}
+```
+
+This extension does not provide general support for debugging projects containing symlinks. If `substitutePath` does not meet your needs, please consider commenting on this issue that contains updates to symlink support reference [golang/vscode-go#622](https://github.com/golang/vscode-go/issues/622).
+
+[Delve]: https://github.com/go-delve/delve
+[VS Code variables]: https://code.visualstudio.com/docs/editor/variables-reference
+[snippets]: https://code.visualstudio.com/docs/editor/userdefinedsnippets
+[Command Palette]: https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette
diff --git a/docs/debugging.md b/docs/debugging.md
index d800dfd942..baff27bde5 100644
--- a/docs/debugging.md
+++ b/docs/debugging.md
@@ -1,459 +1,428 @@
# Debugging
-This document explains how to debug your Go programs in VS Code. The Go debugger is [Delve]. You can read more about it in the [Delve documentation](https://github.com/go-delve/delve/tree/master/Documentation).
+The Go extension allows you to launch or attach to Go programs for debugging. You can inspect variables and stacks, setting breakpoints, and do other debugging activities using [VS Code’s Debugging UI](https://code.visualstudio.com/docs/editor/debugging).
-📣 Integration with the [Delve's native DAP implementation](https://github.com/golang/vscode-go/tree/master/docs/dlv-dap.md) is available for preview. Please give it a try and provide feedback!
+These debugging features are possible by using [Delve](https://github.com/go-delve/delve), the Go debugger.
+The Go extension has been communicating with Delve through a custom debug adapter program (`legacy` mode).
+As the new [`Delve`'s native DAP implementation](https://github.com/go-delve/delve/tree/master/service/dap) becomes available,
+the Go extension is transitioning to skip the legacy debug adapter and directly communicate with Delve for local debugging.
-## Overview
+** 📣 We are happy to announce that now this new mode of Delve integration (_`dlv-dap`_ mode) is enabled for _local_ _debugging_ by default! **
-* [Set up](#set-up)
- * [Installation](#installation)
- * [Configuration](#configuration)
-* [Launch Configurations](#launch-configurations)
- * [Specifying build tags](#specifying-build-tags)
- * [Specifying other build flags](#specifying-other-build-flags)
- * [Using VS Code Variables](#using-vs-code-variables)
- * [Snippets](#snippets)
-* [Debugging on Windows Subsystem for Linux (WSL)](#debugging-on-windows-subsystem-for-linux-wsl)
-* [Remote Debugging](#remote-debugging)
-* [Troubleshooting](#troubleshooting)
- * [Read documentation and common issues](#read-documentation-and-common-issues)
- * [Update Delve](#update-delve)
- * [Check for multiple versions of Delve](#check-for-multiple-versions-of-delve)
- * [Check your launch configuration](#check-your-launch-configuration)
- * [Check your GOPATH](#check-your-gopath)
- * [Enable logging](#enable-logging)
- * [Optional: Debug the debugger](#optional-debug-the-debugger)
- * [Ask for help](#ask-for-help)
-* [Common issues](#common-issues)
+Delve DAP implementation's support for remote debugging is still a work in progress and the Go extension still uses
+the legacy debug adapter for the debug configuration with the `"remote"` mode.
-## Set up
+Many features and settings described in this document may be available only with the new `dlv-dap` mode.
+For troubleshooting and configuring the legacy debug adapter, see [the legacy debug adapter documentation](https://github.com/golang/vscode-go/tree/master/docs/debugging-legacy.md).
-[Delve] should be installed by default when you install this extension.
+## Getting Started
-You may need to update `dlv` to the latest version to support the latest version
-of Go—see [Installation](#installation) below.
+Open a file to debug (either `package main` source file or the test file) in the editor, and select the `Run and Debug` button from [the Run view](https://code.visualstudio.com/docs/editor/debugging#_run-view). Alternatively, you can start debugging using `Start Debugging (F5)` command from [the Run menu](https://code.visualstudio.com/docs/editor/debugging#_run-menu) or from [the Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette) (Linux/Windows: Ctrl+Shift+P, Mac: ⇧+⌘+P).
-### Installation
+When no configuration is configured yet (no `.vscode/launch.json` file), the extension will choose a default configuration based on the file open in the editor.
-You can also install Delve manually in one of two ways:
+If you already have launch configurations for the project (`.vscode/launch.json`), the Run view will display the configuration list to choose from.
-1. Open the [Command Palette][] (Windows/Linux: Ctrl+Shift+P; OSX: Shift+Command+P), select [`Go: Install/Update Tools`](settings.md#go-installupdate-tools), and select [`dlv`](tools.md#dlv).
-2. Follow the [Delve installation instructions](https://github.com/go-delve/delve/tree/master/Documentation/installation).
+
+
+
+❗ When you start debugging in `dlv-dap` mode for the first time, the extension will ask to install Delve built from head (`dlv-dap`). Please follow the instructions to install, and then start the debugging session again (i.e. selecting the source file, pressing F5 or click the codelens).
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Allowed Values: `"default"`, `"native"`, `"lldb"`
|
Allowed Values: `"legacy"`, `"dlv-dap"`
(Default: `dlv-dap`)
|
Allowed Values: `"debugger"`, `"gdbwire"`, `"lldbout"`, `"debuglineerr"`, `"rpc"`, `"dap"`
(Default: `"debugger"`)
|
Allowed Values: `"auto"`, `"debug"`, `"test"`, `"exec"`
(Default: `auto`)
| Indicates local or remote debugging. Local maps to the `dlv attach` command, remote maps to `connect`. `remote` is not supported in `dlv-dap` mode currently. Use `host` and `port` instead.
Allowed Values: `"local"`, `"remote"`
(Default: `local`)
|
+| `output` | Output path for the binary of the debugee.
(Default: `"debug"`)
|
Option 1: Use process picker to select a process to attach, or Process ID as integer.
Allowed Values: `"${command:pickProcess}"`, `"${command:pickGoProcess}"`
Option 2: Attach to a process by name. If more than one process matches the name, use the process picker to select a process.
Option 3: The numeric ID of the process to be debugged. If 0, use the process picker to select a process.
(Default: `0`)
|
+| `program` | Path to the program folder (or any go file within that folder) when in `debug` or `test` mode, and to the pre-built binary file to debug in `exec` mode. If it is not an absolute path, the extension interpretes it as a workspace relative path.
(Default: `"${workspaceFolder}"`)
|
Allowed Values: `"verbose"`, `"trace"`, `"log"`, `"info"`, `"warn"`, `"error"`
(Default: `"error"`)
|
"followPointers" : true,} ``` | | `showGlobalVariables` | Boolean value to indicate whether global package variables should be shown in the variables pane or not.
"maxArrayValues" : 64,
"maxStringLen" : 64,
"maxStructFields" : -1,
"maxVariableRecurse" : 1,
+ Heads up! + The extension now uses Delve's native DAP implementation (dlv-dap) + for local debugging. We updated the + Documentation for Debugging to show the new features available with dlv-dap. + This change does not apply to remote debugging yet. For remote debugging, keep following + the instruction in the old documentation. +
+Option %d: %v
", i+1, describeDebugProperty(&a))
+ }
+ }
+
+ if len(p.Enum) > 0 {
+ var enums []string
+ for _, i := range p.Enum {
+ enums = append(enums, fmt.Sprintf("`%#v`", i))
+ }
+ fmt.Fprintf(b, "
Allowed Values: %v
", strings.Join(enums, ", "))
+ }
+
+ if p.Type == "object" && len(p.Properties) > 0 {
+
+ var keys []string
+ for k := range p.Properties {
+ keys = append(keys, k)
+ }
+ sort.Strings(keys)
+ fmt.Fprintf(b, "
%v
", describeDebugProperty(p.Items))
+ }
+
+ // Default
+ if d := defaultDescriptionSnippet(p); d != "" {
+ fmt.Fprintf(b, "(Default: `%v`)
", d)
+ }
+ return b.String()
+}
diff --git a/tools/relnotes/relnotes.go b/tools/relnotes/relnotes.go
new file mode 100644
index 0000000000..c1684ba13d
--- /dev/null
+++ b/tools/relnotes/relnotes.go
@@ -0,0 +1,305 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// The relnotes command summarizes the Go changes in Gerrit marked with
+// RELNOTE annotations for the release notes.
+package main
+
+import (
+ "bytes"
+ "context"
+ "flag"
+ "fmt"
+ "io/ioutil"
+ "log"
+ "path/filepath"
+ "regexp"
+ "sort"
+ "strings"
+ "time"
+ "unicode"
+
+ "golang.org/x/build/maintner"
+ "golang.org/x/build/maintner/godata"
+)
+
+var (
+ milestone = flag.String("milestone", "", "milestone associated with the release")
+ filterDirs = flag.String("dirs", "", "comma-separated list of directories that should be touched for a CL to be considered relevant")
+ sinceCL = flag.Int("cl", -1, "the gerrit change number of the first CL to include in the output. Only changes submitted more recently than 'cl' will be included.")
+ project = flag.String("project", "vscode-go", "name of the golang project")
+ mdMode = flag.Bool("md", false, "write MD output")
+ exclFile = flag.String("exclude-from", "", "optional path to changelog MD file. If specified, any 'CL NNNN' occurence in the content will cause that CL to be excluded from this tool's output.")
+)
+
+// change is a change that has occurred since the last release.
+type change struct {
+ CL *maintner.GerritCL
+ Note string // the part after RELNOTE=
+ Issues []*issue
+ pkg string
+}
+
+func (c change) TextLine() string {
+ subj := c.CL.Subject()
+ subj = c.Note + ": " + subj
+ return fmt.Sprintf("https://golang.org/cl/%d: %s", c.CL.Number, subj)
+}
+
+type issue struct {
+ *maintner.GitHubIssue
+ repo string
+ owner string
+}
+
+func (i *issue) link() string {
+ if i.owner == "golang" && i.repo == "go" {
+ return fmt.Sprintf("https://golang.org/issue/%v", i.Number)
+ }
+ return fmt.Sprintf("https://github.com/%s/%s/issues/%v", i.owner, i.repo, i.Number)
+}
+
+func main() {
+ flag.Parse()
+
+ var existingMD []byte
+ if *exclFile != "" {
+ var err error
+ existingMD, err = ioutil.ReadFile(*exclFile)
+ if err != nil {
+ log.Fatal(err)
+ }
+ }
+
+ corpus, err := godata.Get(context.Background())
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ var dirs []string
+ for _, dir := range strings.FieldsFunc(*filterDirs, func(r rune) bool {
+ return unicode.IsSpace(r) || r == ','
+ }) {
+ dirs = append(dirs, filepath.ToSlash(dir))
+ }
+
+ ger := corpus.Gerrit()
+
+ // Find the cutoff time for changes to include.
+ start := time.Date(2020, time.August, 1, 00, 00, 00, 0, time.UTC)
+ ger.ForeachProjectUnsorted(func(gp *maintner.GerritProject) error {
+ if gp.Server() != "go.googlesource.com" || gp.Project() != *project {
+ return nil
+ }
+ gp.ForeachCLUnsorted(func(cl *maintner.GerritCL) error {
+ if cl.Status != "merged" {
+ return nil
+ }
+ if *sinceCL >= 0 {
+ if int(cl.Number) == *sinceCL {
+ start = cl.Commit.CommitTime
+ }
+ } else if cl.Branch() == "release" && cl.Commit.CommitTime.After(start) {
+ // Try to figure out when the last release was
+ fmt.Println(cl.Commit.CommitTime)
+ start = cl.Commit.CommitTime
+ }
+ return nil
+ })
+ return nil
+ })
+
+ var changes []*change
+ authors := map[*maintner.GitPerson]bool{}
+ ger.ForeachProjectUnsorted(func(gp *maintner.GerritProject) error {
+ if gp.Server() != "go.googlesource.com" || gp.Project() != *project {
+ return nil
+ }
+ gp.ForeachCLUnsorted(func(cl *maintner.GerritCL) error {
+ // Only include 'master'
+ if cl.Branch() != "master" {
+ return nil
+ }
+ if cl.Status != "merged" {
+ return nil
+ }
+ if cl.Commit.CommitTime.Before(start) {
+ // Was in a previous release; not for this one.
+ return nil
+ }
+
+ if bytes.Contains(existingMD, []byte(fmt.Sprintf("CL %d ", cl.Number))) {
+ return nil
+ }
+
+ // Check that at least one file is in a relevant directory before
+ // adding the CL.
+ if len(dirs) > 0 {
+ var found bool
+ for _, file := range cl.Commit.Files {
+ for _, dir := range dirs {
+ if strings.Contains(file.File, dir) {
+ found = true
+ break
+ }
+ }
+ }
+ if !found {
+ return nil
+ }
+ }
+
+ // try to determine type from issue labels
+ var issues []*issue
+ for _, ref := range cl.GitHubIssueRefs {
+ i := ref.Repo.Issue(ref.Number)
+ // Don't include pull requests.
+ if i.PullRequest {
+ continue
+ }
+ issues = append(issues, &issue{
+ repo: ref.Repo.ID().Repo,
+ owner: ref.Repo.ID().Owner,
+ GitHubIssue: i,
+ })
+ }
+
+ changes = append(changes, &change{
+ Note: clRelNote(cl),
+ CL: cl,
+ Issues: issues,
+ pkg: clPackage(cl),
+ })
+
+ authors[cl.Owner()] = true
+ return nil
+ })
+ return nil
+ })
+
+ sort.Slice(changes, func(i, j int) bool {
+ return changes[i].CL.Number < changes[j].CL.Number
+ })
+
+ if *mdMode {
+ fmt.Printf("## TODO: version - ")
+ now := time.Now()
+ fmt.Printf("%s\n\n", now.Format("2 Jan, 2006"))
+ fmt.Printf("### Changes\n\n")
+ mdPrintChanges(changes, true)
+
+ fmt.Printf("### Issues\n\n")
+ mdPrintIssues(changes, *milestone)
+
+ fmt.Printf("\n### Thanks\n\n")
+ mdPrintContributors(authors)
+ } else {
+ for _, change := range changes {
+ fmt.Printf(" %s\n", change.TextLine())
+ }
+ }
+}
+
+func mdPrintChanges(changes []*change, byPackage bool) {
+ printChange := func(change *change) {
+ fmt.Printf("- ")
+ content := change.CL.Subject()
+ if change.Note != "" && change.Note != "yes" && change.Note != "y" {
+ // Note contains content
+ content = change.Note
+ }
+
+ fmt.Printf("%s", content)
+ if len(change.CL.GitHubIssueRefs) > 0 {
+ fmt.Printf(" (")
+ for i, ref := range change.CL.GitHubIssueRefs {
+
+ if i == 0 {
+ fmt.Printf("[Issue %d](https://github.com/%s/issues/%d)", ref.Number, ref.Repo.ID().String(), ref.Number)
+ } else {
+ fmt.Printf(", [%d](https://github.com/%s/issues/%d)", ref.Number, ref.Repo.ID().String(), ref.Number)
+ }
+ }
+ fmt.Printf(")")
+ }
+ fmt.Printf(" \n", change.CL.Number)
+ }
+ // Group CLs by package or by number order.
+ if byPackage {
+ pkgMap := map[string][]*change{}
+ for _, change := range changes {
+ pkgMap[change.pkg] = append(pkgMap[change.pkg], change)
+ }
+ for _, changes := range pkgMap {
+ for _, change := range changes {
+ printChange(change)
+ }
+ }
+ } else {
+ for _, change := range changes {
+ printChange(change)
+ }
+ }
+}
+
+func mdPrintIssues(changes []*change, milestone string) {
+ var issues []*issue
+ for _, change := range changes {
+ issues = append(issues, change.Issues...)
+ }
+ sort.Slice(issues, func(i, j int) bool {
+ return issues[i].Number < issues[j].Number
+ })
+ for _, issue := range issues {
+ if !issue.Closed {
+ continue
+ }
+ fmt.Printf("%s: %s\n", issue.link(), issue.Milestone.Title)
+ }
+}
+
+// clPackage returns the package name from the CL's commit message,
+// or "??" if it's formatted unconventionally.
+func clPackage(cl *maintner.GerritCL) string {
+ subj := cl.Subject()
+ if i := strings.Index(subj, ":"); i != -1 {
+ return subj[:i]
+ }
+ return "??"
+}
+
+var relNoteRx = regexp.MustCompile(`RELNOTES?=(.+)`)
+
+func parseRelNote(s string) string {
+ if m := relNoteRx.FindStringSubmatch(s); m != nil {
+ return m[1]
+ }
+ return ""
+}
+
+func clRelNote(cl *maintner.GerritCL) string {
+ msg := cl.Commit.Msg
+ if strings.Contains(msg, "RELNOTE") {
+ return parseRelNote(msg)
+ }
+ for _, comment := range cl.Messages {
+ if strings.Contains(comment.Message, "RELNOTE") {
+ return parseRelNote(comment.Message)
+ }
+ }
+ return ""
+}
+
+func mdPrintContributors(authors map[*maintner.GitPerson]bool) {
+ var names []string
+ for author := range authors {
+ names = append(names, author.Name())
+ }
+ sort.Strings(names)
+ if len(names) > 1 {
+ names[len(names)-1] = "and " + names[len(names)-1]
+ }
+
+ fmt.Printf("Thank you for your contribution, %s!\n", strings.Join(names, ", "))
+}