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

15,477

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.

Share:
15,477

Related videos on Youtube

Matt
Author by

Matt

I am an application engineer with a German Diplom (university degree) in computer science*) working in international projects as technical lead, developing web and Windows applications as well as web and Windows services for the .NET Framework based on Microsoft technology. My main development platform is Visual Studio with TFS, Azure DevOps or Git, and I am working with C#, JavaScript, jQuery, SQL, LINQ, EF etc. I am also interested in efficient algorithms of all kinds, cryptography, multithreading, tips & tricks ... I am a Full-stack developer (C# and whatever front-end library or framework they want me to learn/support!) for both "on-prem" and Azure applications. In my opinion, StackOverflow is a great platform to exchange knowledge like this - I found many tips there, which is why I am always motivated to give back information by answering questions where I can. *) Note: According to wikipedia, the German Diplom is comparable with a Bachelor's and Master's degree in one (see http://en.wikipedia.org/wiki/Diplom). Some hints and tips around SO: Use https://stackoverflow.com/search, click on "Advanced..." to show options Search within your favorites: Enter infavorites:mine search_expr Search within your posts related to a tag. For example: user:mine [C#] finds all you have posted that is related to C#. Run SQL queries against stack overflow posts: check this out to download an archive and SQL for SO to run SQL queries against current stack exchange sites Use keyboard tags, e.g. <kbd>Alt</kbd> appears as Alt If necessary, add line breaks with <br/> *) Syntax highlighting in your posts - Use a tag like: <!-- language-all: lang-cs -->For all tags, see: this link (meta) Version tags: Use them to mark pre-C#6: <!-- if version [lt 6.0] --> To add runnable CSS/HTML/JavaScript code, use the code sample icon {} when editing your question rather than providing a JsFiddle link (but JsFiddle is good for testing). If you want to add runnable .NET code (C#, F# or VB.NET), you can create it in DotNetFiddle and add a link. For screenshots use the free tool http://www.screentogif.com/ Hide answers: use >! , like so (point with the mouse): What is the answer to the ultimate question? </br/> The answer is 42. *) use <sup>/<sub> for superscript/subscript #SOreadytohelp

Updated on June 04, 2022

Comments

  • Matt
    Matt almost 2 years

    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.

  • Matt
    Matt over 5 years
    That sounds good. Could you show me how to setup that launch task, please? Do you mean <br/> Terminal -> Configure Tasks... ?
  • Matt
    Matt over 5 years
    Yep, that worked, thank you. After adding it to the tasks.json config, I ran Terminal -> Run Task... -> "Echo vars" and then "Never scan..." and it got displayed inside the terminal window.
  • Mark
    Mark over 5 years
    I just meant you could add the task as a preLaunchTask right in your debug launch.json file. Just in case some variable values change when called through the debug launch rather than a straight task as you did. But both work.
  • Matt
    Matt over 5 years
    I see, didn't think of that. Thank you for the hint!
  • Matt
    Matt almost 5 years
    Regarding the Edit: Excellent hint, Mark! For those who had difficulties finding it (like me): To configure keyboard shortcuts the way you want, open Keyboard Shortcuts editor (File -> Preferences -> Keyboard Shortcuts) and click on the {} button on the right of the editor title bar. See here