commit | ab4483e2aecc03e914338c26f6024a86c43bea23 | [log] [tgz] |
---|---|---|
author | Rebecca Stambler <rstambler@golang.org> | Wed May 27 21:56:17 2020 +0000 |
committer | Rebecca Stambler <rstambler@golang.org> | Wed May 27 22:57:18 2020 +0000 |
tree | b0b6a3e8502bf751cbd18cb56e35f3e10d0c33b3 | |
parent | bc0a099243d0dbb2a3d4e4ff830e627084331ab4 [diff] |
src: refactor tools env variables to handle installation and execution I modified this change to focus only on addressing the differences between environment variables when installing tools vs. when running them. https://golang.org/cl/233325 now handles the issue reports on restart. Change-Id: I9d03e2c8f9244bade19606e9d9c6892da9fa0c66 GitHub-Last-Rev: e6f4db38c2ae407481b8bc05f689c743a7517efb GitHub-Pull-Request: golang/vscode-go#28 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/232863 Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This extension adds rich language support for the Go language to VS Code.
See the Changelog to know what has changed over the last few versions of this extension.
This is the future home for the VS Code Go extension and migration is in progress. Read the announcement in the old repo section to learn about the transition and subscribe to Microsoft/vscode-go#3247 for updates.
gocode
)gogetdoc
or godef
+go doc
)gogetdoc
or godef
+go doc
)gogetdoc
or godef
+go doc
)guru
)go-outline
)go-symbols
)goreturns
or goimports
which also remove unused imports or gofmt
). To disable the format on save feature, add "[go]": {"editor.formatOnSave": false}
to your settings.gorename
. Note: For Undo after rename to work in Windows you need to have diff
tool in your path)gopkgs
)gomodifytags
)impl
)fillstruct
)go build
and go test
)go vet
and show errors as warningsgolint
, staticcheck
, golangci-lint
or revive
)gotype-live
)gotests
)delve
)goplay
)This extension requires the go
tools. See Go's installation guide for the download/installation instruction.
Install and open Visual Studio Code. Press Ctrl+Shift+X
or Cmd+Shift+X
to open the Extensions pane. Find and install the Go extension. You can also install the extension from the Marketplace. Open any .go
file in VS Code. The extension is now activated.
This extension uses a set of Go tools to provide the various rich features. These tools are installed in your GOPATH by default. If you wish to have these tools in a separate location, provide the desired location in the setting go.toolsGopath
. Read more about this and the tools at Go tools that the Go extension depends on.
You will see Analysis Tools Missing
in the bottom right, clicking this will offer to install all of the dependent Go tools. You can also run the command Go: Install/Update tools
to install/update the same. You need to have git installed for these tool installations to work.
Note 1: Read GOPATH in the VS Code Go extension to learn about the different ways you can get the extension to set GOPATH.
Note 2: The Format on save
feature has a timeout of 750ms after which the formatting is aborted. You can change this timeout using the setting editor.formatOnSaveTimeout
. This feature gets disabled when you have enabled the Auto Save
feature in Visual Studio Code.
Note 3: Unless go.useLanguageServer
is set to true
, this extension uses gocode
to provide completion lists as you type. If you have disabled the go.buildOnSave
setting, then you may not get fresh results from not-yet-built dependencies. Therefore, ensure you have built your dependencies manually in such cases.
The Go extension is ready to use on the get go. If you want to customize the features, you can edit the settings in your User or Workspace settings. Read All Settings & Commands in Visual Studio Code Go extension for the full list of options and their descriptions.
The Go extension uses a host of Go tools to provide the various language features. An alternative is to use a single language server that provides the same features using the Language Server Protocol.
gopls
from Google is the official language server for the Go language and is currently in active development. You can choose to use this by setting go.useLanguageServer
to true
in your settings.
If you are working on a project that uses Go modules, you will be prompted to use the language server as it provides much better support for Go modules.
Note: The language server from Google supports Go version > 1.10 only
Ideally, you would see prompts to use/install/update the language server. Follow the prompts and the language server should get set up correctly. If you want to manually install/update the language server,
go.useLanguageServer
to true
in your settingsGo: Install/Update Tools
command, select gopls
from the list and press Ok.Below are the settings you can use to control the use of the language server. You need to reload the VS Code window for any changes in these settings to take effect.
go.useLanguageServer
to true
to enable the use of language server.gopls
, see the recommended settings.go.languageServerExperimentalFeatures
. Below are the features you can thus control. By default, all are set to true
i.e are enabled."go.languageServerExperimentalFeatures": { "format": true, "diagnostics": true, "documentLink": true }
"go.languageServerFlags": ["-logfile", "path to a text file that exists"]
to collect logs in a log file."go.languageServerFlags": ["-rpc.trace"]
to see the complete rpc trace in the output panel (View
-> Output
-> gopls
)If you find any problems using the gopls
language server, please first check the list of existing issues for gopls and update the relevant ones with your case before logging a new one at https://github.com/golang/go/issues
A linter is a tool giving coding style feedback and suggestions. By default this extension uses the official golint as a linter.
You can change the default linter and use the more advanced golangci-lint by setting go.lintTool
to “golangci-lint” in your settings. It shares some of the performance characteristics of megacheck, but supports a broader range of tools. You can configure golangci-lint with go.lintFlags
, for example to show issues only in new code and to enable all linters:
"go.lintFlags": ["--enable-all", "--new"],
You can also use staticcheck.
Another alternative of golint is revive. It is extensible, configurable, provides superset of the rules of golint, and has significantly better performance.
To configure revive, use:
"go.lintFlags": ["-exclude=vendor/...", "-config=${workspaceFolder}/config.toml"]
Finally, the result of those linters will show right in the code (locations with suggestions will be underlined), as well as in the output pane.
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
.
To use the debugger, you must currently manually install delve. For more read Debugging Go Code Using VS Code.
If using WSL on Windows, you will need the WSL 2 Linux kernel. See WSL 2 Installation and note the Window 10 build version requirements.
To remote debug using VS Code, read Remote Debugging.
To quickly get all dependencies installed (or updated) see the Go Tools wiki page.
You can set up a development environment for debugging the extension during extension development. Read more at Building, Debugging and Sideloading the extension in Visual Studio Code.
This extension uses a host of Go tools to provide the various rich features. These tools are installed in your GOPATH by default. If you wish to have the extension use a separate GOPATH for its tools, provide the desired location in the setting go.toolsGopath
. Read more about this and the tools at Go tools that the Go extension depends on.
Please see our wiki on Frequently Asked Questions to get answers to your questions or get started with troubleshooting.
This project welcomes contributions and suggestions. Please go through our Contributing Guide to learn how you can contribute. It also includes details on the Contributor License Agreement.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.