Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Go Function Literal FolderNew to Visual Studio Code? Get it now.
Go Function Literal Folder

Go Function Literal Folder

kacker

|
1 install
| (1) | Free
Fold Go function literals into arrow-function style for better readability
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Go Function Literal Folder

一个 VSCode 扩展,将 Go 语言中的函数字面量(匿名函数)折叠显示为类似箭头函数的简洁形式,提升代码可读性。

灵感来自 JetBrains 的 Go Function Literal Folder 插件。

功能演示

折叠前:

lo.Map(agents, func(a *Agent, _ int) *TemplateResp {
    return &TemplateResp{Name: a.Name}
})

折叠后:

lo.Map(agents, (a, _) => {
    return &TemplateResp{Name: a.Name}
})

特性

  • 🎯 自动识别 Go 函数字面量(匿名函数)
  • 🔄 一键切换折叠/展开状态
  • ⚙️ 可配置是否自动折叠
  • 🎨 自定义颜色:括号、箭头、参数分别着色
  • 👆 智能检测:光标在函数范围内时自动显示原始代码,离开后恢复折叠显示

使用方法

快捷键

快捷键 功能
Cmd+Alt+F (Mac) / Ctrl+Alt+F (Windows/Linux) 切换折叠状态

命令

在命令面板 (Cmd+Shift+P / Ctrl+Shift+P) 中:

  • Go Func Folder: Toggle Fold - 切换折叠状态
  • Go Func Folder: Fold All - 折叠所有函数字面量
  • Go Func Folder: Unfold All - 展开所有函数字面量

配置选项

在 VSCode 设置中搜索 goFuncFolder:

配置项 类型 默认值 说明
goFuncFolder.autoFold boolean true 打开 Go 文件时自动折叠
goFuncFolder.bracketColor string #939293 括号 ( 和 ) 的颜色
goFuncFolder.arrowColor string #ee9089 箭头 => 的颜色
goFuncFolder.paramsColor string #F78C6C 参数名的颜色
goFuncFolder.commaColor string #939293 逗号 , 的颜色

安装

方式一:从源码安装

  1. 克隆此仓库
  2. 运行 npm install
  3. 运行 npm run compile
  4. 按 F5 启动扩展开发主机进行测试

方式二:打包安装

  1. 安装 vsce: npm install -g @vscode/vsce
  2. 打包: vsce package
  3. 在 VSCode 中安装生成的 .vsix 文件

工作原理

该扩展使用 VSCode 的装饰器 API (Decoration API) 来实现视觉上的"折叠"效果:

  1. 使用正则表达式识别代码中的函数字面量
  2. 解析参数列表,提取参数名(省略类型信息)
  3. 使用装饰器隐藏原始的函数签名
  4. 在隐藏的位置显示简化的箭头函数形式

支持的模式

✅ 支持:

  • 作为函数参数的匿名函数
  • 赋值给变量的匿名函数
  • 立即执行的匿名函数

❌ 不会折叠:

  • 普通函数声明 (func name() {})
  • 方法声明 (func (r *Receiver) name() {})

许可证

MIT

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft