Reflecting changes from golang/vscode-go@8b84a397c5

GitHub Action 2022-04-21 20:07:42 +00:00
Родитель 9fb252d2b6
Коммит 7108f4c43e
21 изменённых файлов: 96 добавлений и 108 удалений

22
Home.md

@ -4,25 +4,25 @@ Welcome to the VSCode Go Wiki!
[Remote attach debugging](./debugging#connecting-to-headless-delve-with-target-specified-at-server-start-up) is now available via Delve's native DAP implementation with Delve v1.7.3 or newer.
We plan to enable this as the default in 2022 H1 to enhance remote debugging with the same
[debugging features](./debugging.md) that are already in use for local debugging.
[debugging features](./debugging) that are already in use for local debugging.
We recommend switching your remote attach configurations in `launch.json` to use
`"debugAdapter":"dlv-dap"` now to verify that this works for you.
Please [file a new issue](https://github.com/golang/vscode-go/issues/new/choose) if you encounter any problems.
### User Documentation
* [Overview of Extension Features](features.md)
* [Overview of Extension Features](features)
* [Debugging Feature](debugging)
* [Diagnostics](https://github.com/golang/tools/blob/master/gopls/doc/analyzers.md)
* [Setting Up Your Workspace](https://github.com/golang/tools/blob/master/gopls/doc/workspace.md)
* [Available Settings](settings.md)
* [List of Extension Commands](commands.md)
* [Commonly Used `tasks.json` Setup](tasks.md)
* [3rd-party Tools Used By Extension](tools.md)
* [User Interface](ui.md)
* [FAQs](faq.md)
* [Troubleshooting](troubleshooting.md)
* [Advanced Topics](advanced.md)
* [How to Contribute](contributing.md)
* [Available Settings](settings)
* [List of Extension Commands](commands)
* [Commonly Used `tasks.json` Setup](tasks)
* [3rd-party Tools Used By Extension](tools)
* [User Interface](ui)
* [FAQs](faq)
* [Troubleshooting](troubleshooting)
* [Advanced Topics](advanced)
* [How to Contribute](contributing)

@ -1,3 +1,5 @@
### Want to contribute to this Wiki?
Update the source in the [vscode-go project's docs](https://github.com/golang/vscode-go/tree/master/docs) directory, and send a pull request.

@ -1,4 +1,3 @@
# Advanced topics
This document describes more advanced ways of working with the VS Code Go
extension.
@ -34,7 +33,7 @@ version of `go` with one of the following options.
* (Preferred) Adjust your `PATH` or `Path` environment variable, and *open VS
Code with the adjusted environment* variable, or
* Use the Go extension's `"Go: Choose Go Environment"` command that opens a
[menu](ui.md) to change the `go` version, or
[menu](ui) to change the `go` version, or
* Use the `"go.alternateTools"` settings and specify the absolute path to the
`go` command. `"go.alternateTools": { "go": "/path/to/go/command" }`

@ -1,8 +1,7 @@
# Commands
In addition to integrated editing features, this extension offers a number of commands, which can be executed manually through the [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette) (Ctrl+Shift+P on Linux/Windows or Cmd+Shift+P on Mac OS).
Some of these commands are also available in the VS Code context menu (right-click). To control which of these commands show up in the editor context menu, update the [`"go.editorContextMenuCommands"`](settings.md#go.editorContextMenuCommands) setting.
Some of these commands are also available in the VS Code context menu (right-click). To control which of these commands show up in the editor context menu, update the [`"go.editorContextMenuCommands"`](settings#go.editorContextMenuCommands) setting.
All commands provided by this extension have the prefix `Go:`.

@ -1,8 +1,7 @@
# Contributing
We welcome your contributions and thank you for working to improve the Go development experience in VS Code.
This guide will explain the process of setting up your development environment to work on the VS Code Go extension, as well as the process of sending out your change for review. If you're interested in testing the master branch or pre-releases of the extension, please see the [Go Nightly documentation](nightly.md).
This guide will explain the process of setting up your development environment to work on the VS Code Go extension, as well as the process of sending out your change for review. If you're interested in testing the master branch or pre-releases of the extension, please see the [Go Nightly documentation](nightly).
Our canonical Git repository is located at https://go.googlesource.com/vscode-go and https://github.com/golang/vscode-go is a mirror.

@ -1,4 +1,3 @@
# Debug Adapter
The [Debug Adapter](../src/debugAdapter) runs in a separate Node.js process, which is spawned by VS Code when you debug Go code.
@ -15,11 +14,11 @@ This codebase is currently in flux: We are working on using [`Delve`'s native DA
## Before you begin
Before you start working on your change, please read the [contribution guidelines](contributing.md). This document assumes that you are already familiar with the process of [building](contributing.md#setup), [running](contributing.md#run), and [sideloading](contributing.md#sideload) the VS Code Go extension.
Before you start working on your change, please read the [contribution guidelines](contributing). This document assumes that you are already familiar with the process of [building](contributing#setup), [running](contributing#run), and [sideloading](contributing#sideload) the VS Code Go extension.
## Debug only the Debug Adapter
As a next step, you may want to debug the Debug Adapter, in order to understand how your change work with [Delve](tools.md#delve).
As a next step, you may want to debug the Debug Adapter, in order to understand how your change work with [Delve](tools#delve).
**NOTE: Since the Debug Adapter runs in a separate process from the rest of the extension, the steps below only enable you to debug the Debug Adapter code, not the entire extension. To debug the entire extension, as well as the debug adapter, see the instructions [below](#debug-the-entire-extension).**
@ -49,7 +48,7 @@ First, ensure that you can [build and run VS Code](https://github.com/Microsoft/
Next, follow these steps:
1. Open an instance of VS Code that you have built from source.
2. [Sideload](contributing.md#sideload) your local `vscode-go` extension to the local instance of VS Code. This can be done by copying the contents of the `vscode-go` directory into `$HOME/.vscode-oss-dev/extensions/ms-vscode.go` (the exact location may vary by OS).
2. [Sideload](contributing#sideload) your local `vscode-go` extension to the local instance of VS Code. This can be done by copying the contents of the `vscode-go` directory into `$HOME/.vscode-oss-dev/extensions/ms-vscode.go` (the exact location may vary by OS).
3. Open the `vscode` folder in Visual Studio Code.
4. Launch the VS Code debug instance (OSS - Code) by choosing the `Launch VS Code` debug configuration from the drop-down in the Run view. Add breakpoints as needed.
5. In another instance of VS Code, open the `vscode-go` folder. Choose the `Launch as server` debug configuration in the Run view. Add breakpoints as desired in the [`vscode-go/src/debugAdapter/goDebug.ts`](../src/debugAdapter/goDebug.ts) file.

@ -1,4 +1,3 @@
# 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
@ -32,7 +31,7 @@ need to use the legacy debug adapter (e.g. remote debugging). This document expl
[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).
(Windows/Linux: Ctrl+Shift+P; OSX: Shift+Command+P), select [`Go: Install/Update Tools`](settings#go-installupdate-tools), and select [`dlv`](tools#dlv).
## Selecting `legacy` debug adapter
@ -55,10 +54,10 @@ For debugging using the new debug adapter (default, `"dlv-dap"` mode), please se
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)
* Related to [`GOPATH`](gopath):
* [`go.gopath`](settings#go.gopath)
* [`go.inferGopath`](settings#go.inferGopath)
* [`go.delveConfig`](settings#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`).
@ -353,7 +352,7 @@ Start by taking a quick glance at the [common issues](#common-issues) described
### 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).
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#go-installupdate-tools) command and selecting [`dlv`](tools#dlv).
### Check your [launch configuration](#launch-configurations)
@ -365,7 +364,7 @@ Also, check the version of the Delve API used in your [launch configuration](#la
### 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).
You might have multiple different versions of [`dlv`](tools#dlv) installed, and VS Code Go could be using a wrong or old version. Run the [`Go: Locate Configured Go Tools`](settings#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`.
@ -377,7 +376,7 @@ If you notice `Unverified breakpoints` or missing variables, ensure that your bi
### 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).
Make sure that the debugger is using the right [`GOPATH`](gopath). This is probably the issue if you see `Cannot find package ".." in any of ...` errors. Read more about configuring your [GOPATH](gopath) 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.
@ -396,7 +395,7 @@ With `"trace": "log"`, you will see the actual call being made to `dlv`. To aid
### **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.
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) to learn how to [run](contributing#run) and [sideload](contributing#sideload) the Go extension.
### Ask for help

@ -1,4 +1,3 @@
# Debugging
The Go extension allows you to launch or attach to Go programs for debugging. You can inspect variables and stacks, set breakpoints, and do other debugging activities using [VS Codes Debugging UI](https://code.visualstudio.com/docs/editor/debugging).
@ -322,7 +321,7 @@ TODO: auto-generate from package.json. -->
You can adjust the default value of the following configuration properties using `go.delveConfig` settings. These default values are useful when you choose to run a debug session without the launch configuration set in `launch.json`. For example, debug sessions started using the `Debug Test` code lenses use the adjusted values from these settings.
* [`go.delveConfig`](settings.md#go.delveConfig)
* [`go.delveConfig`](settings#go.delveConfig)
* `debugAdapter`: Controls which debug adapter to use (default: `legacy`). Select dlv-dap.
* `showGlobalVariables`: Show global variables in the Debug view (default: `false`).
* `substitutePath`: Path mappings to apply to get from a path in the editor to a path in the compiled program (default: `[]`).

1
faq.md

@ -1,4 +1,3 @@
### Syntax highlighting does not seem to work.
The default syntax highlighting for Go files is provided by a
[TextMate rule](https://github.com/jeff-hykin/better-go-syntax) embedded in VS Code,

@ -1,4 +1,3 @@
# Features
This document describes the features supported by this extension.
@ -68,7 +67,7 @@ Jump to or peek a symbol's declaration.
Find or go to the references of a symbol.
This feature is not available if you are using Go modules **without** [`gopls`](gopls.md), the Go language server.
This feature is not available if you are using Go modules **without** [`gopls`](gopls), the Go language server.
<div style="text-align: center;"><img src="images/findallreferences.gif" alt="Find references using the context menu" style="width: 75%"> </div>
@ -76,7 +75,7 @@ This feature is not available if you are using Go modules **without** [`gopls`](
Find the concrete types that implement a given interface.
This feature is not available if you are using Go modules **without** [`gopls`](gopls.md), the Go language server.
This feature is not available if you are using Go modules **without** [`gopls`](gopls), the Go language server.
<div style="text-align: center;"><img src="images/implementations.gif" alt="Go to implementations for Server that implements http.Handler and then finds all implementations of http.Handler in the workspace" style="width: 75%"> </div>
@ -100,7 +99,7 @@ See all the symbols in the current file in the VS Code's [Outline view](https://
### Toggle between code and tests
Quickly toggle between a file and its corresponding test file by using the [`Go: Toggle Test File`](commands.md#go-toggle-test-file) command.
Quickly toggle between a file and its corresponding test file by using the [`Go: Toggle Test File`](commands#go-toggle-test-file) command.
<div style="text-align: center;"><img src="images/toggletestfile.gif" alt="Toggle between reverse.go and reverse_test.go" style="width: 75%"> </div>
@ -135,7 +134,7 @@ When organizing imports, the imported packages are grouped in the default `goimp
#### Add import
The extension organizes imports automatically and can add missing imports if the package is present in your module cache already. However, you can also manually add a new import to your file through the [`Go: Add Import`](commands.md#go-add-import) command. Available packages are offered from module cache (or from your `GOPATH` in GOPATH mode).
The extension organizes imports automatically and can add missing imports if the package is present in your module cache already. However, you can also manually add a new import to your file through the [`Go: Add Import`](commands#go-add-import) command. Available packages are offered from module cache (or from your `GOPATH` in GOPATH mode).
<div style="text-align: center;"><img src="images/addimport.gif" alt="Add byte import to Go file" style="width: 75%"> </div>
@ -145,7 +144,7 @@ Rename all occurrences of a symbol in your workspace.
**Note**: For undo after rename to work on Windows, you need to have `diff` tool on your `PATH`.
This feature is not available if you are using Go modules **without** [`gopls`](gopls.md), the Go language server.
This feature is not available if you are using Go modules **without** [`gopls`](gopls), the Go language server.
<div style="text-align: center;"><img src="images/rename.gif" alt="Rename an exported variable in Go workspace" style="width: 75%"> </div>
@ -162,51 +161,51 @@ For known issues with this feature see [golang/go#37170](https://github.com/gola
### Add or remove struct tags
Use the [`Go: Add Tags to Struct Fields`](commands.md#go-add-tags-to-struct-fields) command to automatically generate or remove [tags](https://pkg.go.dev/reflect?tab=doc#StructTag) for your struct. This feature is provided by the [`gomodifytags`](tools.md#gomodifytags) tool.
Use the [`Go: Add Tags to Struct Fields`](commands#go-add-tags-to-struct-fields) command to automatically generate or remove [tags](https://pkg.go.dev/reflect?tab=doc#StructTag) for your struct. This feature is provided by the [`gomodifytags`](tools#gomodifytags) tool.
<div style="text-align: center;"><img src="images/addtagstostructfields.gif" alt="Add tags to struct fields" style="width: 75%"> </div>
### Generate interface implementation
Use the [`Go: Generate Interface Stubs`](commands.md#go-generate-interface-stubs) command to automatically generate method stubs for a given interface. This feature is provided by the [`impl`](tools.md#impl) tool.
Use the [`Go: Generate Interface Stubs`](commands#go-generate-interface-stubs) command to automatically generate method stubs for a given interface. This feature is provided by the [`impl`](tools#impl) tool.
<div style="text-align: center;"><img src="images/generateinterfaceimplementation.gif" alt="Generate functions to implement an interface" style="width: 75%"> </div>
### Generate unit tests
Easily generate unit tests for your project by running one of the [`Go: Generate Unit Tests for ...`](commands.md#go-generate-unit-tests-for-file) commands. This can be done at a function, file, or package level. This feature is provided by the [`gotests`](tools.md#gotests) tool.
Easily generate unit tests for your project by running one of the [`Go: Generate Unit Tests for ...`](commands#go-generate-unit-tests-for-file) commands. This can be done at a function, file, or package level. This feature is provided by the [`gotests`](tools#gotests) tool.
<div style="text-align: center;"><img src="images/generateunittestsforfunction.gif" alt="Generate unit tests for a function" style="width: 75%"> </div>
### Fill struct literals
Use the [`Go: Fill struct`](commands.md#fill-struct) command to automatically fill a struct literal with its default values.
Use the [`Go: Fill struct`](commands#fill-struct) command to automatically fill a struct literal with its default values.
<div style="text-align: center;"><img src="images/fillstructliterals.gif" alt="Fill struct literals" style="width: 75%"> </div>
## Diagnostics
Learn more about [diagnostic errors](tools.md#diagnostics).
Learn more about [diagnostic errors](tools#diagnostics).
### Build errors
Build errors can be shown as you type or on save. Configure this behavior through the [`"go.buildOnSave"`](settings.md#go.buildOnSave) setting.
Build errors can be shown as you type or on save. Configure this behavior through the [`"go.buildOnSave"`](settings#go.buildOnSave) setting.
By default, code is compiled using the `go` command (`go build`), but build errors as you type are provided by the [`gotype-live`](tools.md#diagnostics) tool.
By default, code is compiled using the `go` command (`go build`), but build errors as you type are provided by the [`gotype-live`](tools#diagnostics) tool.
### Vet errors
Vet errors can be shown on save. The vet-on-save behavior can also be configured through the [`"go.vetOnSave"`](settings.md#go.vetOnSave) setting.
Vet errors can be shown on save. The vet-on-save behavior can also be configured through the [`"go.vetOnSave"`](settings#go.vetOnSave) setting.
The vet tool used is the one provided by the `go` command: [`go vet`](https://golang.org/cmd/vet/).
### Lint errors
Much like vet errors, lint errors can also be shown on save. This behavior is configurable through the [`"go.lintOnSave"`](settings.md#go.lintOnSave) setting.
Much like vet errors, lint errors can also be shown on save. This behavior is configurable through the [`"go.lintOnSave"`](settings#go.lintOnSave) setting.
The default lint tool is [`staticcheck`]. However, custom lint tools can be easily used instead by configuring the [`"go.lintTool"`](settings.md#go.lintTool) setting. [`golint`], [`golangci-lint`], and [`revive`] are also supported.
The default lint tool is [`staticcheck`]. However, custom lint tools can be easily used instead by configuring the [`"go.lintTool"`](settings#go.lintTool) setting. [`golint`], [`golangci-lint`], and [`revive`] are also supported.
For a complete overview of linter options, see the [documentation for diagnostic tools](tools.md#diagnostics).
For a complete overview of linter options, see the [documentation for diagnostic tools](tools#diagnostics).
## Run and test in the editor
@ -214,29 +213,29 @@ For a complete overview of linter options, see the [documentation for diagnostic
To run your code without debugging, use the keyboard shortcut `Ctrl+F5` or run the command `Debug: Start without Debugging`. To debug, see [Debugging](#debugging) below.
This command requires you to have a [launch configuration](debugging.md#launch-configuration) in a `launch.json` file. To open or create your `launch.json`, run the `Debug: Open launch.json` command. Use the default `Go: Launch file` configuration.
This command requires you to have a [launch configuration](debugging#launch-configuration) in a `launch.json` file. To open or create your `launch.json`, run the `Debug: Open launch.json` command. Use the default `Go: Launch file` configuration.
Behind the scenes, the `Debug: Start without Debugging` command calls `go run`. `go run` usually requires the path to the file to run, so your `launch.json` should contain `"program": "${file}"`.
### Test and benchmark
[Test UI](https://code.visualstudio.com/api/extension-guides/testing) and [Code lenses](https://code.visualstudio.com/blogs/2017/02/12/code-lens-roundup) allow users to easily run tests and benchmarks for a given function, file, package, or workspace. Alternatively, the same functionality is available through a set of commands: [`Go: Test Function At Cursor`](commands.md#go-test-function-at-cursor), [`Go: Test File`](commands.md#go-test-file), [`Go: Test Package`](commands.md#go-test-package), and [`Go: Test All Packages in Workspace`](commands.md#go-test-all-packages-in-workspace).
[Test UI](https://code.visualstudio.com/api/extension-guides/testing) and [Code lenses](https://code.visualstudio.com/blogs/2017/02/12/code-lens-roundup) allow users to easily run tests and benchmarks for a given function, file, package, or workspace. Alternatively, the same functionality is available through a set of commands: [`Go: Test Function At Cursor`](commands#go-test-function-at-cursor), [`Go: Test File`](commands#go-test-file), [`Go: Test Package`](commands#go-test-package), and [`Go: Test All Packages in Workspace`](commands#go-test-all-packages-in-workspace).
<div style="text-align: center;"><img src="images/testexplorer.gif" alt="Testing UI" style="width: 75%"> </div>
### Code Coverage
Show code coverage in the editor, either after running a test or on-demand. This can be done via the commands: [`Go: Apply Cover Profile`](commands.md#go-apply-cover-profile) and [`Go: Toggle Test Coverage in Current Package`](commands.md#go-toggle-test-coverage-in-current-package).
Show code coverage in the editor, either after running a test or on-demand. This can be done via the commands: [`Go: Apply Cover Profile`](commands#go-apply-cover-profile) and [`Go: Toggle Test Coverage in Current Package`](commands#go-toggle-test-coverage-in-current-package).
## [Debugging](debugging.md)
## [Debugging](debugging)
This extension offers debugging of Go programs. See the [debugging documentation](debugging.md) for more information.
This extension offers debugging of Go programs. See the [debugging documentation](debugging) for more information.
## Other
### Go Playground
Export your current file to the [Go Playground](https://play.golang.org) via the [`Go: Run On Go Playground`](settings.md#go-run-on-go-playground) command. This is useful for quickly creating a piece of sample code.
Export your current file to the [Go Playground](https://play.golang.org) via the [`Go: Run On Go Playground`](settings#go-run-on-go-playground) command. This is useful for quickly creating a piece of sample code.
[`gopls`]: gopls.md
[`staticcheck`]: https://staticcheck.io/

@ -1,4 +1,3 @@
# `GOPATH`
The `GOPATH` environment variable is a fundamental part of writing Go code
**without** [Go modules]. It specifies the location of your workspace, and it
@ -21,7 +20,7 @@ Go code with `GOPATH`](https://golang.org/doc/gopath_code.html#GOPATH).
## Check the value of `GOPATH`
First, it's useful to quickly check that you are using the right `GOPATH`. Two commands report the `GOPATH` value used by the VS Code Go extension: (1) [`Go: Current GOPATH`](commands.md#go-current-gopath), or (2) [`Go: Locate Configured Go Tools`](commands.md#go-locate-configured-go-tools). Use either of these commands to check which `GOPATH` the extension is using.
First, it's useful to quickly check that you are using the right `GOPATH`. Two commands report the `GOPATH` value used by the VS Code Go extension: (1) [`Go: Current GOPATH`](commands#go-current-gopath), or (2) [`Go: Locate Configured Go Tools`](commands#go-locate-configured-go-tools). Use either of these commands to check which `GOPATH` the extension is using.
If the `GOPATH` value is incorrect, see the details below on how to configure it.
@ -39,15 +38,15 @@ Still, there are a number of cases in which you might want a more complicated `G
## Different `GOPATH`s for different projects
Setting [`go.gopath`](settings.md#go.gopath) in your [user settings](https://vscode.readthedocs.io/en/latest/getstarted/settings/) overrides the environment's `GOPATH` value.
Setting [`go.gopath`](settings#go.gopath) in your [user settings](https://vscode.readthedocs.io/en/latest/getstarted/settings/) overrides the environment's `GOPATH` value.
[Workspace settings](https://vscode.readthedocs.io/en/latest/getstarted/settings/) override user settings, so you can use the [`go.gopath`](settings.md#go.gopath) setting to set different `GOPATH`s for different projects. A `GOPATH` can also contain multiple directories, so this setting is not necessary to achieve this behavior.
[Workspace settings](https://vscode.readthedocs.io/en/latest/getstarted/settings/) override user settings, so you can use the [`go.gopath`](settings#go.gopath) setting to set different `GOPATH`s for different projects. A `GOPATH` can also contain multiple directories, so this setting is not necessary to achieve this behavior.
## Automatically inferring your `GOPATH`
**NOTE: This feature only works in `GOPATH` mode, not in module mode.**
The [`go.inferGopath`](settings.md#go.inferGopath) setting overrides the [`go.gopath`](settings.md#go.gopath) setting. If you set [`go.inferGopath`](settings.md#go.inferGopath) to `true`, the extension will try to infer your `GOPATH` based on the workspace opened in VS Code. This is done by searching for a `src` directory in your workspace. The parent of this `src` directory is then added to your [global `GOPATH`](#setting-gopath) (`go env GOPATH`).
The [`go.inferGopath`](settings#go.inferGopath) setting overrides the [`go.gopath`](settings#go.gopath) setting. If you set [`go.inferGopath`](settings#go.inferGopath) to `true`, the extension will try to infer your `GOPATH` based on the workspace opened in VS Code. This is done by searching for a `src` directory in your workspace. The parent of this `src` directory is then added to your [global `GOPATH`](#setting-gopath) (`go env GOPATH`).
For example, say your global `GOPATH` is `$HOME/go`, but you are working in a repository with the following structure.
@ -58,7 +57,7 @@ foo/
└── main.go
```
If you open the `foo` directory as your workspace root in VS Code, [`"go.inferGopath"`](settings.md#go.inferGopath) will set your `GOPATH` to `$HOME/go:/path/to/foo/bar`.
If you open the `foo` directory as your workspace root in VS Code, [`"go.inferGopath"`](settings#go.inferGopath) will set your `GOPATH` to `$HOME/go:/path/to/foo/bar`.
This setting is useful because it allows you to avoid setting the `GOPATH` in the workspace settings of each of your projects.
@ -78,8 +77,8 @@ If you switch frequently between `GOPATH`s, you may find that the extension prom
Before Go 1.11, the `go get` command installed tools and their source code to your `GOPATH`. Because this extension uses a lot of different tools, this causes clutter in your `GOPATH`. If you wish to reduce this clutter, you can have the extension install tools to a different location. This also addresses the issue described above, when switching `GOPATHs` forces you to reinstall Go tools.
This can be done by setting [`"go.toolsGopath"`](settings.md#go.toolsGopath) to an alternate path, only for tool installations. After you configure this setting, be sure to run the [`Go: Install/Update Tools`](commands.md#go-installupdate-tools) command so that the Go tools get installed to the provided location.
This can be done by setting [`"go.toolsGopath"`](settings#go.toolsGopath) to an alternate path, only for tool installations. After you configure this setting, be sure to run the [`Go: Install/Update Tools`](commands#go-installupdate-tools) command so that the Go tools get installed to the provided location.
The extension will fall back to your existing `GOPATH` if tools are not found in the [`go.toolsGopath`](settings.md#go.toolsGopath) directory.
The extension will fall back to your existing `GOPATH` if tools are not found in the [`go.toolsGopath`](settings#go.toolsGopath) directory.
[Go modules]: https://go.dev/blog/using-go-modules

@ -1,4 +1,3 @@
# Go Nightly
This master branch of this extension is built and published nightly through the [Go Nightly]. If you're interested in testing new features and bug fixes, you may be interested in switching to the [Go Nightly] extension. Also, if you file an issue, we may suggest trying out the fix in [Go Nightly].

@ -1,5 +1,7 @@
# Release candidate (DATE)
Use the following template to create an issue for release.
```
# Release candidate (DATE)
- [ ] Announce the release, leave enough time for teams to surface any last minute issues that need to get in before freeze. Make sure debugger and gopls teams are looped in as well.
- [ ] Create a milestone with the issues that are fixed by this release
- [ ] Update `master` for the release
@ -36,3 +38,4 @@
- [ ] Bump the version number to the next monthly ("X.XX.X-dev") release in the `master` branch
- [ ] `package.json`
- [ ] `package-lock.json`
```

@ -1,4 +1,3 @@
# Settings
This extension is highly configurable, and as such, offers a number of settings. These can be configured by modifying your [User or Workspace Settings](https://code.visualstudio.com/docs/getstarted/settings).
@ -19,7 +18,7 @@ To view the list of settings:
## Security
This extension runs a few [third-party command-line tools](tools.md) found from the locations determined by the `PATH` or `Path` environment variable, and the settings such as `"go.alternateTools"` or `"go.toolsGopath"`. Configuring them in workspace settings allows users to conveniently select a different set of tools based on project's need, but also allows attackers to run arbitrary binaries on your machine if they successfuly convince you to open a random repository. In order to reduce the security risk, the extension reads those settings from user settings by default. If the repository can be trusted and workspace settings must be used, you can mark the workspace as a trusted workspace using the `"Go: Toggle Workspace Trust Flag"` command.
This extension runs a few [third-party command-line tools](tools) found from the locations determined by the `PATH` or `Path` environment variable, and the settings such as `"go.alternateTools"` or `"go.toolsGopath"`. Configuring them in workspace settings allows users to conveniently select a different set of tools based on project's need, but also allows attackers to run arbitrary binaries on your machine if they successfuly convince you to open a random repository. In order to reduce the security risk, the extension reads those settings from user settings by default. If the repository can be trusted and workspace settings must be used, you can mark the workspace as a trusted workspace using the `"Go: Toggle Workspace Trust Flag"` command.
## Detailed list

@ -1,4 +1,3 @@
# Smoke Test
Before releasing a new version of the extension, please run the following smoke test to make sure that all features are working.
@ -6,7 +5,7 @@ Before releasing a new version of the extension, please run the following smoke
First, clone [golang.org/x/example](https://github.com/golang/example). At the time of writing (June 2020), this repository has not changed since 2017. If it has changed since, these steps may not be exactly reproducible and should be adjusted.
For now, we smoke test the extension only in [`GOPATH`](gopath.md) mode.
For now, we smoke test the extension only in [`GOPATH`](gopath) mode.
If it does not already exist:
@ -22,7 +21,7 @@ git clone https://github.com/golang/example
cd example
```
Next, [build and sideload the modified Go extension](contributing.md#sideload) and open the `example/hello` directory. Open `hello.go`.
Next, [build and sideload the modified Go extension](contributing#sideload) and open the `example/hello` directory. Open `hello.go`.
## Test code navigation

@ -1,4 +1,3 @@
# Using [VS Code Tasks] with Go
From the [VS Code Tasks] documentation:

@ -1,6 +1,6 @@
# Test explorer implementation (src/goTest)
## Mapping tests
## Implementation (src/goTest)
### Mapping tests
`TestItem`s themselves cannot be used with `Map`s. For non-primitive (object)
keys, Map uses strict equality. Two objects are only strictly equal to each

@ -1,4 +1,3 @@
# Testing
We currently use two separate continuous integration (CI) systems to test all changes and pushed commits:
@ -41,8 +40,8 @@ This is the workflow triggered for every PR and commit made to our mirror reposi
[`.github/workflows/test-smoke.yml`](../.github/workflows/test-smoke.yml)
define the GitHub Actions-based CI workflow.
### [Nightly Release](nightly.md)
### [Nightly Release](nightly)
A new version of the [Go Nightly](nightly.md) extension, based on the current `master` branch, is released at least once a day between Monday and Thursday. Learn more in the [Go Nightly documentation](nightly.md).
A new version of the [Go Nightly](nightly) extension, based on the current `master` branch, is released at least once a day between Monday and Thursday. Learn more in the [Go Nightly documentation](nightly).
The daily release process is automated via a GitHub Action. See [`.github/workflows/release.yml`](../.github/workflows/release.yml) and [`build/all.bash`](../build/all.bash).

@ -1,8 +1,7 @@
# Tools
This document describes the tools that power the VS Code Go extension.
Tools will be installed by default when you install the extension. You can also manually install or update all of these tools by running the [`Go: Install/Update Tools`](commands.md#go-installupdate-tools) command. If any tools are missing, you will see an `Analysis Tools Missing` warning in the bottom-right corner of the editor, which will prompt you to install these tools.
Tools will be installed by default when you install the extension. You can also manually install or update all of these tools by running the [`Go: Install/Update Tools`](commands#go-installupdate-tools) command. If any tools are missing, you will see an `Analysis Tools Missing` warning in the bottom-right corner of the editor, which will prompt you to install these tools.
VS Code Go will install the tools to your `$GOPATH/bin` by default.
@ -20,10 +19,10 @@ The extension checks for the availability of the new Go release by periodically
`gopls` uses the `go` command to analyze your code. The extension automatically propagates necessary settings such as `"go.buildFlags"`, `"go.buildTags"`, `"go.toolsEnvVars"` and the path to the right `go` command to `gopls`. No extra settings should be necessary, but when you need to adjust `gopls`'s behavior further (e.g., enable more advanced analysis features), please see [all the settings for `gopls`](https://github.com/golang/vscode-go/blob/master/docs/settings.md#settings-for-gopls).
If you encounter issues with `gopls`, please read the [troubleshooting guide](troubleshooting.md#collect-gopls-information). If you want to run the extension without the language server, you can disable it by setting `"go.useLanguageServer": false`.
If you encounter issues with `gopls`, please read the [troubleshooting guide](troubleshooting#collect-gopls-information). If you want to run the extension without the language server, you can disable it by setting `"go.useLanguageServer": false`.
`gopls` officially supports the four newer major versions of Go. If you are using a very old version of Go, or you explicitly disable the language server, the extension will automatically fall back to the legacy mode. The legacy mode uses old tools instead of `gopls`. Unfortunately many of them are no longer actively maintained and many features the extension provides will not be available.
You can tell whether the extension is using `gopls`, by checking whether the high voltage icon (⚡) is present in the [Go status bar](./ui.md).
You can tell whether the extension is using `gopls`, by checking whether the high voltage icon (⚡) is present in the [Go status bar](./ui).
`gopls` is under active development, and updating it is important to get new features. The extension periodically checks the [module proxy](https://golang.org/cmd/go/#hdr-Module_proxy_protocol) to detect a new version has been released. When a newer version is available, a pop-up will appear, prompting you to update. If you would like to opt out of this automated update check, set `"go.toolsManagement.checkForUpdates"` to `false`.
For more information about `gopls`, please visit its [documentation](https://golang.org/s/gopls).
@ -33,10 +32,10 @@ For more information about `gopls`, please visit its [documentation](https://gol
### [`dlv`](https://github.com/go-delve/delve)
This extension uses Delve for its debug/test functionalities. The extension currently ships with a thin Debug Adapter that implements the [Debug Adapter protocol](https://microsoft.github.io/debug-adapter-protocol/) and connects VS Code and `dlv`.
For a comprehensive overview of how to debug your Go programs, please see the [debugging guide](./debugging.md).
For a comprehensive overview of how to debug your Go programs, please see the [debugging guide](./debugging).
### [`dlv-dap`](https://github.com/go-delve/delve)
This extension requires an unstable version of [`dlv`](#dlv) when users opt in to use Delve's native DAP implementation. `dlv-dap` is a `dlv` built from the master, which includes unreleased features. Please see the documentation about [Dlv DAP - Delve's Native DAP implementation](./dlv-dap.md) for details.
This extension requires an unstable version of [`dlv`](#dlv) when users opt in to use Delve's native DAP implementation. `dlv-dap` is a `dlv` built from the master, which includes unreleased features. Please see the documentation about [Dlv DAP - Delve's Native DAP implementation](./dlv-dap) for details.
### [`go-outline`](https://pkg.go.dev/github.com/ramya-rao-a/go-outline?tab=overview)
@ -44,30 +43,30 @@ This tool provides the information needed to compute the various test code lense
### [`goplay`](https://pkg.go.dev/github.com/haya14busa/goplay?tab=overview)
This tool provides support for the [`Go: Run on Go Playground`](features.md#go-playground) command.
This tool provides support for the [`Go: Run on Go Playground`](features#go-playground) command.
### [`gomodifytags`](https://pkg.go.dev/github.com/fatih/gomodifytags?tab=overview)
This tool provides support for the [`Go: Add Tags to Struct Fields`](features.md#add-or-remove-struct-tags) and [`Go: Remove Tags From Struct Fields`](features.md#add-or-remove-struct-tags) commands.
This tool provides support for the [`Go: Add Tags to Struct Fields`](features#add-or-remove-struct-tags) and [`Go: Remove Tags From Struct Fields`](features#add-or-remove-struct-tags) commands.
### [`impl`](https://github.com/josharian/impl)
This tool provides support for the [`Go: Generate Interface Stubs`](features.md#generate-interface-implementation) command.
This tool provides support for the [`Go: Generate Interface Stubs`](features#generate-interface-implementation) command.
### [`gotests`](https://github.com/cweill/gotests/)
This tool provides support for the [`Go: Generate Unit Tests`](features.md#generate-unit-tests) set of commands.
This tool provides support for the [`Go: Generate Unit Tests`](features#generate-unit-tests) set of commands.
### [`staticcheck`]
This is the default lint tool. See the [full list of checks](https://staticcheck.io/docs/checks) that `staticcheck` provides. Other lint tools can be used by configuring the [`"go.lintTool"`](settings.md#go.lintTool) setting.
This is the default lint tool. See the [full list of checks](https://staticcheck.io/docs/checks) that `staticcheck` provides. Other lint tools can be used by configuring the [`"go.lintTool"`](settings#go.lintTool) setting.
Other options include:
* [`golangci-lint`]: This meta-linter combines a number of existing lint tools, including [staticcheck](#staticcheck), into one interface.
* [`revive`]: This tool is an enhancement on top of [`golint`], and it provides additional checks.
* [`golint`]: This used to be the default linter used by this extension before it was officially deprecated.
You can use the [`"go.lintFlags"`](settings.md#go.lintFlags) setting to further configure your linter of choice. Most linters can be configured via special configuration files, but you may still need to pass these command-line flags. The configuration documentation for each supported linter is listed here:
You can use the [`"go.lintFlags"`](settings#go.lintFlags) setting to further configure your linter of choice. Most linters can be configured via special configuration files, but you may still need to pass these command-line flags. The configuration documentation for each supported linter is listed here:
* [`staticcheck`](https://staticcheck.io/docs/#configuration)
* [`golangci-lint`](https://golangci-lint.run/usage/configuration/)
@ -95,32 +94,32 @@ Configure `revive` to exclude `vendor` directories and apply extra configuration
When `gopls` cannot be used, the extension falls back to the legacy mode. Be aware that many of these tools may be incompatible with the recent versions of Go or do not work in Modules mode.
* [`go-outline`](https://pkg.go.dev/github.com/ramya-rao-a/go-outline?tab=overview):
In the legacy mode, this tool provides the `[document outline](features.md#document-outline) feature` and the [go to symbol](features.md#go-to-symbol) in the current file feature.
In the legacy mode, this tool provides the `[document outline](features#document-outline) feature` and the [go to symbol](features#go-to-symbol) in the current file feature.
* `gocode`: code completion in the legacy mode is provided by `gocode`. Different versions of `gocode` are used depending on your version of Go.
* Go 1.9 and above: [mdempsky/gocode](https://github.com/mdempsky/gocode)
* Go 1.11 and above, with modules enabled: [stamblerre/gocode](https://github.com/stamblerre/gocode), named `gocode-gomod` internally.
* [`go-symbols`](https://pkg.go.dev/github.com/acroca/go-symbols?tab=overview): provides the [go to symbol](features.md#go-to-symbol) in workspace feature.
* [`go-symbols`](https://pkg.go.dev/github.com/acroca/go-symbols?tab=overview): provides the [go to symbol](features#go-to-symbol) in workspace feature.
* [`guru`](https://pkg.go.dev/golang.org/x/tools/cmd/guru?tab=doc): provides the [find references](features.md#find-references) and [find interface implementations](features.md#find-interface-implementations) features.
It can also be used to provide the [go to definition](features.md#go-to-definition) via the [`"go.docsTool"`](settings.md#go.docsTool) setting. `guru` does not support Go modules.
* [`guru`](https://pkg.go.dev/golang.org/x/tools/cmd/guru?tab=doc): provides the [find references](features#find-references) and [find interface implementations](features#find-interface-implementations) features.
It can also be used to provide the [go to definition](features#go-to-definition) via the [`"go.docsTool"`](settings#go.docsTool) setting. `guru` does not support Go modules.
* [`gorename`](https://pkg.go.dev/golang.org/x/tools/cmd/gorename?tab=doc): provides the [rename symbol](features.md#rename-symbol) feature. `gorename` does not have support for Go modules
* [`gorename`](https://pkg.go.dev/golang.org/x/tools/cmd/gorename?tab=doc): provides the [rename symbol](features#rename-symbol) feature. `gorename` does not have support for Go modules
* [`godoctor`](https://github.com/godoctor/godoctor): provides the [refactoring](features.md#refactor) features. It does not support Go modules, and we expect that [`gopls`] will provide this feature instead ([golang/go#37170](https://github.com/golang/go/issues/37170)).
* [`godoctor`](https://github.com/godoctor/godoctor): provides the [refactoring](features#refactor) features. It does not support Go modules, and we expect that [`gopls`] will provide this feature instead ([golang/go#37170](https://github.com/golang/go/issues/37170)).
* [`fillstruct`](https://github.com/davidrjenni/reftools/tree/master/cmd/fillstruct): provides support the [`Go: Fill struct`](features.md#fill-struct-literals) command.
* [`fillstruct`](https://github.com/davidrjenni/reftools/tree/master/cmd/fillstruct): provides support the [`Go: Fill struct`](features#fill-struct-literals) command.
* [`gogetdoc`], [`godef`], [`godoc`]: these are documentation tools used for the [go to definition](features.md#go-to-definition), [signature help](features.md#signature-help), and [quick info on hover](features.md#quick-info-on-hover) in the legacy mode. [`guru`](#guru) can also be used, but only for the [go to definition](features.md#go-to-definition) behavior. Configure this via the [`"go.docsTool"`](settings.md#go.docsTool) setting.
* [`gogetdoc`], [`godef`], [`godoc`]: these are documentation tools used for the [go to definition](features#go-to-definition), [signature help](features#signature-help), and [quick info on hover](features#quick-info-on-hover) in the legacy mode. [`guru`](#guru) can also be used, but only for the [go to definition](features#go-to-definition) behavior. Configure this via the [`"go.docsTool"`](settings#go.docsTool) setting.
* [`goimports`], [`gofmt`]: Formatting tools are used by the [formatting and import organization](features.md#format-and-organize-imports) features. [`goreturns`] is used by default in the legacy mode. It formats the file according to the industry standard [`gofmt`] style, organizes imports, and fills in default return values for functions. Other tools can be used for formatting instead; this can be configured with the [`"go.go.formatTool"`](settings.md#formatTool) setting.
* [`goimports`], [`gofmt`]: Formatting tools are used by the [formatting and import organization](features#format-and-organize-imports) features. [`goreturns`] is used by default in the legacy mode. It formats the file according to the industry standard [`gofmt`] style, organizes imports, and fills in default return values for functions. Other tools can be used for formatting instead; this can be configured with the [`"go.go.formatTool"`](settings#formatTool) setting.
* [`gofmt`] only formats the file, without import organization or filling in return values
* [`goformat`] is a configurable version of [`gofmt`]
* [`goreturns`] fills in default return values for functions, in addition to applying `goimports`-style formatting. This tool does not have support for Go modules.
* Diagnostics tools: By default, [`gotype-live`], [`go vet`], and [`golint`] are used to provide [build](features.md#build-errors), [vet](features.md#vet-errors), and [lint](features.md#lint-errors) errors. [`gotype-live`] provides build errors as you type, while `go build` can be used to show build errors only on save. [`gotype-live`] does not work with modules.
* Diagnostics tools: By default, [`gotype-live`], [`go vet`], and [`golint`] are used to provide [build](features#build-errors), [vet](features#vet-errors), and [lint](features#lint-errors) errors. [`gotype-live`] provides build errors as you type, while `go build` can be used to show build errors only on save. [`gotype-live`] does not work with modules.

@ -1,8 +1,7 @@
# Troubleshooting
If you suspect that the Go extension is not working correctly, please follow the troubleshooting steps below.
**NOTE: [Debugging](debugging.md#troubleshooting) has its own troubleshooting documentation.**
**NOTE: [Debugging](debugging#troubleshooting) has its own troubleshooting documentation.**
## Make sure your project compiles
@ -16,17 +15,17 @@ Check that there aren't any diagnostics that indicate a problem with your worksp
Check the bottom of the VS Code window for any warnings and notifications. For example, address warnings such as "⚠️ Analysis Tools Missing".
Run the [`Go: Locate Configured Go Tools`](commands.md#go-locate-configured-go-tools) command. The output is split into sections.
Run the [`Go: Locate Configured Go Tools`](commands#go-locate-configured-go-tools) command. The output is split into sections.
In the first indented section, check that at least `go-outline`, `dlv`, and `gopls` are installed -- they're necessary for the extension's basic functionality. The other tools [provide optional features](tools.md) and are less important unless you need those features. You can install tools by running the [`Go: Install/Update Tools`](commands.md#go-installupdate-tools) command.
In the first indented section, check that at least `go-outline`, `dlv`, and `gopls` are installed -- they're necessary for the extension's basic functionality. The other tools [provide optional features](tools) and are less important unless you need those features. You can install tools by running the [`Go: Install/Update Tools`](commands#go-installupdate-tools) command.
Then, look at the `Workspace Folder` section(s) for the environment in use. Verify that `GOROOT` is set to a valid Go installation; if not, follow the [getting started guide](../README.md#install-go). If `GOPATH` is unset, or surprising, read more about [setting up your `GOPATH`](gopath.md#setting-gopath). Also, `GOMOD` should usually point to your project's `go.mod` file if you're in module mode. (More complicated workspace setups may have a blank `GOMOD`. See the `gopls` [workspace documentation](https://github.com/golang/tools/blob/master/gopls/doc/workspace.md) for more on valid workspace setups.) To change the workspace environment, use settings such as [`go.gopath`](settings.md#go.gopath) and [`go.toolsEnvVars`](settings.md#go.toolsEnvVars).
Then, look at the `Workspace Folder` section(s) for the environment in use. Verify that `GOROOT` is set to a valid Go installation; if not, follow the [getting started guide](../README#install-go). If `GOPATH` is unset, or surprising, read more about [setting up your `GOPATH`](gopath#setting-gopath). Also, `GOMOD` should usually point to your project's `go.mod` file if you're in module mode. (More complicated workspace setups may have a blank `GOMOD`. See the `gopls` [workspace documentation](https://github.com/golang/tools/blob/master/gopls/doc/workspace.md) for more on valid workspace setups.) To change the workspace environment, use settings such as [`go.gopath`](settings#go.gopath) and [`go.toolsEnvVars`](settings#go.toolsEnvVars).
Finally, take a look at your settings in the JSON form (`Preferences: Open Settings (JSON)`). This is an easier way to quickly see what non-default configurations you have. Consider [reading about](settings.md) any settings you don't understand, or just commenting them out.
Finally, take a look at your settings in the JSON form (`Preferences: Open Settings (JSON)`). This is an easier way to quickly see what non-default configurations you have. Consider [reading about](settings) any settings you don't understand, or just commenting them out.
## Update tools
It's possible that you are using an outdated version of a tool, so the bug you are encountering may have already been fixed. You can update all tools at once by running the [`Go: Install/Update Tools`](commands.md#go-installupdate-tools) command.
It's possible that you are using an outdated version of a tool, so the bug you are encountering may have already been fixed. You can update all tools at once by running the [`Go: Install/Update Tools`](commands#go-installupdate-tools) command.
## Restart `gopls`

1
ui.md

@ -1,4 +1,3 @@
# Extension UI
## Using The Go Status Bar