Skip to content

Latest commit

 

History

History
228 lines (133 loc) · 11.2 KB

features.md

File metadata and controls

228 lines (133 loc) · 11.2 KB

Features

This document describes the features supported by this extension.

Table of Contents

Code completion

Completion results appear for symbols as you type. You can trigger this manually with the Ctrl+Space shortcut.

Autocompletion is also supported for packages you have not yet imported into your program.

Code completion and signature help

Signature help

Information about the signature of a function pops up as you type in its parameters.

Quick info on hover

Documentation appears when you hover over a symbol.

Go to definition

Jump to or peek a symbol's declaration.

Go to definition using the context menu

Find references

Find or go to the references of a symbol.

This feature is not available if you are using Go modules without gopls, the Go language server.

Find references using the context menu

Find interface implementations

Find the concrete types that implement a given interface.

This feature is not available if you are using Go modules without gopls, the Go language server.

Go to implementations for Server that implements http.Handler and then finds all implementations of http.Handler in the workspace

Search for symbols in your file or workspace by opening the Command Palette (Ctrl+Shift+P) and typing @ for symbols in the current file or # for symbols in the entire workspace.

Use Workspace Symbols to locate Hello in the workspace

Call hierarchy

Show all calls from or to a function.

Show call hierarchy and investigate callers of a function

Document outline

See all the symbols in the current file in the VS Code's Outline view.

Outline of a Go file

Toggle between code and tests

Quickly toggle between a file and its corresponding test file by using the Go: Toggle Test File command.

Toggle between reverse.go and reverse_test.go

Code Editing

Predefined snippets for quick coding. These snippets will appear as completion suggestions when you type. Users can also define their own custom snippets (see Snippets in Visual Studio Code).

Use the struct type snippet

Format and organize imports

Format code and organize imports, either manually or on save.

Add import

Manually add a new import to your file through the Go: Add Import command. Available packages are offered from your GOPATH and module cache.

Add byte import to Go file

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, the Go language server.

Rename an exported variable in Go workspace

Refactor

Select the area for refactoring (e.g. variable, function body, etc). Click on the Code Action light bulb icon that appears in the selected area, or select "Refactoring..." or "Rename Symbol" from the VS Code Context menu. For known issues with this feature see golang/go#37170.

Extract to variable followed by a rename

Code Generation

Add or remove struct tags

Use the Go: Add Tags to Struct Fields command to automatically generate or remove tags for your struct. This feature is provided by the gomodifytags tool.

Add tags to struct fields

Generate interface implementation

Use the Go: Generate Interface Stubs command to automatically generate method stubs for a given interface. This feature is provided by the impl tool.

Generate functions to implement an interface

Generate unit tests

Easily generate unit tests for your project by running one of the Go: Generate Unit Tests for ... commands. This can be done at a function, file, or package level. This feature is provided by the gotests tool.

Generate unit tests for a function

Fill struct literals

Use the Go: Fill struct command to automatically fill a struct literal with its default values.

Fill struct literals

Diagnostics

Learn more about diagnostic errors.

Build errors

Build errors can be shown as you type or on save. Configure this behavior through the "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 tool.

Vet errors

Vet errors can be shown on save. The vet-on-save behavior can also be configured through the "go.vetOnSave" setting.

The vet tool used is the one provided by the go command: go vet.

Lint errors

Much like vet errors, lint errors can also be shown on save. This behavior is configurable through the "go.lintOnSave" setting.

The default lint tool is staticcheck. However, custom lint tools can be easily used instead by configuring the "go.lintTool" setting. golint, golangci-lint, and revive are also supported.

For a complete overview of linter options, see the documentation for diagnostic tools.

Run and test in the editor

Run your code

To run your code without debugging, use the keyboard shortcut Ctrl+F5 or run the command Debug: Start without Debugging. To debug, see Debugging below.

This command requires you to have a 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 and Code lenses 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, Go: Test File, Go: Test Package, and Go: Test All Packages in Workspace.

Testing UI

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 and Go: Toggle Test Coverage in Current Package.

This extension offers debugging of Go programs. See the debugging documentation for more information.

Other

Go Playground

Export your current file to the Go Playground via the Go: Run On Go Playground command. This is useful for quickly creating a piece of sample code.