YouTip LogoYouTip

Go Vscode

Visual Studio Code (VS Code) is a free, open-source code editor developed by Microsoft. It supports multiple programming languages and provides features like syntax highlighting, intelligent code completion, code refactoring, and debugging. With the official Go extension for Visual Studio Code, you can get intelligent suggestions, code navigation, symbol search, unit testing, program debugging, and other practical capabilities to assist with Go project development. > If you haven't heard of VS Code or haven't installed it yet, you can refer to: (https://example.com/vscode/vscode-tutorial.html). ### Install Go Plugin Open VS Code extension marketplace and search for: (https://marketplace.visualstudio.com/items?itemName=golang.Go). In the editor, click Extensions on the left sidebar, search for Go, and install the official plugin: !(https://example.com/wp-content/uploads/2026/06/tutorial_1780712149454.png) After installation, you can start writing Go code. Try typing fmt. to see the intelligent suggestion feature: !(https://example.com/wp-content/uploads/2026/06/tutorial_1780712974621.png) * * * ## IntelliSense IntelliSense is provided by the gopls language service maintained by the Go official team. You can customize its running rules through gopls configuration options. !(https://example.com/wp-content/uploads/2026/06/completion-signature-help.gif) ### 1. Semantic Highlighting VS Code uses TextMate syntax for code highlighting by default. For better semantic-level highlighting, enable `ui.semanticTokens` in the configuration: "gopls": { "ui.semanticTokens": true } ### 2. Auto Code Completion When editing Go source code, the plugin provides real-time code completion suggestions, supporting members from the current package, imported packages, and not-yet-imported packages. Type the package name + . to invoke method/constant hints from that package. > Shortcut: `Ctrl+Space(βŒƒSpace)` to manually invoke the completion popup ### 3. Hover Documentation Hover over variables, functions, or structs to see a popup with documentation comments, function signatures, and other details. ### 4. Function Parameter Hints When typing the left parenthesis `(` of a function, the parameter signature pops up automatically. When entering arguments, underscores follow to switch between parameters to fill in. > Shortcut: `Shift+Cmd+Space(β‡§βŒ˜Space)` to manually trigger parameter hints when the cursor is inside parentheses ## Code Navigation The right-click context menu in the editor provides a complete set of 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 source in a popup without switching files * **Shift+F12(⇧F12) Find All References**: List all locations where the current symbol is referenced * **Shift+Alt+H(⇧βŒ₯H) Call Hierarchy**: View the call chain of a function (callers and callees) * **Cmd+F12(⌘F12) Go to Implementations**: For interfaces, see all implementations; for concrete types, see all implemented interfaces Open the command palette `Shift+Cmd+P(β‡§βŒ˜P)` and use symbol search for quick navigation: * `Shift+Cmd+O(β‡§βŒ˜O)`: Search for symbols in the current file * `Cmd+T(⌘T)`: Search for symbols across the entire workspace Use the command `Go: Toggle Test File` to quickly switch between business code and its corresponding test file. * * * ## Code Formatting * Shortcut: `Shift+Alt+F(⇧βŒ₯F)` to format the current file with one click * You can also execute "Format Document" via the command palette or right-click menu ### Formatting Configuration 1. Disable auto-format on save "": { "editor.formatOnSave": false} 2. Set Go plugin as the default formatter for Go files "": { "editor.defaultFormatter": "golang.go"} 3. Enable gofumpt strict formatting style (stricter than native gofmt) "gopls": { "formatting.gofumpt": true} > Formatting is implemented based on gopls * * * ## Unit Testing VS Code sidebar testing panel + CodeLens quick buttons above code support unit testing, benchmarking, and performance sampling for **functions/files/packages/entire projects**. Enter `Go: test` in the command palette to view all test commands. Common ones include: * Go: Test Function At Cursor: Run tests 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 package * Go: Test All Packages in Workspace: Batch test the entire project !(https://example.com/wp-content/uploads/2026/06/testcommands.png) The first three commands can automatically generate test case skeletons based on gotests. The plugin supports configuration: * `go.testOnSave`: Automatically run tests when saving code * `go.coverOnSave`: Automatically generate test coverage on save * `go.testFlags`: Customize go test running parameters * * * ## Debugging The Go plugin uses the Delve debugger to implement Go code debugging, with these exclusive capabilities: 1. Local debugging + remote service debugging 2. Use Delve expression syntax in the debug panel to view custom data 3. Execute dlv native commands in the debug console to dynamically modify debug configuration and view variables 4. Configure `hideSystemGoroutines` to hide/show system goroutines 5. Right-click code to open the Disassembly View 6. Experimental features: function call debugging, core file analysis, Mozilla rr reverse debugging * * * ## More Related Tools AI Development Environment Online AI Application Generation and Development Platform
← Ts VscodeObsidian Web Clipper β†’