4

In the VSCode's lauch.json file, I use multiple configurations for debugging different files. And some of these variables are common between configurations. I wonder if this could be possible to define a global variable in the launch.json and use it in different locations of the file?

For example, I'm looking for a way to define variable_common once and use it in config 1 and config 2:

    "configurations": [
        {
            "name": "Python: config 1",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "args": ["variable_1", "variable_2", "variable_common"]
        },

        {
            "name": "Python: config 2",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "args": ["variable_3", "variable_4", "variable_common"]
        }
]

1 Answer 1

3

With the extension Command Variable you can create custom variables

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: config 1",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "justMyCode": true,
      "args": ["variable_1", "variable_2", "${input:VAR_COMMON}"]
    },
    {
      "name": "Python: config 2",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "justMyCode": true,
      "args": ["variable_3", "variable_4", "${input:VAR_COMMON}"]
    }
  ],
  "inputs": [
    {
      "id": "VAR_COMMON",
      "type": "command",
      "command": "extension.commandvariable.transform",
      "args": { "text": "common_arg" }
    }
  ]
}
Sign up to request clarification or add additional context in comments.

Comments

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.