调试唯一的javascript文件时,是否真的需要更改launch.json中的文件名?

调试唯一的javascript文件时,是否真的需要更改launch.json中的文件名?,javascript,debugging,visual-studio-code,Javascript,Debugging,Visual Studio Code,我目前正在调试几个javascript文件。在Visual Studio代码中启动调试器之前更新文件路径非常令人沮丧 是否可以通过某种方式将vsc调试器配置为自动获取用户打开的文件并自动启动调试器,以避免反复更新此launch.json脚本 launch.json { "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "L

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

是否可以通过某种方式将vsc调试器配置为自动获取用户打开的文件并自动启动调试器,以避免反复更新此launch.json脚本

launch.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 ...
    }
  ]
}
根据报告,有:

"program": "${file}",

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

在我的例子中,您必须使用不同的选项,例如
${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