1

I know how to pass fixed arguments in the launch.json, e.g. In Visual Studio Code, how to pass arguments in launch.json . What I really need is a prompt where I can give a value for an argument that changes.

In addition, my argument is a (data) directory for which there is a very ugly long absolute path. I'd really like to be able to set the working directory to a path which contains each of my individual data directories so I only need to provide a relative directory path, i.e. just the directory name.

I'm working with Python, on Windows (not my choice) using VS Code 1.55.2 (not my choice, either).

Kevin Buchs
  • 2,520
  • 4
  • 36
  • 55
  • [input-variables](https://code.visualstudio.com/docs/editor/variables-reference#_input-variables) or [pick-file](https://marketplace.visualstudio.com/items?itemName=rioj7.command-variable#pick-file) – rioV8 May 23 '22 at 16:09
  • Thanks, @rioV8 . I gave input-variables a spin and that seems a workable solution. I can make this work without having to set the working directory if I just use the input variable with a constant directory string prefixed to it. Then I only need to enter the leaf. If you would like credit for the answer, feel free to submit an answer. – Kevin Buchs May 23 '22 at 21:23

1 Answers1

5

You can use input variables

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Current File with arguments",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "args": [
        "--dir",
        "/some/fixed/dir/${input:enterDir}"
      ]
    }
  ],
  "inputs": [
    {
      "id": "enterDir",
      "type": "promptString",
      "description": "Subdirectory to process",
      "default": "data-0034"
    }
  ]
}

You can place the ${input:enterDir} in any string in the task "configurations" like the "cwd" property.

If you like to pick a directory from a list because it is dynamic you can use the extension Command Variable that has the command pickFile

Command Variable v1.36.0 supports the fixed folder specification.

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Current File with arguments",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "args": [
        "--dir",
        "${input:pickDir}"
      ]
    }
  ],
  "inputs": [
    {
      "id": "pickDir",
      "type": "command",
      "command": "extension.commandvariable.file.pickFile",
      "args": {
        "include": "**/*",
        "display": "fileName",
        "description": "Subdirectory to process",
        "showDirs": true,
        "fromFolder": { "fixed": "/some/fixed/dir" }
      }
    }
  ]
}

On Unix like systems you can include the folder in the include glob pattern. On Windows you have to use the fromFolder to convert the directory path to a usable glob pattern. If you have multiple folders you can use the predefined property.

rioV8
  • 24,506
  • 3
  • 32
  • 49