Commands

In addition to integrated editing features, this extension offers a number of commands, which can be executed manually through the Command Palette (Ctrl+Shift+P).

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" setting.

All commands provided by this extension have the prefix Go:.

Latest changes

The commands described below are up-to-date as of June 2020. We do our best to keep documentation current, but if a command is missing, you can always consult the full list in the Extensions view.

To view this list:

  1. Navigate to the Extensions view (Ctrl+Shift+X).
  2. Find the Go extension and click on it to open the Extension Editor.
  3. Click on the Feature Contributions tab.
  4. Scroll through the list under Commands.

Finally, you can also see a full list by using a meta command: Go: Show All Commands....

Detailed list

Below is a detailed list of commands. They are categorized into code editing and generation, testing and benchmarking, build, lint, and vet, miscellaneous, and troubleshooting. You will find the troubleshooting commands helpful when diagnosing an issue with the extension (learn more in the Troubleshooting documentation).

Code editing and generation

Go: Add Import

Manually add an import to your file. See Add import.

[Go: Add Package to Workspace]

Add a package to the current workspace.

Go: Add Tags to Struct Fields

Automatically generate tags for your struct. See Add or remove struct tags.

Go: Remove Tags From Struct Fields

Removes tags from the selected struct fields. See Add or remove struct tags.

Go: Fill struct

Fill a struct literal with default values. See Fill struct.

Go: Generate Interface Stubs

Generate method stubs for given interface. See Generate interface implementation.

Go: Generate Unit Tests For Function

Generate unit tests for the selected function in the current file. See Generate unit tests.

Go: Generate Unit Tests For File

Generate unit tests for the current file. See Generate unit tests.

Go: Generate Unit Tests For Package

Generate unit tests for the current package. See Generate unit tests.

Go: Extract to function

Extract the highlighted code to a function. Provided by the godoctor tool. Learn more about refactoring.

Go: Extract to variable

Extract the highlighted code to a local variable. Provided by the godoctor tool. Learn more about refactoring.

Testing and benchmarking

Go: Test Function at Cursor

Run the test function at the current cursor position in the file.

Go: Subtest at Cursor

Run the subtest (t.Run) at the current cursor position in the file.

Go: Benchmark Function At Cursor

Run the benchmark at the current cursor position in the file.

Go: Debug Test At Cursor

Debug the test at the current cursor position.

Go: Test File

Run all of the tests in the current file.

Go: Benchmark File

Run all of the benchmarks in the current file.

Go: Test Package

Run all of the tests in the current package.

Go: Benchmark Package

Run all of the benchmarks in the current package.

Go: Test Previous

Re-run the most recently executed test command.

Go: Test All Packages In Workspace

Run all of the tests in the current workspace.

Go: Cancel Running Tests

Cancel currently running tests.

Go: Toggle Test File

Toggle between a file and its corresponding test file.

Go: Apply Cover Profile

Apply a given cover profile to the current file.

Go: Toggle Test Coverage In Current Package

Show code coverage in the current file.

Build, lint, and vet

Go: Build Current Package

Build the current package and show build errors.

Go: Vet Current Package

Show vet errors for the current package.

Go: Lint Current Package

Show lint errors for the current package.

Go: Build Workspace

Build all of the packages in the current workspace and show build errors.

Go: Vet Workspace

Show vet errors for all of the packages in the current workspace.

Go: Lint Workspace

Show lint errors for all of the packages in the current workspace.

Go: Install Current Package

Install the current package and its dependencies.

Miscellaneous

Go: Restart Language Server

Use this command to restart the language server without reloading the VS Code window. This can be helpful if something seems goes wrong with the language server (for example, if you see incorrect error messages).

Go: Run on Go Playground

Upload the current selection or file to the Go Playground (play.golang.org). See Go Playground.

Troubleshooting

Go: Current GOPATH

See the current value of GOPATH. This is not equivalent to go env GOPATH, as your VS Code settings may have altered the value of GOPATH used by the extension. This command is helpful when troubleshooting the extension.

Go: Install/Update Tools

Install or update the Go tools on which the extension depends. Tools can be installed or updated all at once, or individual tools can be selected.

Go: Locate Configured Go Tools

This command is helpful when troubleshooting the extension. It prints out the environment variables and paths to the tools used by the extension. See an example of the command's output in the troubleshooting documentation.