Skip to content
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

launch-config should allow me reference any command #12735

Closed
jrieken opened this issue Sep 27, 2016 · 21 comments
Closed

launch-config should allow me reference any command #12735

jrieken opened this issue Sep 27, 2016 · 21 comments
Assignees
Labels
feature-request Request for new features or functionality verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@jrieken
Copy link
Member

jrieken commented Sep 27, 2016

I wanna write an extension that is a set of commands for asking for user input, like input text, make selection etc. Then I want to use commands from that extension in our launch.config - my ultimate goal is support mocha -g "test name" from within VS Code.

I have modified our launch.json so

        "args": [
                "--timeout",
                "999999",
                "-g",
                "${command.inputs.text}"
            ]

and an extension that contributes a inputs.text command and that activates on that command

// extension.js
vscode.commands.registerCommand('inputs.text', function () { ... });

// package.json
 "activationEvents": [
     "onCommand:inputs.text"
 ]

This doesn't work and it requires me to also define a debugger which I believe is unnecessary complicated.

@jrieken jrieken added the feature-request Request for new features or functionality label Sep 27, 2016
@isidorn
Copy link
Contributor

isidorn commented Sep 27, 2016

I agree that this step of defining variables inside debuggers feels like an extra step and we could just allow to run an arbitrary command. Doing this debug adapters would not have to specify interactive variables and other extensions could use this feature more easily - Joh's use case.

@weinand let us know what you think. I might be missing something here

@isidorn isidorn added this to the October 2016 milestone Sep 30, 2016
@weinand
Copy link
Contributor

weinand commented Oct 13, 2016

@isidorn yes, making commands directly available as variables makes sense and we should support this (and we should continue to support the 'variables' contribution).

What I don't like is the resulting syntax. If the command ID follows the common practice to use '.' as separators then using the 'command.' prefix makes things a bit unwieldy:

  "program": "${command.extension.node-debug.pickProcess}"

For this the 'variables' contribution helped because it allowed to introduce a short (but scoped) alias:

  "program": "${command.pickProcess}"

TL;DR:

The reasoning behind the intermediate 'variables' contribution point was twofold:

  • we wanted to decouple a dynamic variable (e.g. 'PickProcess') from its implementation (today a command is defined in an extension; in the future maybe it will become a builtin process picker).
  • we wanted to introduce a scope for a dynamic variable: the variable is only available in launch configurations of the debug type for which the variable is defined.

Today the first reason is no longer valid: since dynamic variables use the ${command.variable} syntax, the implementation detail 'command based' is already apparent when using a variable. So replacing a command based implementation by something builtin, would require a major stretch...

@daviwil
Copy link
Contributor

daviwil commented Oct 16, 2016

Related question: is it currently supported to use the command variable syntax in the 'args' or 'env' parameters of a launch configuration (at the top-level, not in the configurationAttributes)? I tried it yesterday and it didn't seem to work, the debug adapter got the argument but it was the command syntax string and not the resolved value.

This would be a huge benefit in my case as the alternative is to write a bunch of extra code in my TypeScript-based debug adapter bridge just to read the request that contains the properties defined in my launch config (since the command syntax seems to work there).

@weinand
Copy link
Contributor

weinand commented Oct 16, 2016

@daviwil variable substitution should work everywhere. If it doesn't it is a bug.

/cc @isidorn

@daviwil
Copy link
Contributor

daviwil commented Oct 16, 2016

That's great news. Here's what I've done so you can verify whether I've made a mistake somewhere or if it's a bug:

Registering and using the command variable in package.json:

        "debuggers": [
            {
                "type": "PowerShell",
                "enableBreakpointsFor": {
                    "languageIds": [
                        "powershell"
                    ]
                },
                "variables": {
                    "GetSessionPath": "PowerShell.GetSessionPath"
                },
                "program": "./out/debugAdapter.js",
                "args": [
                    "${command.GetSessionPath}"
                ],
                "runtime": "node",
                "configurationAttributes": {

Registering the command:

            vscode.commands.registerCommand('PowerShell.GetSessionPath', () => { return this.getDebugAdapterArgs() })

And here's what I see in the process.argv of my debug adapter:

C:\Program Files (x86)\Microsoft VS Code Insiders\Code - Insiders.exe,c:/dev/vscode-powershell/out/debugAdapter.js,${command.GetSessionPath}

@daviwil
Copy link
Contributor

daviwil commented Oct 16, 2016

Also, I never see my command get invoked when I start my debugger. I've got a breakpoint set in my extension code where I register the command and it never gets hit.

Strangely, I don't see the command get invoked even when I use it in a configuration attribute:

                "configurationAttributes": {
                    "launch": {
                        "required": [
                            "program"
                        ],
                        "properties": {
                            "debugAdapterArgs": {
                                "type": "string",
                                "description": "Arguments that are sent by the extension to the debug adapter.  Not a user setting.",
                                "default": "${command.GetSessionPath}"
                            },

@weinand
Copy link
Contributor

weinand commented Oct 16, 2016

@daviwil are you expecting variable substitution to take place in the package.json? That won't work. You can use variables in the configurationAttributes contribution but their substitution is delayed until the user starts the launch config.

@weinand
Copy link
Contributor

weinand commented Oct 16, 2016

@daviwil and make sure that the extension gets activated when the command is executed, so add all commands to the activationEvents section in your package.json like this:

    "activationEvents": [
        "onCommand:extension.pickNodeProcess",
        "onCommand:extension.node-debug.provideInitialConfigurations"
    ],

@weinand
Copy link
Contributor

weinand commented Oct 16, 2016

@daviwil and make sure that all those package.json contributions are only registered if you run your extension. Just editing package.json and then running the debug adapter isn't enough. You'll have to run (or better debug) the extension and from the new VS Code window you can start the launch config.

@daviwil
Copy link
Contributor

daviwil commented Oct 16, 2016

I'm expecting the variable substitution to happen for my debug adapter's args field when the user starts the PowerShell debugger. Does this mean that variable substitution doesn't happen outside of the configurationAttributes section for debugger contributions? I'm trying to avoid using configuration attributes for this because it will require me to read the content of messages coming from the debug client before I pass them on via TCP to my real debug adapter which runs in another process.

My extension is already activated at this point (but I am aware that I'll need the activation event in case the user somehow starts the debugger if it's not activated yet).

@daviwil
Copy link
Contributor

daviwil commented Oct 16, 2016

Yep, I am debugging my extension using a new instance of VS Code with --extensionDevelopmentPath set.

@weinand
Copy link
Contributor

weinand commented Oct 16, 2016

Variable substitution only takes place for all attribute values of a selected launch configuration when a new debug session is started.

I don't understand what you mean by "doesn't happen outside of the configurationAttributes section" since variable substitution does not even take place "inside" the configurationAttributes section.
Yes, you can use variables inside the "configurationAttributes" contribution but these variables are not substituted when the initial launch configuration is created. There are just literally copied.

Substitution occurs when the launch config is started.

@daviwil
Copy link
Contributor

daviwil commented Oct 16, 2016

Yes, I intend for this substitution to occur when the launch config starts, I'm not concerned with launch config creation time because I need the debug adapter's arguments to be populated using a command at the moment when the debugger gets launched.

Maybe it would help to say step-by-step what I expect to happen:

  1. User creates a launch config or has an existing launch config for the PowerShell debugger
  2. User starts the VS Code debugger with their PowerShell launch configuration
  3. VS Code uses the debugger contribution in the PowerShell extension to determine which program it should launch and resolves one of the adapter's command line arguments using an extension command
  4. VS Code launches the debug adapter process and passes the specified process arguments including the one that was resolved at launch time using an extension command
  5. The PowerShell debug adapter starts up, reads the command line arguments and uses them to configure itself before the debug client starts sending messages

I apologize for the lack of clarity in my questions, thanks a lot for helping me with this!

@weinand
Copy link
Contributor

weinand commented Oct 16, 2016

No variable substitution occurs in your step 3 because "the adapter's command line arguments" are not part of a launch config (and variable substitution only occurs for launch configs).

In your initial question I assumed that you were referring to the 'args' or 'env' parameters of a launch configuration (which are passed to the 'launch' request of the debug adapter). But actually you were asking about 'args' passed to the debug adapter itself (and 'env' is not even supported here).

We do not support variable substitution for arguments that are passed to the debug adapter (and we probably never will). But we are considering to open up the whole process of launching a debug adapter by moving it to the extension (optionally). With this you could write extension code that launches the debug adapter and can pass whatever arguments it needs.

@daviwil
Copy link
Contributor

daviwil commented Oct 16, 2016

Thanks for the clarification! I would love it if you allowed extension code to launch the debug adapter process, that would enable a few things I've been hoping to accomplish. For now I'll just find another way to do what I need to do.

@weinand
Copy link
Contributor

weinand commented Oct 16, 2016

@daviwil please see #13833

@isidorn
Copy link
Contributor

isidorn commented Nov 25, 2016

This is now supported, created microsoft/vscode-docs#689 to update the docs

@weinand
Copy link
Contributor

weinand commented Nov 25, 2016

I've created #16064 with a proposal for better command variable syntax.

@weinand weinand removed their assignment Dec 5, 2016
@isidorn isidorn added the verification-needed Verification of issue is requested label Dec 6, 2016
@weinand
Copy link
Contributor

weinand commented Dec 7, 2016

@isidorn since #16064 did not made it into the November milestone, I suggest that we do not announce this feature in the November release.

@weinand weinand added the verified Verification succeeded label Dec 8, 2016
@atian25
Copy link

atian25 commented Sep 14, 2017

@weinand I'm writing a extension to provide debug configurations.

as mentioned at docs "initialConfigurations": "extension.eggjs.provideInitialConfigurations"

my question is how to link a command to configurationSnippets?

had try "configurationSnippets": ["${command.extension.eggjs.provideConfigurationSnippets}"] and "configurationSnippets": ["extension.eggjs.provideConfigurationSnippets"] without luck.

the command is not trigger.

@atian25
Copy link

atian25 commented Sep 18, 2017

@weinand any suggest?

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

5 participants