New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic args for debug task #9544

Closed
normalser opened this Issue Jul 20, 2016 · 11 comments

Comments

Projects
None yet
4 participants
@normalser
Copy link

normalser commented Jul 20, 2016

It would be nice if one could define task with option dynamicArgs: true in launch.json (or something similar) that when starting debugger for the task - it would prompt user with text box to provide arguments that would be passed to the script (similar how current static args option works)

Use case: Ability to easily debug some cli tasks that can start with different arguments on command line

Right now one need to go to launch.json and edit arguments or duplicate configurations to handle different arguments

@weinand weinand self-assigned this Jul 21, 2016

@weinand

This comment has been minimized.

Copy link
Member

weinand commented Jul 21, 2016

@wallverb mock-debug shows how this is already possible if you are an extension owner.

The section "Debug Extension Authoring: Command Variables" in the 1.3.0 release notes provides background.

@mike-pt

This comment has been minimized.

Copy link

mike-pt commented Jan 28, 2017

So is this only possible if you're an extension owner?

I was just trying to use this for Python debugging.. but I get command 'AskForProgramName' not found

when I try to use:

    "configurations": [
        {
            "name": "Python",
            "type": "python",
            "request": "launch",
            "stopOnEntry": true,
            "pythonPath": "${config.python.pythonPath}",
            "program": "${workspaceRoot}/${command.AskForProgramName}",
[ ..... ]
@weinand

This comment has been minimized.

Copy link
Member

weinand commented Jan 29, 2017

@mike-pt at the moment variables like AskForProgramName are only valid for the debugger extension that defines the variable. So you are not able to use it in a launch config for 'python' because the variable is defined in the 'mock' debugger.

However, it is already possible to use the command ID instead of the variable: ${command.extension.mock-debug.getProgramName}.
Command IDs can be used in all launch configs, independent from where they come from.

Please note that you'll have to install the mock-debug extension for making the command extension.mock-debug.getProgramName available.

And we are planning to change the syntax a bit in the Februar milestone to this ${command:extension.mock-debug.getProgramName}

@mike-pt

This comment has been minimized.

Copy link

mike-pt commented Jan 30, 2017

I see, thanks for the information.

@weinand weinand added the debug label Jan 30, 2017

@mike-pt

This comment has been minimized.

Copy link

mike-pt commented Jan 30, 2017

Ok I was trying this but still got:
command 'extension.mock-debug.getProgramName}' not found same for askProgramName

I then realized that this is because I was still using "Python" as the debugger... so I deleted the launch.json and selected "mock debug", which works but it also means I can not specify a pythonpath... or args etc..

So still this is something targeted for extension owners not users...

You be nice if we could just naively do this... for me it would be mostly for args, the program I'm debugging can use different args and It would be useful to be asked for which args to run... for now I'll just hardcode them and change as needed.

But thanks once more, at least now I understand how it works (I think :) )

EDIT:
Actually never-mind, after vscode close/reopen "${command.extension.mock-debug.getProgramName}." works from python... so maybe the reload was not enough... not sure...

I can't use it for python args though... I suspect that would need changes on the Python Debbuger extension...

Still would love to see this naively... but one extra extension installed is not the end of the world.

@weinand

This comment has been minimized.

Copy link
Member

weinand commented Jan 30, 2017

@mike-pt variable substitution occurs before the launch config is passed to a debug adapter, so the Python Debugger extension (or any other debugger extension) is not involved in this.
But the issue is probably that the python args expects an array and ${command.extension.mock-debug.getProgramName} returns a string.

You can create an extension that implements nothing else than commands that can be used as variables in launch configs. So in theory you could create a command that asks the user for a string, breaks them into separate arguments and returns them as an array so that you could use them with the python args. But currently the missing piece is that variable substitution only works with strings, not arrays (and other types). We plan to lift this limitation.

BTW, a launch-config can contain launch configurations for different debuggers, you don't have to "delete" them when switching debuggers.

@mike-pt

This comment has been minimized.

Copy link

mike-pt commented Jan 30, 2017

Yeah that is the "issue" with arguments in the Python debugger... I don't see why its not a string though, Its not a bad idea to open an issue in their repo and ask for that....

With the proper changes we could then use "${command.extension.mock-debug.getProgramName}" in args and input the full args "line", but that's something to ask in the python debugger extension repo I suppose :)

I'm very recent to vscode (at least on a daily usage) so I'm not sue about codding my own extension, I can give it a try though.

Deleting was just easier to make sure it would offer the "mock-debug choice" when you don't have a launch-config at all.

@weinand

This comment has been minimized.

Copy link
Member

weinand commented Jan 30, 2017

Yes, the Python debugger could provide its own ${command.extension.python-debug.getCommandline} (or even define a nice Variable ${command.AskProgramArguments}).
And they could allow a single string for the args argument so that they could use the variable directly.

@rozzzly

This comment has been minimized.

Copy link

rozzzly commented Feb 2, 2017

I've been following this thread, and was inspired to create an extension that helps prompt the user for a file to debug. It's a little rough around the edges currently, but I encourage you to check it out. Thanks for the point in the right direction, @weinand.

rozzzly-dev.vscode-prompt-debug

example

@weinand

This comment has been minimized.

Copy link
Member

weinand commented Apr 5, 2017

Closing, since the existence of the vscode-prompt-debug extension proves that dynamic attributes are possible.

@weinand weinand closed this Apr 5, 2017

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017

@weinand weinand reopened this Dec 6, 2018

@weinand weinand added this to the November 2018 milestone Dec 6, 2018

@weinand

This comment has been minimized.

Copy link
Member

weinand commented Dec 6, 2018

This feature will become available in the November release via #63987.

Example:

{
	"version": "0.2.0",
	"configurations": [
		{
			"type": "node",
			"request": "launch",
			"name": "Launch Program",
			"program": "${workspaceRoot}/${input:programName}",
		}
	],
	"inputs": [
		{
			"id": "programName",
			"type": "pickString",
			"default": "test.js",
			"description": "The program name"
		}
	]
}

@weinand weinand closed this Dec 6, 2018

@weinand weinand added the on-testplan label Dec 7, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.