我们该如何配置 .vscode/launch.json
来调试 Deno 项目?
在 configurations
中,VSCode 提供的 IntelliSense 并没有提供针对 Deno 的选项。是否有相应的扩展可以使用?
我们该如何配置 .vscode/launch.json
来调试 Deno 项目?
在 configurations
中,VSCode 提供的 IntelliSense 并没有提供针对 Deno 的选项。是否有相应的扩展可以使用?
根据Deno手册,您需要连接调试器。
创建.vscode/launch.json
文件,并将<entry_point>
替换为实际脚本,然后按下F5。
{
"version": "0.2.0",
"configurations": [
{
"name": "Deno",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"runtimeArgs": ["run", "--inspect-brk", "-A", "<entry_point>"],
"port": 9229
}
]
}
它将在您在VS Code上设置的断点处停止,已在此处尝试并运行良好。
关于VS Code插件:
插件中的官方支持正在开发中- https://github.com/denoland/vscode_deno/issues/12
官方VS Code Deno扩展从v2.3.0开始提供便捷的调试支持。
您已经可以按下F5键调试活动文件,无需launch.json
文件(非常有用)。
要使用Deno
条目自动生成launch.json
文件:按下CTRL+Shift+D(打开调试视图)→“创建一个launch.json文件”→ Deno
launch.json
中添加Deno条目在打开的launch.json
中按下添加配置...
(请参见上面的屏幕录制)。
launch.json
{
"type": "pwa-node",
"program": "${file}", // change "program" value to "${file}"
// ...
},
// Inside keybindings.json
{
"key": "ctrl+alt+d",
"command": "workbench.action.debug.selectandstart",
"args": "Start debug task"
},
这个快捷方式称为"调试:选择并启动调试"
- 请参见此相关帖子。
要在调试控制台中显示日志输出,我仍需要将"outputCapture": "std"
添加到配置条目中。更多信息:
要调试当前文件,您可以使用以下配置 :)
"outputCapture": "std"
允许Deno将输出打印到VS代码控制台
{
"version": "0.2.0",
"configurations": [
{
"name": "Deno",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"runtimeArgs": ["run", "--inspect-brk", "-A", "${fileBasename}"],
"outputCapture": "std",
"port": 9229
}
]
}
P.S. 刚刚添加到 Evandro Pomatti 的回答中
attachSimplePort
替换port
。{
"name": "Deno",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"runtimeArgs": ["run", "--inspect-brk", "-A", "${fileBasename}"],
"outputCapture": "std",
"attachSimplePort": 9229
},
"outputCapture": "std"
才能在调试控制台中查看日志。 - ford04"outputCapture": "std"
以捕获控制台日志。谢谢 @ford04。 - Radical Edward"debug.javascript.usePreview": false
设为false,原因是https://github.com/denoland/vscode_deno/issues/12#issuecomment-656406826。 - phil294"port"
更改为"attachSimplePort"
如其他地方所述。 - adiabatic