Developing Go with VSCode
Visual Studio Code (abbreviated as VS Code) is a free, open-source code editor developed by Microsoft that supports multiple programming languages and provides features such as syntax highlighting, intelligent code completion, code refactoring, and debugging.
With the official Go extension for Visual Studio Code, you get intelligent code completion, go-to-definition, symbol search, unit testing, program debugging, and many other practical features that help with Go project development.
If you are not yet familiar with VS Code or have not installed it, you can refer to:VSCode Tutorial。
Installing the Go Plugin
Open the VS Code Extensions marketplace and search for:Go Extension for VS Code。
In the editor, click Extensions on the left, then search for Go, and install the official plugin:

Once installed, we can start writing Go code. Type fmt. to try the intelligent code completion:

IntelliSense
IntelliSense is provided by the gopls language service maintained by the official Go team, and its behavior can be customized through gopls configuration options.

1. Semantic Highlighting
VS Code highlights code based on TextMate grammar by default. For better semantic-level highlighting, enable it in the settingsui.semanticTokens:
"gopls": { "ui.semanticTokens": true }
2. Code Auto-completion
When editing Go source code, the plugin pops up code completion candidates in real time, supporting member completion for the current package, imported packages, and packages not yet imported; typing a package name followed by . brings up method and constant hints for that package.
Shortcut keys:
Ctrl+空格(⌃Space)manually trigger the completion popup
3. Hover Documentation
Hover the mouse over a variable, function, or struct, and a popup shows documentation comments, function signatures, and other details.
4. Function Parameter Hints
Type the opening parenthesis of a function(and the parameter signature pops up automatically; as you enter arguments, an underline follows to indicate the argument currently being filled in;
Shortcut keys:
Shift+Cmd+空格(⇧⌘Space)with the cursor inside the parentheses, manually trigger the parameter hints
Code Navigation
The editor's right-click menu includes a full set of built-in code navigation features:
- F12 go to definition: navigate to the source definition of a type/variable
- Go to Type Definition: locate the underlying type source of a variable
- Alt+F12 (⌥F12) peek definition: preview the source in a popup without switching files
- Shift+F12 (⇧F12) find references: list all locations where the current symbol is referenced
- Shift+Alt+H (⇧⌥H) call hierarchy: view the callers and callees of a function
- Cmd+F12 (⌘F12) go to implementation: view all implementing classes for an interface, and all interfaces implemented by a concrete class
Open command paletteShift+Cmd+P(⇧⌘P), quickly jump via symbol search:
Shift+Cmd+O(⇧⌘O): search for symbols within the current fileCmd+T(⌘T): search for symbols globally across the entire workspace
Using the Directive Go: Toggle Test File, quickly switch back and forth between business code and the corresponding test file.
Code Formatting
- Shortcut keys:
Shift+Alt+F(⇧⌥F)Format the current file with one click - You can also run "Format Document" via the command palette/right-click menu
Formatting Configuration
-
Disable format on save
"[go]": { "editor.formatOnSave": false
} 2.
Set the Go plugin as the default formatter for Go files
"[go]": {
"editor.defaultFormatter": "golang.go"
}
3.
Enable the strict gofumpt formatting style (stricter than native gofmt)
"gopls": {
"formatting.gofumpt": true
}
Formatting relies on gopls under the hood
Unit testing
The VS Code sidebar testing panel + CodeLens quick buttons above the code supportunit testing, benchmark testing, and performance profiling offunctions / files / packages / the entire project.
Enter in the command palette Go: test to see all test commands; commonly used ones:
- Go: Test Function At Cursor: run the test for the function at the cursor
- Go: Test File: run all test cases in the current file
- Go: Test Package: run all tests in the current code package
- Go: Test All Packages in Workspace: batch-test the entire project

The first three commands can automatically generate test case skeletons based on gotests; the plugin supports configuration:
go.testOnSave: automatically run tests on savego.coverOnSave: automatically generate test coverage on savego.testFlags: customize go test run parameters
Debugging
The Go plugin relies on the Delve debugger to debug Go code, with unique capabilities:
- Local debugging + remote service debugging
- Use Delve expression syntax to view custom data in the debug panel
- Run native dlv commands in the debug console to dynamically modify debug settings and inspect variables
- Configure
hideSystemGoroutinesHide/show system goroutines - Right-click code to open the Disassembly View
- Experimental features: function call debugging, core file analysis, Mozilla rr reverse debugging