
To get started with Go development in VSCode, you'll want to install the Go extension. This will give you access to features like code completion, debugging, and project exploration.
The Go extension is available in the VSCode marketplace, and installation is a breeze. Just search for "Go" in the extensions panel and click install.
With the Go extension installed, you'll be able to create new Go projects in VSCode using the "Go: Create Go Workspaces" command. This will set up a basic directory structure for your project.
Go development in VSCode also makes it easy to manage your Go modules. You can use the "Go: Get" command to download dependencies, and the "Go: Clean" command to remove unnecessary files.
Expand your knowledge: Golang Create
Getting Started
To get started with debugging Go code in VS Code, open a file to debug in the editor and select the Run and Debug button from the Run view.
You can also start debugging using the Start Debugging (F5) command from the Run menu or from the Command Palette.
If you already have launch configurations for the project, the Run view will display the configuration list to choose from.
Install the Extension
To get started, you'll need to install the Go extension in Visual Studio Code. This will provide you with IntelliSense, code navigation, and advanced debugging features.
You can bring up the Extensions view by clicking on the Extensions icon in the Activity Bar. Alternatively, you can use the keyboard shortcut Ctrl+Shift+X.
Search for the Go extension in the Extensions view, then select "Install" to proceed with the installation.
The installation process is straightforward, and you can track its progress in the Extensions view.
You can also install the extension by clicking on the Extension manager button in the left side panel and following the same steps.
For another approach, see: Go Template Html
Import Packages
As you start working on your Go file, you'll want to import the necessary packages. The extension organizes imports and removes unused imports by default.
To get started, run the command Go: Add Import to get a list of packages that can be imported to your Go file. This will help you choose the right packages for your project.
You can override the per-language default settings if you want different behavior. This is done by following the instructions provided by the extension.
Choose one package from the list and it will get added in the import block of your Go file. This is a straightforward process that will save you time in the long run.
Writing and Debugging
Writing and Debugging is a crucial part of the Go development experience in VS Code. You can debug Go code using the Delve debugger, which is a powerful tool for inspecting variables and setting breakpoints.
Some features unique to Go are local and remote debugging, data inspection using Delve's expression syntax, and dynamic configuration change and inspection options with the dlv command from the DEBUG CONSOLE. These features make debugging Go code a breeze.
To get started, create a break point on the line you want to inspect by clicking to the left of the numbered line or by placing your cursor on the line and hitting F9. You can also open the Debug view by selecting the debug icon in the Activity Bar or by using the keyboard shortcut Ctrl+Shift+D.
For more insights, see: Gcloud Api Using Golang
Here are some unique Go debugging features:
- Local & remote debugging
- Data inspection using Delve's expression syntax
- Dynamic configuration change and inspection options with dlv command from DEBUG CONSOLE
- Ability to hide/show system goroutines (use hideSystemGoroutines configuration)
- Disassembly view support (right-click your source code and select Open Disassembly View)
- Experimental function call, core inspection, Mozilla rr support
IntelliSense
IntelliSense is a powerful tool that provides you with suggested completions as you type in a Go file. This feature is provided by the Go language server, gopls, maintained by the Go team.
You can configure the behavior of gopls using the gopls settings.
As you type, IntelliSense will give you suggestions 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.
Use ⌃Space (Windows, Linux Ctrl+Space) to trigger the suggestions manually.
With IntelliSense, you can easily access information about variables, functions, and structs by hovering over them. This will give you information on that item such as documentation, signature, etc.
Broaden your view: Golang Pkg
Semantic Syntax Highlighting
Semantic syntax highlighting is a game-changer for better code readability. Enabling semantic highlighting by turning on Gopls' ui.semanticTokens setting can give you a significant boost in syntax highlighting.
This setting is recommended for those who want to move away from the default TextMate-based syntax highlighting.
Worth a look: Setting up Golang
Formatting
Formatting is a crucial aspect of writing, and 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, but you can disable this behavior by setting editor.formatOnSave to false for the [go] language identifier.
You can change this setting using your JSON setting files, making it easy to customize your formatting preferences.
Formatting is provided by gopls, and if you want gofumpt-style formatting, you can configure gopls to use gofumpt.
If you have multiple formatters activated for Go files, you can select the Go extension as the default formatter, streamlining your workflow.
Code Navigation and Organization
Code navigation in VSCode for Go is a breeze. You can access a range of features from the context menu in the editor, including Go to Definition, Go to Type Definition, and Peek Definition.
To navigate via symbol search, use the Go to Symbol commands from the Command Palette (⇧⌘P). You can also use the Go: Toggle Test File command to navigate between a Go file and its test implementation.
Here are some key code navigation commands to keep in mind:
- Go to Definition: F12
- Go to Type Definition: Go to the type that defines a symbol.
- Peek Definition: ⌥F12 (Windows Alt+F12, Linux Ctrl+Shift+F10)
- Go to References: ⇧F12 (Windows, Linux Shift+F12)
- Show Call Hierarchy: ⇧⌥H (Windows, Linux Shift+Alt+H)
- Go to Implementations: ⌘F12 (Windows, Linux Ctrl+F12)
VSCode also provides a Go Outliner, which offers an outline view for your Go code, making it easier to navigate through your project's structure.
Signature Help
Signature Help is a game-changer for anyone who's ever struggled to remember function parameters.
You can trigger signature help manually by pressing ⇧⌘Space (or Ctrl+Shift+Space on Windows and Linux) while the cursor is inside the function call parentheses.
This feature provides a pop-up with the function signature, and as you type the parameters, the hint (underline) moves to the next parameter, making it easy to see what's required.
Code Navigation
Code navigation is a powerful tool that helps you quickly move around your codebase. You can access code navigation features from the context menu in the editor.
To navigate to the source code of a type definition, press F12. If you want to see all references for a type, press Shift+F12. You can also use the Peek Definition feature to bring up a Peek window with the type definition by pressing ⌥F12 (Windows Alt+F12, Linux Ctrl+Shift+F10).
The Go to Symbol commands from the Command Palette are another way to navigate your code. You can use these commands to find a specific symbol in your file or workspace.
Here are the Go to Symbol commands:
Navigation is especially useful when working on larger projects. It can save you time and effort by making it easier to find what you need.
Refactoring
Refactoring is a crucial part of code navigation and organization. To start refactoring, select the area of your code that needs attention, such as a variable or function body.
Click on the Code Action light bulb icon that appears in the selected area to access refactoring options. This icon can also be accessed by selecting Refactoring... or Rename Symbol (F2) from the VS Code context menu.
Refactoring can be a time-consuming process, but with the right tools, you can streamline your workflow. By selecting the correct area for refactoring, you can avoid unnecessary steps and focus on the task at hand.
The Code Action light bulb icon is a convenient way to access refactoring options without having to navigate through menus. This feature saves you time and effort, allowing you to focus on writing clean and efficient code.
Debugging
Debugging is a crucial part of the development process, and VS Code provides a robust set of features to help you identify and fix issues in your Go code.
You can debug Go code by utilizing the Delve debugger, which is integrated into the Go extension for VS Code. This allows you to inspect variables, set breakpoints, and step through your code line by line.
Some features unique to Go debugging in VS Code include local and remote debugging, data inspection using Delve's expression syntax, and the ability to hide or show system goroutines. You can also use the dlv command from the DEBUG CONSOLE to dynamically change and inspect configurations.
The Go extension also supports disassembly view, which allows you to view the disassembled code of your program. This can be useful for low-level debugging and optimization.
Here are some of the key features of the Go debugger in VS Code:
- Local and remote debugging
- Data inspection using Delve's expression syntax
- Dynamic configuration change and inspection options with dlv command from DEBUG CONSOLE
- Ability to hide or show system goroutines
- Disassembly view support
- Experimental function call, core inspection, and Mozilla rr support
To get started with debugging, you can create a breakpoint by clicking to the left of the numbered line in your code, or by pressing F9. You can then open the Debug view by selecting the debug icon in the Activity Bar, or by using the keyboard shortcut Ctrl+Shift+D.
Once you have created a breakpoint, you can run the debugger by selecting Run and Debug, or by pressing F5. You can then hover over the variable name on line 7 to see its value, and exit the debugger by clicking Continue on the debugger bar, or by pressing F5.
Note that VS Code also supports remote debugging, which allows you to debug your code on a remote machine or container. This can be useful for testing and debugging code in a production-like environment.
Advanced Debugging
You can debug Go code in VS Code using the Delve debugger, which provides some unique features.
Local and remote debugging are supported, allowing you to debug your Go code on your local machine or remotely.
Data inspection is made easy with Delve's expression syntax, enabling you to peek into the inner workings of your code.
To inspect variables, set breakpoints, and perform other debugging activities, check out VS Code debugging.
Some features unique to Go debugging are:
- Local & remote debugging
- Data inspection using Delve's expression syntax
- Dynamic configuration change and inspection options with dlv command from DEBUG CONSOLE
- Ability to hide/show system goroutines (use hideSystemGoroutines configuration)
- Disassembly view support (right-click your source code and select Open Disassembly View)
- Experimental function call, core inspection, Mozilla rr support
Testing and Running
You can easily run tests, benchmarks, and profiles for a given function, file, package, or workspace using the VS Code Test UI and editor CodeLens elements. Alternatively, you can use a set of commands such as Go: Test Function At Cursor, Go: Test File, Go: Test Package, and Go: Test All Packages in Workspace.
These commands are available through the Command Palette, and you can explore more test-related commands by typing "Go: test" in it. You can also use gotests to generate test skeletons for functions, and go test to run tests.
To configure the extension to run tests and compute test coverage, you can use settings such as go.testOnSave, go.coverOnSave, and go.testFlags.
A fresh viewpoint: Golang Package Alias
Test
Testing and running are essential parts of the development process.
You can easily run tests, benchmarks, and profiles for a given function, file, package, or workspace using the VS Code Test UI and editor CodeLens elements.
There are many test-related commands available through the Command Palette, which can be accessed by typing "Go: test".
Some of these commands include "Go: Test Function At Cursor", "Go: Test File", and "Go: Test Package".
These commands can be used to generate test skeletons for functions in the current package, file, or at the cursor using gotests.
Alternatively, you can use "Go: Test All Packages in Workspace" to run tests in the current package, file, or at the cursor using go test.
To get test coverage, you can use the "Go: Test Coverage" command.
You can configure the extension to run tests and compute test coverage using the following settings:
- go.testOnSave
- go.coverOnSave
- go.testFlags
Launch
To launch and debug your project, select Run > Start Debugging (F5). This will start the debug session by building and launching the program.
Suggestion: Golang Run Debug Mode

The Go extension will launch the program, and you can terminate it when the debug session ends. This is a convenient way to get started with debugging.
To use the launch feature, you need to configure your launch.json file. The program attribute in this file needs to be the absolute path to the Go file, folder containing the main package, or test file.
For "Remote Debugging", add the port attribute to the launch configuration. This will allow VS Code to connect to the external dlv dap server at host:port and launch the target there.
Here's a summary of the launch options:
Settings and Configuration
To configure your Go project in VS Code, you can create a launch configuration file. This file, called launch.json, allows you to customize your debugging setup beyond the default options.
You can create a launch.json file by clicking "create a launch.json file" in the Run view, or by using the Command Palette to open an existing file. If you already have a launch.json file, you can add a new configuration to it by clicking the Add Configuration button and using IntelliSense to navigate available options.
The launch.json file has many configuration attributes, including the program attribute, which must point to the absolute path to the package or binary to debug in the remote host's file system. You can also use the go.delveConfig settings to adjust the default value of configuration properties, such as the -gcflags and -o flags for build.
Here are some key settings you can configure using go.delveConfig:
You can also configure environment variables, such as GOPATH, which specifies the root of your Go Workspace. By default, the workspace is located at %USERPROFILE%/go for Windows, but you can change this by setting the GOPATH variable in your system settings.
Settings
You can adjust the default value of various configuration properties using the go.delveConfig settings. These default values are useful when you choose to run a debug session without a launch configuration set in launch.json.
For example, debug sessions started using the Debug Test code lenses use the adjusted values from these settings. The -gcflags=all=-N -l flag tells the go build command to preserve the debug information. This flag is particularly useful when you want to ensure that your debug sessions have access to all the necessary information.

The -o flag causes the compiled binary to be placed in "${fileDirname}/__debug_bin". You can configure extra build flags and environment variables used for build as args or options' env settings.
It's a good idea to add __debug_bin to your .gitignore to avoid debugging binaries getting checked-in into your repository. This will help keep your code clean and prevent any issues that might arise from including debugging binaries in your repository.
Related reading: Vscode Golang Debugging
Launch.json Attributes
Launch.json Attributes are crucial for customizing your VS Code experience.
The "version" attribute specifies the version of the launch configuration file, which is usually set to "0.2.0" or higher.
A "configurations" section is required in the launch.json file, which contains one or more launch configurations.
Each configuration has a unique "name" attribute that identifies it.
The "type" attribute specifies the debugger type, such as "node" or "python", which determines how the debugger behaves.
The "request" attribute is optional and specifies the type of request to make when launching the debugger.
The "preLaunchTask" attribute specifies a task to run before launching the debugger.
The "program" attribute specifies the path to the executable or script to be debugged.
The "args" attribute specifies the command-line arguments to pass to the executable or script.
The "env" attribute specifies the environment variables to be passed to the executable or script.
The "stopAtEntry" attribute is optional and specifies whether to stop at the entry point of the program.
The "outFiles" attribute specifies the output files to be considered when debugging.
The "sourceMaps" attribute is optional and specifies whether to use source maps when debugging.
Prerequisites and Tools
To get started with Go development in Visual Studio Code, you'll need to meet some prerequisites.
You'll need to have the GO language installed on your Windows system, as well as Visual Studio Code and the GO Extension for Visual Studio Code.
Here are the specific requirements:
- GO language in Windows
- Visual Studio Code
- GO Extension for Visual Studio Code
Once you have these requirements met, you can start installing the necessary tools.
Featured Images: pexels.com


