如何在VSCode中查找命令标识符?含调试启动命令标识查询
如何查找VSCode命令标识符(附Debug命令ID)
我经常在扩展开发里碰到这个需求,给你分享两个靠谱的通用方法,以及你要的Debug: Start Debugging的标识符:
通用查找方法
方法一:命令面板快速查看(最简便)
这是我平时用得最多的方式,完全不用碰代码:
- 按下
Ctrl+Shift+P打开命令面板 - 找到你目标命令的标题(比如
Debug: Start Debugging) - 按住
Ctrl键(Mac系统换成Cmd键),这时候命令标题旁边会直接弹出对应的命令标识符 - 点击这个标识符就能一键复制到剪贴板,直接用在你的扩展代码里
方法二:通过开发者工具批量查看
如果需要批量找命令或者做精准筛选,用这个方法:
- 按下
Ctrl+Shift+I(Mac是Cmd+Opt+I)打开VSCode的开发者工具 - 在控制台里输入这段代码并回车,就能列出所有已注册的命令标识符:
vscode.commands.getCommands(true).then(commands => commands.forEach(cmd => console.log(cmd))); - 要是想只看某一类命令(比如Debug相关),可以改成过滤逻辑:
vscode.commands.getCommands(true).then(commands => { const debugCmds = commands.filter(cmd => cmd.startsWith('debug')); debugCmds.forEach(cmd => console.log(cmd)); });
Debug: Start Debugging的命令标识符
你要的这个命令的标识符是debug.startDebugging,在扩展里调用它的示例TypeScript代码如下:
import * as vscode from 'vscode'; // 在你的扩展逻辑中调用 async function triggerDebug() { await vscode.commands.executeCommand('debug.startDebugging'); }
内容的提问来源于stack exchange,提问作者Nurbol Alpysbayev
相关产品推荐
相关产品推荐

