Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
GitHub Action edited this pageMar 21, 2025 ·5 revisions

This document describes more advanced ways of working with the VS Code Goextension.

Formatting Code and Organizing Imports

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

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

Formatting and organizing imports are enabled by default. Youcan choose to disable them by configuring the following settings.

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

Choosing a different version of Go

The extension chooses thego command using thePATH (orPath) environmentvariable by default. You can configure the extension to choose a differentversion ofgo with one of the following options.

  • (Preferred) Adjust yourPATH orPath environment variable, andopen VSCode with the adjusted environment variable, or
  • Use the Go extension's"Go: Choose Go Environment" command that opens amenu to change thego version, or
  • Use the"go.alternateTools" settings and specify the absolute path to thego command."go.alternateTools": { "go": "/path/to/go/command" }

note: For historical reasons, some users configure the"go.goroot"

settings or theGOROOT environment variable to select the Go SDK location.With recent versions of Go, that's unnecessary in most cases.

Configuring the installation of command-line tools

TheGo: Install/Update Tools command uses thego get command to download andinstall requested tools. By default,go get will install the compiled tools inone of the following directories.

  • the directory theGOBIN environment variable specifies, or
  • thebin directory under the firstGOPATH (or"go.gopath") directory, or
  • the$HOME/go/bin (or$USERPROFILE/go/bin) directory.

Some users prefer to choose a different installation location. In that case, usethe"go.toolsGopath" setting.

The extension finds the required tools by their names (go,gopls,dlv,etc.). The"go.alternateTools" setting provides a way to configure theextension to use different tool location, for example a wrapper with a differentname.

The extension uses pinned versions of command-line tools. See the pinned versionsin tools informationhere.To use an alternate version of a tool install it manually with with go install.

Using a custom linter

A commonly customized feature is the linter, which is the tool used to providecoding style feedback and suggestions. This extension supports linters such asstaticcheck,golangci-lint, andrevive. You can choose one of them usingthe"go.lintTool" setting. For customization of the linter, please consult thelinter's documentation.

Note that if you are usingstaticcheck, you can enable it to run withingopls by setting"gopls": { "ui.diagnostic.staticcheck": true }.

Working on the Go standard library and the Go tools

This extension can be used for developing the standard library with additionalconfiguration.

First, youmust open thesrc/ folder in VS Code, not the Go tree root.

Then, you need to configure the workspace, by placing the following insrc/.vscode/settings.json.Command Palette ->Preferences: Open Workspace Settings (JSON) will open the settings file.

{// Use the local go tool. This needs to be built with make.bash."go.alternateTools":{"go":"~/godev/bin/go"},//// Below is optional.//// Build a separate set of tools. For golang/vscode-go#294."go.toolsGopath":"~/.vscode/godev",// Don't reformat HTML files since we have a custom style."html.format.enable":false}

The above assumes the Go tree is checked out at~/godev. If your Go tree issomewhere else, modifygo.alternateTools.go to point to the gobinaryaccordingly. Many underlying tools includinggopls invoke the go command(go list, etc), so we assume the binary isn't completely broken.

You can add.vscode to.git/info/exclude to avoid risking checkingsettings.json into git.

If you see an "inconsistent vendoring" error, please report it atgolang/go#40250.


✏️ Want to contribute to this wiki?

Updatethe source and send a PR.

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp