How to display current values of VS Code's predefined variables (such as “${workspaceFolder}”)?

只谈情不闲聊 提交于 2019-11-30 13:43:55

There may be a better way but you could run a

//  "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"
},

in your launch task and then in tasks.json add:

{
   "label": "Echo vars",
   "command": "echo",
   "args": [
     "${env:USERNAME}",
     "workspaceFolder = ${workspaceFolder}"
   ],
   "type": "shell"
},

Those values will be echoed to the terminal.


EDIT: Because a later version of vscode now supports sending variables to the terminal this simpler keybinding will print out values in the terminal:

{
  "key":  "alt+q",
  "command": "workbench.action.terminal.sendSequence",
  "args": {
    // "text": "${env:USERNAME}",  // this works
     "text" : "file = ${file};  workspaceFolder = ${workspaceFolder}"
  }  
},

then Alt-q prints out the values.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!