Smart Console Log Helper
一个智能的 VS Code 插件,通过快捷键快速生成 console.log 语句,支持选中变量和剪贴板内容,让调试更高效。
🚀 特性
- 快捷键支持: 使用
Ctrl+Shift+L (Windows/Linux) 或 Cmd+Shift+L (Mac) 快速生成 console.log
- 智能变量检测: 选中变量时自动生成对应的 console.log 语句
- 剪贴板集成: 没有选中文本时,自动读取剪贴板内容
- 三种输出格式:
- 简单格式:
console.log(variable);
- 标签格式:
console.log('🐛 variable:', variable); (带 Bug 图标)
- 花式格式:
console.log('📌 [时间戳] variable:', variable); (带图钉图标和动态时间戳)
- 智能位置插入: 支持在光标位置或当前行之后插入 console.log
- 变量名清理: 自动清理变量名,移除 const/let/var 等前缀
📦 安装
- 在VS Code中打开扩展面板 (
Ctrl+Shift+X 或 Cmd+Shift+X)
- 搜索 "Smart Console Log Helper"
- 点击安装
🔧 使用方法
基本使用
- 选中变量: 在代码中选中一个变量名
- 使用快捷键: 按
Ctrl+Shift+L (Windows/Linux) 或 Cmd+Shift+L (Mac)
- 自动生成: 插件会自动在适当位置生成 console.log 语句
剪贴板使用
- 复制变量名到剪贴板 (
Ctrl+C 或 Cmd+C)
- 将光标放在想要插入 console.log 的位置
- 使用快捷键
Ctrl+Shift+L (Windows/Linux) 或 Cmd+Shift+L (Mac)
示例
// 选中变量 'user'
const user = { name: '张三', age: 25 };
// 使用快捷键后生成(标签格式):
console.log('🐛 user:', user);
⚙️ 配置
插件提供了以下可自定义的设置:
- 类型:
string
- 可选值:
"simple", "labeled", "fancy"
- 默认值:
"labeled"
- 描述: 默认的 console.log 格式化样式
smartConsoleLog.insertAfterCurrentLine
- 类型:
boolean
- 默认值:
true
- 描述: 是否在当前行之后插入 console.log,而不是在光标位置
配置示例
{
"smartConsoleLog.format": "labeled",
"smartConsoleLog.insertAfterCurrentLine": true
}
💡 输出示例
Simple 格式
console.log(myVariable);
Labeled 格式(带 Bug 图标)
console.log('🐛 myVariable:', myVariable);
Fancy 格式(带图钉图标和时间戳)
console.log(`📌 [${new Date().toLocaleTimeString()}] myVariable:`, myVariable);
🎯 支持的语言
- JavaScript
- TypeScript
- JavaScript React (JSX)
- TypeScript React (TSX)
- Vue.js
- 其他支持 JavaScript 语法的文件
🛠️ 开发
如果你想为此项目做出贡献,请遵循以下步骤:
- 克隆仓库
- 安装依赖:
npm install
- 编译项目:
npm run compile
- 运行测试:
npm test
- 在调试模式下启动VS Code:
F5
📝 更新日志
v1.0.0
- 初始版本发布
- 支持基本的 console.log 生成功能
- 添加剪贴板集成
- 提供多种格式化选项
- 添加配置选项
🤝 贡献
欢迎提交 Issues 和 Pull Requests!
📄 许可证
MIT License
享受编程的乐趣! 🎉
| |