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

时间:2017-09-28 13:56:38

标签: javascript debugging visual-studio-code

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

是否有可能以某种方式配置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 ...
    }
  ]
}

2 个答案:

答案 0 :(得分:1)

根据VS Code documentation,有:

"program": "${file}",

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

答案 1 :(得分:1)

您必须尝试使用​​此处找到的不同选项 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
相关问题