vscode-go

An extension for VS Code which provides support for the Go language.

Subscribe to updates I use vscode-go


Statistics on vscode-go

Number of watchers on Github 3302
Number of open issues 139
Average time to close an issue 4 days
Main language TypeScript
Average time to merge a PR 3 days
Open pull requests 57+
Closed pull requests 37+
Last commit 7 months ago
Repo Created almost 3 years ago
Repo Last Updated 6 months ago
Size 35.9 MB
Homepage https://marketpla...
Organization / Authormicrosoft
Latest Release0.6.77
Contributors17
Page Updated
Do you use vscode-go? Leave a review!
View open issues (139)
View vscode-go activity
View on github
Latest Open Source Launches
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating vscode-go for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

Go for Visual Studio Code

Join the chat at https://gitter.im/Microsoft/vscode-go Build Status

Read the Release Notes to know what has changed over the last few versions of this extension.

This extension adds rich language support for the Go language to VS Code, including:

  • Completion Lists (using gocode)
  • Signature Help (using gogetdoc or godef+godoc)
  • Snippets
  • Quick Info (using gogetdoc or godef+godoc)
  • Goto Definition (using gogetdoc or godef+godoc)
  • Find References (using guru)
  • Find implementations (using guru)
  • References CodeLens
  • File outline (using go-outline)
  • Workspace symbol search (using go-symbols)
  • Rename (using gorename. Note: For Undo after rename to work in Windows you need to have diff tool in your path)
  • Build-on-save (using go build and go test)
  • Lint-on-save (using golint or gometalinter)
  • Format on save as well as format manually (using goreturns or goimports or gofmt)
  • Generate unit tests skeleton (using gotests)
  • Add Imports (using gopkgs)
  • Add/Remove Tags on struct fields (using gomodifytags)
  • Semantic/Syntactic error reporting as you type (using gotype-live)
  • Run Tests under the cursor, in current file, in current package, in the whole workspace (using go test)
  • Show code coverage
  • Generate method stubs for interfaces (using impl)
  • Fill struct literals with default values (using fillstruct)
  • [partially implemented] Debugging (using delve)
  • Upload to the Go Playground (using goplay)

IDE Features

IDE

How to use this extension?

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.

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: Users may want to consider turning Auto Save on in Visual Studio Code ("files.autoSave": "afterDelay") when using this extension. Many of the Go tools work only on saved files, and error reporting will be more interactive with Auto Save turned on. If you do turn Auto Save on, then the format-on-save feature will be turned off.

Note 3: 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. In this case, to get fresh results from such dependencies, enable the go.gocodeAutoBuild setting. This will make the extension use gocode's autobuild=true setting. If you experience any performance issues with autocomplete, you should try setting "go.gocodeAutoBuild": false in your VS Code settings.

Customizing the Go extension features

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.

Go Language Server (Experimental)

Set go.useLanguageServer to true to use the Go language server from Sourcegraph for features like Hover, Definition, Find All References, Signature Help, Go to Symbol in File and Workspace.

  • This is an experimental feature and is not available in Windows yet.
  • If set to true, you will be prompted to install the Go language server. Once installed, you will have to reload VS Code window. The language server will then be run by the Go extension in the background to provide services needed for the above mentioned features.
  • Everytime you change the value of the setting go.useLanguageServer, you need to reload the VS Code window for it to take effect.
  • To collect traces, set "go.languageServerFlags": ["-trace"]
  • To collect errors from language server in a logfile, set "go.languageServerFlags": ["-trace", "-logfile", "path to a text file that exists"]

Linter

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 Go Meta Linter by setting go.lintTool to gometalinter in your settings.

Go meta linter uses a collection of various linters which will be installed for you by the extension.

Some of the very useful linter tools:

  • errcheck checks for unchecked errors in your code.
  • varcheck finds unused global variables and constants.
  • deadcode finds unused code.

If you want to run only specific linters (some linters are slow), you can modify your configuration to specify them:

  "go.lintFlags": ["--disable=all", "--enable=errcheck"],

Alternatively, you can use megacheck which may have significantly better performance than gometalinter, while only supporting a subset of the tools.

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.

Commands

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 context
  • Go: Current GOPATH to see your currently configured GOPATH
  • Go: Test at cursor to run a test at the current cursor position in the active document
  • Go: Test Package to run all tests in the package containing the active document
  • Go: Test File to run all tests in the current active document
  • Go: Test Previous to run the previously run test command
  • Go: Test All Packages in Workspace to run all tests in the current workspace
  • Go: Generates unit tests for package Generates unit tests for the current package
  • Go: Generates unit tests for file Generates unit tests for the current file
  • Go: Generates unit tests for function Generates unit tests for the selected function in the current file
  • Go: Install Tools Installs/updates all the Go tools that the extension depends on
  • Go: 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 interface
  • Go: Fill Struct Fills struct literal with default values
  • Go: Run on Go Playground Upload the current selection or file to the Go Playground

You can access all of the above commands from the command pallet (Cmd+Shift+P or Ctrl+Shift+P).

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.

Optional: Debugging

To use the debugger, you must currently manually install delve. See the Installation Instructions for full details. On OS X it requires creating a self-signed cert to sign the dlv binary.

For more read Debugging Go Code Using VS Code.

Remote Debugging

To remote debug using VS Code, read Remote Debugging.

Install or update all dependencies

To quickly get all dependencies installed (or updated) see the Go Tools wiki page

Building and Debugging the Extension

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.

Tools this extension depends on

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.

License

MIT

vscode-go open issues Ask a question     (View All Issues)
  • almost 2 years FormatOnSave removes imports in use
  • almost 2 years Extension Unit Tests for Testing fails in Mac OS X with Go 1.7
  • almost 2 years debugger does not stop the process
  • almost 2 years Add command for clearing coverage highlight
  • almost 2 years Proposal: Option to not lint if there are build errors
  • almost 2 years godef to net package failed
  • almost 2 years Update gotests to support subtests
  • almost 2 years Add a Wiki page for all the features supported by the extension with Gifs
  • almost 2 years Debugging: support 'launchBrowser' in launch.json
  • almost 2 years Add setting to lint whole workspace rather than just the current package
  • almost 2 years Extract Method feature
  • almost 2 years Windows 10 / VSCode 1.6.1 - gofmt -w — updated file does not visually refresh in Editor
  • almost 2 years Add test on save feature
  • almost 2 years win10 vscode debugging, can't add/remove breakpoint.
  • almost 2 years completion doesn't show latest version of the file
  • almost 2 years import code completion is... too complete
  • almost 2 years IntelliSense should not appear within multiline strings
  • almost 2 years Signature Help and Quick Info do not show function comments for unexported functions in packages and all functions in main.go
  • almost 2 years debugger should warn if "program" property doesn't exist
  • almost 2 years Error squigglies don't update after selecting item in completions list
  • almost 2 years Poor sorting for completions list
  • almost 2 years kewywords missing from completions list
  • almost 2 years Allow setting options for gocode
  • almost 2 years GOPATH environment variable not current until restart of vscode
  • almost 2 years can't debug beego
  • almost 2 years Delete tooling source code once it's installed
  • almost 2 years Debugger not running and showing no errors on OSX
  • almost 2 years Auto-import suggests package twice when file is dirty
  • almost 2 years Add an option for logging
  • almost 2 years languageservice: implementation as a languageservice?
vscode-go open pull requests (View All Pulls)
  • Add support for coverage markup
  • [WIP] Add a go install command
  • initial oracle support using codeLens #8
  • [WIP] Add go-metalinter support
  • Adds vendor/ to GOPATH envvar at startup.
  • append cwd to gopath when debug program
  • Make sure tmp file for go code cover exists
  • Allow Go tools to be installed in a separate GOPATH
  • Replace godef with guru
  • Add command to extract method out of selected code
  • Preserve focus when running tests
  • Fixes #310 - install Missing Analysis Tool. Better feedback would be nice
  • update dependencies, add goimports, add channel select snippets
  • Add showLog to initialConfigurations
  • Move away from deprecated language configuration settings
  • Add command to extract method out of selected code
  • Substitute environment variable in gopath setting
  • Fix the executable name so ".exe" doesn't end up in the install warning
  • Fixes #13. Use diffs from the gorename tool instead of letting gorename update the file on disk.
  • minor fix hover doc unexcept line wrapping!
  • Proposal to implement collapsing
  • Fixes #316 Replace full path for vendor packages with relative path
  • adding kill command for test.
  • Add testFlags to user settings with -v as default
  • Fix signature / hover provider (e.g. for struct fields)
  • Due to issue #599, use gogetdoc instead of godef
  • Add support for reading http.proxy setting
  • if buildOnSave is on: build using -i
  • Add support for guru as a docs tool
  • Goimpl implementation
  • Add basic multi-package mode
  • Add testEnvVars from workspace config to debug environment
  • Support configuring gocode.
  • add support for testEnvFile
  • 📚 Fix misspelling on snippets/go.json
  • Show build/vet/lint status in Status bar. Fix #1456
  • Cyclometric complexity code lens
  • Add custom debug command support
  • Runnable golang scratch pad
  • Add support for expanderr.
  • Add `go.toolCommands` which specifies alternate command locations
  • Go documentation window
  • Add "Cancel Running Test" status bar item
  • Fix #1072 Avoid completions in block comments
  • Add $GOROOT/bin to $PATH for tools
  • add fillstruct tool
  • Typo: disable-all => disable=all
  • Added configuration to use legacy Find All References
  • Fix broken tests
  • Make generated file edit warning optional
  • Fix internal package import
  • feat: auto complete exported item`s comment
  • Use col numbers from cmd outputs to give src locations for error/warnings
  • Add benchmark debuging codelens
  • Add the output option for the delve
  • bugfix: Ensure 'debug test' codelens only tests the selected test.
  • WIP: Suggestion to expand func types to func snippets (#1553)
vscode-go list of languages used
vscode-go latest release notes
0.6.77 Fill struct fields with default values, show maps correctly when debugging and bug fixes
0.6.76 More bug fixes
* [Bug 1449](https://github.com/Microsoft/vscode-go/issues/1449): Rename fails due to cgo not being able to find the go executable.  
* [Bug 1508](https://github.com/Microsoft/vscode-go/issues/1508): Broken Path in Windows when running Go tools
0.6.74 Bug fixes and Bug fixes
  • Nikhil Raman (@cheesedosa)

    • Feature Request 1456: Show build/vet/lint status in status bar instead of opening output pane when run manually
  • Ramya Rao (@ramya-rao-a)

    • Bug 1470: Go: Build Workspace command or the setting "go.buildOnSave": "workspace" results in persistent error from trying to build the root directory with no Go files.
    • Bug 1469: Formatting adds in Chinese files some times.
    • Bug 1481: Untitled files in empty workspace results in build errors
    • Bug 1483: Generating unit tests for a function generates tests for other functions with similar names
Other projects in TypeScript