当我调试一个唯一的javascript文件时,我真的需要更改launch.json中的文件名吗?



我目前正在调试几个javascript文件。在 Visual Studio Code 中启动调试器之前更新文件路径是非常令人沮丧的。

是否可以以某种方式将 vsc 调试器配置为自动获取用户已打开的文件并自动启动调试器以避免一遍又一遍地更新此 launch.json 脚本?

启动.json

{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program":
"${workspaceRoot}/server/operations/database/eClassKeywordsImport.js"
// "${workspaceRoot}/server/operations/NPL/stringAlgo.js"
// another file ...
// another file ...
}
]
}

根据 VS Code 文档,有:

"program": "${file}",

当前在活动编辑器选项卡中打开的文件路径中的源。

您必须使用此处找到的不同选项 https://code.visualstudio.com/docs/editor/variables-reference 例如,${file}打印整个路径,而不仅仅是文件名,因此${relativeFile}更好的选择

更多:

Predefined variables#
The following predefined variables are supported:
${workspaceFolder} - the path of the folder opened in VS Code
${workspaceFolderBasename} - the name of the folder opened in VS Code without any slashes (/)
${file} - the current opened file
${fileWorkspaceFolder} - the current opened file's workspace folder
${relativeFile} - the current opened file relative to workspaceFolder
${relativeFileDirname} - the current opened file's dirname relative to workspaceFolder
${fileBasename} - the current opened file's basename
${fileBasenameNoExtension} - the current opened file's basename with no file extension
${fileDirname} - the current opened file's dirname
${fileExtname} - the current opened file's extension
${cwd} - the task runner's current working directory on startup
${lineNumber} - the current selected line number in the active file
${selectedText} - the current selected text in the active file
${execPath} - the path to the running VS Code executable
${defaultBuildTask} - the name of the default build task
${pathSeparator} - the character used by the operating system to separate components in file paths
Predefined variables examples#
Supposing that you have the following requirements:
A file located at /home/your-username/your-project/folder/file.ext opened in your editor;
The directory /home/your-username/your-project opened as your root workspace.
So you will have the following values for each variable:
${workspaceFolder} - /home/your-username/your-project
${workspaceFolderBasename} - your-project
${file} - /home/your-username/your-project/folder/file.ext
${fileWorkspaceFolder} - /home/your-username/your-project
${relativeFile} - folder/file.ext
${relativeFileDirname} - folder
${fileBasename} - file.ext
${fileBasenameNoExtension} - file
${fileDirname} - /home/your-username/your-project/folder
${fileExtname} - .ext
${lineNumber} - line number of the cursor
${selectedText} - text selected in your code editor
${execPath} - location of Code.exe
${pathSeparator} - / on macOS or linux, \ on Windows

最新更新