问题描述
我正在编写 javascript,目前正在做简单的练习/程序.有时,我希望运行我的文件进行测试.我知道我可以创建一个 HTML
文件并在控制台中执行此操作.在 Sublime 中,有一种方法可以构建"当前文件并立即查看结果(例如,发送到 console.log 的任何内容).
I am writing javascript and am currently doing simple exercises/programs. At times, I wish to run my file for testing purposes. I am aware I could create an HTML
file and do this within the console. In Sublime, there exists a way to "build" the current file and immediately see the results (say, whatever is sent to console.log).
对于 VS Code,似乎对于我想以这种方式构建"/调试的每个文件,我必须手动更改 launch.json
文件以反映当前程序的名称.
With VS Code, it seems that for every file I want to "build"/debug in this manner, I must manually change the launch.json
file to reflect the name of the current program.
我一直在研究解决这个问题的方法,我了解到有像 ${file}
这样的变量,但是当我在 launch.json
中使用它时程序"属性,例如:
I have been researching a way around this, and I learned that there are variables like ${file}
, but when I use that in the launch.json
"program" attribute, for example:
"program": "${workspaceRoot}/${file}"
有或没有 workspaceRoot
部分,我收到以下错误:
with or without the workspaceRoot
part, I get the following error:
Attribute "program" does not exist" (file name here).
我是否缺少一种简单的方法来完成此操作,还是每次我想运行该文件时都必须继续编辑 launch.json
?
Am I missing a simple way to accomplish this, or must I keep editing launch.json
every time I want to run the file?
提前致谢!
推荐答案
更改为:
"program": "${file}"
这篇关于在 VS Code 中调试当前文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!