Frequently Asked Questions

NOTE: Debugging has its own FAQ documentation.

Syntax highlighting doesn't seem to work.

The default syntax highlighting for Go files is provided by a TextMate rule embedded in VS Code, not by this extension.

For better syntax highlighting (including generics support), we recommend enabling semantic highlighting by turning on Gopls' ui.semanticTokens setting.

"gopls": { "ui.semanticTokens": true }

Code formatting by this extension doesn't seem to work.

When you have multiple formatter extensions, be sure to set this extension as the default formatter for go language.

"[go]": {
  "editor.defaultFormatter": "golang.go"
}

How can I stop the extension from formatting files on save?

Formatting and organizing imports for Go are enabled by default. This is implemented by setting the language-specific editor settings, that take precedence over user/workspace editor settings.

You can choose to disable them by configuring the following settings.

"[go]": {
        "editor.formatOnSave": false,
        "editor.codeActionsOnSave": {
            "source.organizeImports": false
        }
}

This decision was made a while ago to help users follow the best practice, and to detect broken code early (e.g. unused imports causes compile errors in Go). Unfortunately, these language-specific editor settings overriden by the extension is not easily visible from the settings UI, and confuses users new to Go. In the following issues, we are discussing and collecting ideas to improve the situation without interrupting existing users.