Go Anno - VSCode Extension
Auto generate comment for Golang. A VSCode port of the GoLand goanno plugin.
中文说明
Features
- Automatically generate structured comments for Go functions, methods, interfaces, structs, and packages
- 7 configurable template scenarios (Normal Method, Interface Method, Interface, Struct, Struct Field, Package, Other)
- 21 template variables with click-to-insert in settings
- Merge with existing comments (rewrite mode)
- Auto-indentation matching code context
- Cursor auto-positioning to
${todo} placeholder
Quick Start
- Open any
.go file
- Place cursor on a function, method, type, or package declaration
- Press
Ctrl+Alt+/ (Windows/Linux) or right-click → Goanno: Generate Comment
Supported Elements
| Element |
Example |
| Function |
func GetUser(id int) *User { |
| Method |
func (s *Service) Start(port int) error { |
| Interface |
type Repository interface { |
| Interface Method |
GetByID(id string) (*Model, error) |
| Struct |
type Config struct { |
| Struct Field |
Name string |
| Package |
package main |
Template Variables
| Variable |
Description |
${todo} |
Placeholder for description |
${function_name} |
Function or method name |
${receiver} |
Receiver name or type |
${receiver_name} |
Receiver name |
${receiver_type} |
Receiver type |
${receiver_name_type} |
Receiver name and type |
${params} |
Parameter name or type |
${param_name} |
Parameter name |
${param_type} |
Parameter type |
${param_name_type} |
Parameter name and type |
${return_types} |
Return name or type |
${ret} |
Same as ${return_types} |
${ret_name} |
Return name |
${ret_type} |
Return type |
${ret_name_type} |
Return name and type |
${date} |
Current date (yyyy-MM-dd HH:mm:ss) |
${interface_name} |
Interface name |
${struct_name} |
Struct name |
${struct_field_name} |
Struct field name |
${package_name} |
Package name |
${note} |
Previous comments (reserved) |
Default Templates
Normal Method:
//
// ${function_name}
// @Description: ${todo}
// @receiver ${receiver}
// @param ${params}
// @return ${return_types}
//
Package:
// Package ${package_name}
// @Description: ${todo}
Configuration
Open settings via:
Ctrl+Shift+P → "Goanno: Open Settings"
- Right-click in
.go file → "Goanno: Open Settings"
- Or edit directly in VSCode Settings (
settings.json)
| Setting |
Description |
goanno.covert |
Merge with existing comments |
goanno.templates.normal |
Normal method template |
goanno.templates.interface |
Interface template |
goanno.templates.interfaceMethod |
Interface method template |
goanno.templates.struct |
Struct template |
goanno.templates.structField |
Struct field template |
goanno.templates.package |
Package template |
goanno.templates.none |
Fallback template |
Keyboard Shortcut
| Platform |
Shortcut |
| Windows/Linux |
Ctrl + Alt + / |
| Mac |
Cmd + Alt + / |
Installation
From VSIX
- Download
goanno-x.x.x.vsix from Releases
- Open VSCode → Extensions (
Ctrl+Shift+X) → ... → Install from VSIX...
From Source
git clone https://github.com/yourname/goanno.git
cd goanno
npm install
npm run compile
Press F5 in VSCode to launch Extension Development Host.
中文说明
Go Anno 是一个 VSCode 插件,用于自动生成 Go 语言的函数/方法/接口/结构体注释。移植自 GoLand 平台的 goanno 插件。
快速开始
- 打开任意
.go 文件
- 将光标放在函数、方法、类型定义或 package 声明行上
- 按
Ctrl+Alt+/(Windows)或右键菜单选择 Goanno: Generate Comment
配置模板
打开设置页面:Ctrl+Shift+P → "Goanno: Open Settings",可分别配置 7 种场景的注释模板。
可用变量
支持 21 种模板变量,在设置面板中点击即可插入。
License
MIT
| |