Wayback Machine
249 captures
09 Feb 2017 - 05 Feb 2026
Mar APR May
16
2019 2020 2021
success
fail
About this capture
COLLECTED BY
Collection: GDELT Project
TIMESTAMPS
loading
The Wayback Machine - https://web.archive.org/web/20200416204432/https://code.visualstudio.com/docs/languages/go
This site uses cookies for analytics, personalized content and ads. By continuing to browse this site, you agree to this use. Learn more
Skip to content 
Visual Studio Code
  • Docs
  • Updates
  • Blog
  • API
  • Extensions
  • FAQ
  • Search
  • Search Search
  • Download VS Code Download VS Code Download

Version 1.44 is now available! Read about the new features and fixes from March.

Dismiss this update
'; document.body.appendChild(div.children[0]); }
  • Overview
  • Setup
    • Overview
    • Linux
    • macOS
    • Windows
    • Network
    • Additional Components
  • Get Started
    • Intro Videos
    • Tips and Tricks
    • User Interface
    • Themes
    • Settings
    • Key Bindings
    • Display Language
    • Telemetry
  • User Guide
    • Basic Editing
    • Extension Marketplace
    • IntelliSense
    • Code Navigation
    • Refactoring
    • Debugging
    • Version Control
    • Integrated Terminal
    • Tasks
    • Settings Sync
    • Snippets
    • Emmet
    • Command Line
    • Multi-root Workspaces
    • Accessibility
  • Languages
    • Overview
    • JavaScript
    • JSON
    • HTML
    • CSS, SCSS and Less
    • TypeScript
    • Markdown
    • PowerShell
    • C++
    • Java
    • PHP
    • Python
    • Go
    • T-SQL
    • C#
    • .NET Core
  • Node.js / JavaScript
    • Working with JavaScript
    • Node.js Tutorial
    • Node.js Debugging
    • Node.js Deployment
    • React Tutorial
    • Angular Tutorial
    • Vue Tutorial
    • Ember Tutorial
    • Debugging Recipes
    • Extensions
  • TypeScript
    • Tutorial
    • Compiling
    • Debugging
  • Python
    • Tutorial
    • Editing Code
    • Linting
    • Debugging
    • Environments
    • Testing
    • Jupyter Notebook Support
    • Python Interactive
    • Data Science Tutorial
    • Django Tutorial
    • Flask Tutorial
    • Create containers
    • Python on Azure
    • Settings Reference
  • Java
    • Getting Started
    • Navigate and Edit
    • Refactoring
    • Linting
    • Project Management
    • Build Tools
    • Run and Debug
    • Testing
    • Spring Boot
    • Application Servers
    • Java on Azure
    • Extensions
    • FAQ
  • C++
    • GCC on Windows
    • Microsoft C++
    • GCC on Linux
    • GCC on Windows Subsystem for Linux
    • Clang on macOS
    • Debugging
    • Editing
    • Settings
    • Enhanced colorization
    • c_cpp_properties.json
    • Debug configuration
    • Natvis framework
    • Pipe transport
    • Logging
    • FAQ
  • Containers
    • Overview
    • Node.js
    • Python
    • ASP.NET Core
    • Debug
    • Registries
    • Deploy to Azure
    • Choose a dev environment
    • Customize
  • Azure
    • Extensions
    • Deployment
    • Remote Debugging for Node.js
    • Docker
    • MongoDB
    • Kubernetes
    • Try Azure App Service
  • Remote
    • Overview
    • SSH
    • Containers
    • Visual Studio Online
    • Windows Subsystem for Linux
    • Tutorials
    • Tips and Tricks
    • Advanced Containers
    • Linux Prerequisites
    • FAQ

Topics

Go in Visual Studio Code

Using the Go extension for Visual Studio Code, you get language features like IntelliSense, code navigation, symbol search, bracket matching, snippets, and many more that will help you in Golang development.

go extension banner

You can install the Go extension from the VS Code Marketplace.

IntelliSense

Auto completions

As you type in a Go file, you can see IntelliSense providing you with suggested completions. This even works for members in current, imported, and not yet imported packages. Just type any package name followed by ., and you will get suggestions for the corresponding package members.

By setting go.autocompleteUnimportedPackages to true in your settings, you can also get suggestion for packages that you could import. Select one of these suggestions and an import to the selected package will be added to your file.

Tip: Use ⌃Space (Windows, Linux Ctrl+Space) to trigger the suggestions manually.

Hover Information

Hovering on any variable, function, or struct will give you information on that item such as documentation, signature, etc.

Information on hover

By default, the extension uses godef and godoc to get this information. You can choose to use gogetdoc instead by changing the setting go.docsTool in your User or Workspace Settings.

Signature help

When you open the ( while calling a function, a pop-up provides signature help for the function. As you keep typing the parameters, the hint (underline) moves to the next parameter.

Signature Help

Tip: Use ⇧⌘Space (Windows, Linux Ctrl+Shift+Space) to manually trigger the signature help when the cursor is inside the () in the function call.

The extension's signature help also uses godef and godoc. You can choose to use gogetdoc instead by changing the setting go.docsTool in your User or Workspace Settings.

Code navigation

Code navigation features are available in the context menu in the editor.

  • Go To Definition F12 - Go to the source code of the type definition.
  • Peek Definition ⌥F12 (Windows Alt+F12, Linux Ctrl+Shift+F10) - Bring up a Peek window with the type definition.
  • Go to References ⇧F12 (Windows, Linux Shift+F12) - Show all references for the type.

You can navigate via symbol search using the Go to Symbol commands from the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)).

  • Go to Symbol in File - ⇧⌘O (Windows, Linux Ctrl+Shift+O)
  • Go to Symbol in Workspace - ⌘T (Windows, Linux Ctrl+T)

You can also navigate back and forth between a Go file and its test implementation using the Go: Toggle Test File command.

Build, lint, and vet

On save, the Go extension can run go build, go vet, and your choice of linting tool (golint or gometalinter) on the package of the current file. You can control these features via the settings below:

  • go.buildOnSave
  • go.buildFlags
  • go.vetOnSave
  • go.vetFlags
  • go.lintOnSave
  • go.lintFlags
  • go.lintTool
  • go.testOnSave

The errors and warnings from running any/all of the above will be shown red/green squiggly lines in the editor. These diagnostics also show up in the Problems panel (View > Problems).

Formatting

You can format your Go file using ⇧⌥F (Windows Shift+Alt+F, Linux Ctrl+Shift+I) or by running the Format Document command from the Command Palette or the context menu in the editor.

By default, formatting is run when you save your Go file. You can disable this behavior by setting editor.formatOnSave to false for the [Go] language. You can change this using your json setting files

"[go]":  {
        "editor.formatOnSave": false
    }

You can choose among three formatting tools: gofmt, goreturns, and goimports by changing the setting go.formatTool.

Test

There are many test-related commands that you can explore by typing "Go: test" in the Command Palette.

Test Commands

The first three above can be used to generate test skeletons for the functions in the current package, file or at cursor using gotests. The last few can be used to run tests in the current package, file or at cursor using go test. There is also a command for getting test coverage.

Import packages

Run the command Go: Add Import to get a list of packages that can be imported to your Go file. Choose one and it will get added in the import block of your Go file.

Rename symbols

You can rename symbols using F2 or by running the Rename Symbol command in the context menu in the editor.

Debugging

The Go extension lets you debug Go code as well. You will need to install the Delve debugger manually as a prerequisite. Read Debugging Go code using VS Code for setup steps, information on remote debugging and a troubleshooting guide.

Next steps

This has been a brief overview showing the Go extension features within VS Code. For more information, see the details provided in the Go extension README.

To stay up-to-date on the latest features/bug fixes for the Go extension, see the CHANGELOG.

If you have any issues or feature requests, feel free to log them in the Go extension repo.

If you'd like to learn more about VS Code, try these topics:

  • Basic Editing - A quick introduction to the basics of the VS Code editor.
  • Install an Extension - Learn about other extensions are available in the Marketplace.
  • Code Navigation - Move quickly through your source code.
4/8/2020

In this article there are 9 sectionsIn this article

  • IntelliSense
  • Code navigation
  • Build, lint, and vet
  • Formatting
  • Test
  • Import packages
  • Rename symbols
  • Debugging
  • Next steps
  • Hello from Seattle.
  • Follow @code
  • Support
  • Privacy
  • Terms of Use
  • License
Microsoft homepage Microsoft homepage © 2020 Microsoft