Vscode-js-debug: Prompt for arguments?

Created on 24 Oct 2016  Â·  11Comments  Â·  Source: microsoft/vscode-js-debug

I'm working on a large Node project that's made up of several different packages, each one with a suite of tests. I have a launch.json configuration per package to run each test suite individually. But when I'm trying to debug a single failing test, the overhead of running the entire suite can really slow things down.

In those cases, I go in and manually edit the launch.json and add some arguments to the args field to tell Mocha to only run matching tests with the -g option:

"args": ["--opts", "tests/mocha.opts", "-g", "photos should upload and return a 200 response"],

However, this isn't super discoverable for other people on the team. Ideally, I'd like to make a configuration that prompts the user to provide a string that can be passed as the argument.

I really like how ${command.PickProcess} allows me to create a dynamic configuration with a GUI to prompt me for the process to attach to. Is there any way to do something similar for an argument value? If not, can I humbly submit this as a feature request? 😄

feature-request

Most helpful comment

@weinand Can you give an example of a task (entry of task.json) which uses a prompt to add command arguments?

All 11 comments

The mock debugger shows how to ask the user for a string/name from a launch config:
https://github.com/Microsoft/vscode-mock-debug/blob/master/src/extension.ts#L23
The problem is that you cannot (yet) easily use this approach in a launch config without writing that extension code and introducing a 'variable'.
But it is planned to simplify this: https://github.com/Microsoft/vscode/issues/12735

Since Microsoft/vscode#12735 has been implemented it is now possible to provide "Prompt for Arguments" functionality as an extension and use it in launch.json and task.json.

@weinand Can you give an example of a task (entry of task.json) which uses a prompt to add command arguments?

@weinand Can you ?

Applying what is said in https://code.visualstudio.com/docs/editor/variables-reference#_input-variables to the example from above:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "run tests",
      "command": "mocha",
      "args": [
         "--opts", "tests/mocha.opts",
         "-g", "'${input:someArgs}'"
       ]
    }
  ],
  "inputs": [
    {
      "id": "someArgs",
      "type": "promptString",
      "description": "enter some arguments"
    }
  ]
}

(I did not verify that this works...)

I verified that it works -- https://github.com/Microsoft/vscode-node-debug/issues/108#issuecomment-581815593

You can put an inputs section into launch.json, and reference the defined variables in your launch configurations.

Now I want ONE MORE thing - a way to get the OLD arg behavior allowing a space delimited arg string, because I want one generic configuration to debug any old script, like:

   configuration: [
   {
        // This runs the current file as a script with whatever args are typed 
        "type": "node",
        "request": "launch",
        "name": "Launch script",
        "cwd": "${fileDirname}",
        "program": "${file}",
        "args": "${input:argValues}",      // <== This doesn't work because this must be a list
        "skipFiles": [ "<node_internals>/**" ]
    },

With an input section as above with "id": "argValues"

@marvingreenberg your ONE MORE thing is covered by this feature request: https://github.com/microsoft/vscode/issues/83678

Sigh. Closed, due to overthinking. I can think of three approaches that
would be fine (allow args to be a list OR a space delimited string - , OR
have 'args' and 'argString' (mutually exclusive, and some people would use
the string of of convenience in super of imprecision) OR just do the
referenced flattening on the lists of lists and just document that input
"promptLists" have this behavior, or introduce some weird syntax
${[arglist]} to emphasize the difference)

On Tue, May 5, 2020, 11:31 AM Andre Weinand notifications@github.com
wrote:

@marvingreenberg https://github.com/marvingreenberg your ONE MORE thing
is covered by this feature request: microsoft/vscode#83678
https://github.com/microsoft/vscode/issues/83678

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/microsoft/vscode-node-debug/issues/108#issuecomment-624126462,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AABU5A45NNSV6WX2XO2MPPTRQAWO3ANCNFSM4CT3NF2Q
.

@marvingreenberg I just noticed that this issue lives in the "vscode-node-debug" repository and not "vscode", so it does not ask for a generic VS Code solution (which is not feasible for the reasons explained in length in microsoft/vscode#83678).

What you suggest is actually possible in a specific extension: node-debug could support an alternative argString property that takes a command-line-like string and parses it into the array args. This could even take place in the extension outside of the debug adapter.

/cc @connor4312 for js-debug

I don't want to comment too much in what is obviously the wrong place (as my earlier comment was) I apologize - and I see that 83678 is not closed permanently. Oh, but I can't comment Over there. I'm definitely +1 on @weinand suggestion to inject (e.g.) _args for string array - it is creative and provides a good appraoch for differnt uses including inputs: {

@marvingreenberg I've unlocked https://github.com/microsoft/vscode/issues/83678

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eamodio picture eamodio  Â·  5Comments

roblourens picture roblourens  Â·  7Comments

roblourens picture roblourens  Â·  5Comments

baptoutiego picture baptoutiego  Â·  3Comments

Skuriles picture Skuriles  Â·  5Comments