Tools

This document describes the tools used to create the VS Code Go extension. Each feature is provided by a command-line tool written in Go, so if you experience an issue, it may be due to the underlying tool. Some tools are required for the functionality of the extension, while others are provide optional features.

Some of the features can be provided by multiple tools, and this can be configured through the extension's settings. For more details, see the Documentation, Formatting, and Diagnostics sections below.

NOTE: If you are using the language server, gopls, then most of the below tools are not needed. We strongly recommend using gopls if you are using Go modules, as it performs better.

Installation

These tools will be installed by default when you install the extension. You can manually install or update all of these tools by running the Go: Install/Update 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 by default, but the tools will also be found if they are on your PATH. If you wish to use a separate GOPATH for tools only, you can configure this via the "go.toolsGopath" setting.

Table of Contents

Go toolchain

This extension requires you to install the Go toolchain, meaning that you have the go command on your PATH. To do this, follow the Go installation guide.

The build-on-save and vet-on-save features are provided by the go build and go vet commands.

gocode

Code completion is provided by gocode. It is the only tool that runs as a server. This enables it to provide completions faster, since a new process isn't starting per-keystroke. As a result, it is also easier to troubleshoot.

To restart gocode, run gocode close on the command-line.

To see gocode's internals for debugging purposes, run:

gocode close
gocode -s -debug

Then, type and trigger completions in your VS Code window as usual. You should see information printed in your terminal window.

Different versions of gocode are used depending on your version of Go.

  • Go 1.8 and below: nsf/gocode
  • Go 1.9 and above: mdempsky/gocode
  • Go 1.11 and above, with modules enabled: stamblerre/gocode
    • This version of gocode does not have any caching, so if you find it slow, consider using [gopls] instead.

gopkgs

This tool provides autocompletion for unimported packages.

go-outline

This tool provides the document outline feature, as well as the go to symbol in the current file feature.

go-symbols

This tool provides the go to symbol in workspace feature.

guru

This tool provides the find references and find interface implementations features.

It can also be used to provide the go to definition via the "go.docsTool" setting (see Customization).

guru does not have support for Go modules, so we recommend using gopls for those features instead.

gorename

This tool provides the rename symbol feature.

gorename does not have support for Go modules, so we recommend using gopls for this feature instead.

delve

This is the debugger for the Go language. It is used to provide the debugging features of this extension.

goplay

This tool provides support for the Go: Run on Go Playground command.

gomodifytags

This tool provides support for the Go: Add Tags to Struct Fields command.

impl

This tool provides support for the Go: Generate Interface Stubs command.

gotests

This tool provides support for the Go: Generate Unit Tests set of commands.

fillstruct

This tool provides support the Go: Fill struct command.

Documentation

Documentation tools are used for the go to definition, signature help, and quick info on hover. gogetdoc is used by default.

If gogetdoc does not work for you, a combination of the godef and godoc tools can be used. guru can also be used, but only for the go to definition behavior.

Configure this via the "go.docsTool" setting.

Formatting

Formatting tools are used by the formatting and import organization features.

goreturns is used by default. 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.formatTool" setting.

NOTE: goreturns does not have support for Go modules, so we recommend using goimports or gopls instead.

Other format tool options include:

  • goimports, which applies the default gofmt style and organizes imports, but without the behavior of filling in default return values
  • gofmt only formats the file, without import organization or filling in return values
  • goformat is a configurable version of gofmt

Diagnostics

Diagnostic tools are used to surface errors and warnings in your code when you save your file or as you type.

By default, gotype-live, go vet, and golint are used to provide build, vet, and lint errors. gotype-live provides build errors as you type, while go build can be used to show build errors only on save.

NOTE: gotype-live does not work with modules, so if you are using modules, we recommend using gopls instead.

Other lint tools can be used instead of golint by configuring the "go.lintTool" setting. Other options include: