我在尝试调试一些角度打字稿源代码时面临VS代码调试器的问题,我认为原因是其中一些VS Code Variables具有错误的值 - 正如建议的here。
我想遵循这个建议,但我看不出如何查询VS代码变量(例如,为我的项目显示这些变量的当前值)。
其中一个变量是
$ {} workspaceFolder
它们在VS代码的配置文件中使用,对于launch.json
文件中的此示例。
你知道是否有办法显示这些值?例如,记录值或在警报窗口中显示它们就足以让我对其进行故障排除。
可能有更好的方法,但你可以运行
// "preLaunchTask": "Echo vars" in your debug launch like:
{
"name": "Chrome : Launch with sourcemaps",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceRoot}",
"sourceMaps": true,
"runtimeArgs": [
"--remote-debugging-port=9222"
],
"preLaunchTask": "Echo vars"
},
在您的启动任务中,然后在tasks.json中添加:
{
"label": "Echo vars",
"command": "echo",
"args": [
"${env:USERNAME}",
"workspaceFolder = ${workspaceFolder}"
],
"type": "shell"
},
这些值将回显给终端。
编辑:因为更高版本的vscode现在支持向终端发送变量,这个更简单的键绑定将打印终端中的值:
{
"key": "alt+q",
"command": "workbench.action.terminal.sendSequence",
"args": {
// "text": "${env:USERNAME}", // this works
"text" : "file = ${file}; workspaceFolder = ${workspaceFolder}"
}
},
然后Alt-q打印出值。