41

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.

2
  • 2
    With VSCode 1.52 (Nov. 2020), you will have ${fileWorkspaceFolder}. Commented Nov 17, 2020 at 7:22
  • @VonC - Thank you for the hint, and the link! Commented Nov 17, 2020 at 7:54

2 Answers 2

52

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.

Sign up to request clarification or add additional context in comments.

Comments

5

Open C:\Users\your user name\AppData\Roaming\Code\User\keybindings.json

Copy the data object below and add it to keybindings.json. Use whatever predefined variables you want.

{
    "key":  "alt+q",
    "command": "workbench.action.terminal.sendSequence",
    "args": {
        "text" : "echo file = '${file}' : workspaceFolder = '${workspaceFolder}'\u000D"
    }
}

Type alt+q in terminal to see results.

2 Comments

And what if you are using Linux?
On Mac the path appears to be: ~/Library/Application Support/Code/User/keybindings.json. For another OS you can find the file (and the associated path) by activating the command window and entering "Open Keyboard Shortcuts (JSON)".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.