Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I am facing an issue with VS code debugger while trying to debug some angular typescript source code, and I think the reason is that some of those VS Code Variables have the wrong value - as suggested here.

I'd like to follow that advice, but I see no way how to query the VS code variables (e.g. display the current values of these variables for my project).

One of these variables is

${workspaceFolder}

They are used in VS code's config files, for this example in the launch.json file.

Do you know if there is a way to display those values? For example, log the values or show them in an alert window would just be sufficient for me to troubleshoot it.

like image 666
Matt Avatar asked Nov 26 '18 16:11

Matt


People also ask

What is ${ workspaceFolder in VS Code?

${workspaceFolder} - the path of the folder opened in VS Code.

How do you display in VS Code?

Press Ctrl+Shift+P to bring up the Command Palette then start typing "display" to filter and display the Configure Display Language command. Press Enter and a list of installed languages by locale is displayed, with the current locale highlighted.

How do you view variables in VS Code?

Display a data tipSet a breakpoint in your code, and start debugging by pressing F5 or selecting Debug > Start Debugging. When paused at the breakpoint, hover over any variable in the current scope. A data tip appears, showing the name and current value of the variable.


1 Answers

Old answer:

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": "echo ${env:USERNAME}",  // this works
            "text" : "echo file = '${file}' : workspaceFolder = '${workspaceFolder}'\u000D"
        }
    }
]

then Alt-q prints out the values.

The \u000D at the end is just a return.

like image 194
Mark Avatar answered Sep 17 '22 04:09

Mark