To view a complete list of the commands and settings for this extension:
Feature Contributions
tab.You can configure your settings by modifying your User or Workspace Settings. To navigate to your settings, open the Command Palette (Ctrl+Shift+P) and search for “settings”. The simplest way to modify your settings is through “Preferences: Open Settings (UI)”.
NOTE: Most of these settings don't apply if you are using gopls
. Learn more about gopls
-specific settings in this documentation.
A list of popular and notable settings can be found below.
One of "godoc"
, "gogetdoc"
, or "guru"
(gogetdoc
is the default). This is the tool used by the go to definition, signature help, and quick info on hover features. See more information about each of these tools in the Documentation section.
One of "gofmt"
, "goimports"
, "goreturns"
, and "goformat"
(goreturns
is the default). This is the tool used by the formatting and import organization features. See more information about each of these tools in the Formatting section.
One of "golint"
, "staticcheck"
, "golangci-lint"
, and "revive"
(golint
is the default). This is the tool used by the lint-on-save feature. See more information about each of these tools in the Diagnostics section.
This setting can be used to pass additional flags to your lint tool of choice.
Most linters can be configured via special configuration files, but you may still need to pass command-line flags. The configuration documentation for each supported linter is listed here:
Enable all golangci-lint
linters and only show errors in new code:
"go.lintFlags": ["--enable-all", "--new"]
Configure revive
to exclude vendor
directories and apply extra configuration with a config.toml
file:
"go.lintFlags": [ "-exclude=vendor/...", "-config=${workspaceFolder}/config.toml" ]
In addition to integrated editing features, the extension also provides several commands in the Command Palette for working with Go files:
Go: Add Import
to add an import from the list of packages in your Go contextGo: Current GOPATH
to see your currently configured GOPATHGo: Test at cursor
to run a test at the current cursor position in the active documentGo: Test Package
to run all tests in the package containing the active documentGo: Test File
to run all tests in the current active documentGo: Test Previous
to run the previously run test commandGo: Test All Packages in Workspace
to run all tests in the current workspaceGo: Generate Unit Tests For Package
Generates unit tests for the current packageGo: Generate Unit Tests For File
Generates unit tests for the current fileGo: Generate Unit Tests For Function
Generates unit tests for the selected function in the current fileGo: Install Tools
Installs/updates all the Go tools that the extension depends onGo: Add Tags
Adds configured tags to selected struct fields.Go: Remove Tags
Removes configured tags from selected struct fields.Go: Generate Interface Stubs
Generates method stubs for given interfaceGo: Fill Struct
Fills struct literal with default valuesGo: Run on Go Playground
Upload the current selection or file to the Go PlaygroundYou can access all of the above commands from the command palette (Cmd+Shift+P
or Ctrl+Shift+P
).
A few of these are available in the editor context menu as an experimental feature as well. To control which of these commands show up in the editor context menu, update the setting go.editorContextMenuCommands
.