【发布时间】:2023-03-24 03:10:01
【问题描述】:
我们如何配置.vscode/launch.json 来调试 Deno 项目?
当我在configurations 时,VSCode 提供的 IntelliSense 没有为 Deno 提供选项。或者这个有扩展吗?
【问题讨论】:
我们如何配置.vscode/launch.json 来调试 Deno 项目?
当我在configurations 时,VSCode 提供的 IntelliSense 没有为 Deno 提供选项。或者这个有扩展吗?
【问题讨论】:
您需要按照the deno manual 附加调试器。
创建.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
【讨论】:
"outputCapture": "std" 才能在调试控制台中查看日志。
"outputCapture": "std"。谢谢@ford04
"debug.javascript.usePreview": false,因为github.com/denoland/vscode_deno/issues/…
官方VS Code Deno extension自带方便的debug supportv2.3.0开头。
来自 PR 的截屏视频:你已经可以按 F5 来调试没有launch.json 的活动文件(非常有用)。
使用Deno 条目自动生成launch.json:按CTRL+Shift+D(打开调试视图)→ “创建一个 launch.json 文件” → Deno
launch.json 中添加 Deno 条目
在打开的launch.json 中按Add Configuration...(参见上面的截屏视频)。
F5 现在将触发当前活动的调试启动操作。
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"
},
快捷方式称为"Debug: Select and Start Debugging" - 另见this related post。
要在调试控制台中显示日志输出,我仍然需要在配置条目中添加"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
}
]
}
附:刚刚添加到 Evandro Pomatti 的答案中
【讨论】: