Skip to content

Allow debug launch configurations to be added dynamically #10861

Closed

Description

Today, when a C# .NET Core project is opened, the C# extension does a fair amount of work to generate a launch.json file (if none exists already) that matches the current settings in the project. However, if the user changes the launch configurations in their project it gets out-of-sync with launch.json. For C#, the duplication of launch configurations between launch.json and the project files adds a lot of complexity for the user. It might be a better experience for C# developers if the extension were able to provide debug launch configurations to VS Code dynamically when a project is opened or modified.

Activity

  1. added
    debug
    on Aug 24, 2016
  2. added
    feature-request
    on Aug 24, 2016
  3. daviwil commented on Sep 16, 2016

    @daviwil
    Contributor

    Another possibility (which would help greatly with the PowerShell extension) would be to provide a way specify a command or function to be called in the language extension which could dynamically generate the parameters to send as part of launch.json. My language server holds some connection details that are unique for each VS Code window with the PowerShell extension active (TCP port numbers, etc). It'd be nice if the language server could provide that information to the debugger to be passed to the debug adapter without having to manipulate launch.json.

    I was considering the option to update the launch.json directly for each session using the new configuration APIs but I'd feel a little bad having the user deal with edits to their checked-in launch.json file when they work in a repo shared with other develoeprs.

  4. DustinCampbell commented on Sep 16, 2016

    @DustinCampbell
    MemberAuthor

    From the C# extension's perspective it would be easier to provide the launch configurations that we know about unless the launch.json already exists. If the launch.json is present, we would assume that the user is defining their own configurations and not provide any.

    Our biggest concern in generating a launch.json is with user modifications. Today, we generate a launch.json for the user when we analyze their project for the first time. However, if the user changes their project, it's now up to them to keep the launch.json in sync. We could re-generate the launch.json, but we would want to detect whether the user has modified it first to avoid stomping on their changes.

  5. isidorn commented on Sep 20, 2016

    @isidorn

    As part of #9061 it is now possibly to modify the launch.json at any time through extension host code. Please try that out and let me know if something is missing for your scenarios - thanks!

  6. DustinCampbell commented on Sep 20, 2016

    @DustinCampbell
    MemberAuthor

    Isidor Nikolic (@isidorn), if I understand the work correctly, this means that extensions now have an easier way to modify the launch.json file. This will definitely simplify some of the code we already have in the C# extension to generate that file. However, this particular issue was about being able to provide launch configurations programmatically (i.e. without modifying the file).

    In our scenario, we already have all of the launch configuration information in the user's project files in a different format. Duplicating this information in a launch.json file and keeping it in sync when the user makes changes is a major headache. Unless I'm missing something, I don't think #9061 addresses our scenario.

  7. isidorn commented on Sep 20, 2016

    @isidorn

    Dustin Campbell (@DustinCampbell) thanks for claryfing -> reopening this

  8. isidorn commented on Sep 20, 2016

    @isidorn

    Dustin Campbell (@DustinCampbell) are you aware that it is possible to do this and does that help with your scenario? This way you are passing a custom launch configuration to be used instead of modifying the underlying launch.json

     let launchConfig = {
            "name": "Test",
            "type": "node",
            "request": "launch",
            "program": "${workspaceRoot}/test.js",
            "cwd": "${workspaceRoot}",
            "stopOnEntry": true
        };
    
        vscode.commands.executeCommand('vscode.startDebug', launchConfig).then(() => {
            vscode.window.showInformationMessage('OK!');
        }, err => {
            vscode.window.showInformationMessage('Error: ' + err.message);
        });
    
  9. DustinCampbell commented on Sep 20, 2016

    @DustinCampbell
    MemberAuthor

    I'm aware of that, but as I understand it, there are limitations:

    1. I don't think I can hook the existing F5 keyboard shortcut in an extension. That's really an assumption though and I'd be delighted to be wrong. 😄
    2. It doesn't provide the user with a way to pick a different configuration from the debug panel.
  10. isidorn commented on Sep 20, 2016

    @isidorn
    1. Your extension can get activated on event 'onDebug:type' where type is 'node', 'cpp'. This happens once the user hits F5
    2. vscode.commands.executeCommand('vscode.startDebug', 'myConfigName') should pick a configuration from the debug panel and start debugging that configuration
  11. DustinCampbell commented on Sep 20, 2016

    @DustinCampbell
    MemberAuthor

    'cpp'? Is that a typo? This is the C# extension I'm referring to.

  12. isidorn commented on Sep 20, 2016

    @isidorn

    You can put any type you want there, go, php, c# - whatever debug type your C# extension registers

  13. daviwil commented on Sep 20, 2016

    @daviwil
    Contributor

    Isidor Nikolic (@isidorn) hmmm, so if an extension registers for onDebug:language, does that override the normal behavior for F5? If so, what gets invoked inside of the extension's code to take its place?

  14. DustinCampbell commented on Sep 20, 2016

    @DustinCampbell
    MemberAuthor

    FWIW, this strikes me as a weird hoop to make extension authors jump through. Also, it's not clear to me how activating the extension on the onDebug:type event helps. I would expect that the C# extension would already be activated.

  15. isidorn commented on Sep 21, 2016

    @isidorn

    David Wilson (@daviwil) currently we only have limited support for this, an extension can be activiated onDebug:language. So it will not override the normal behavior of F5 but an extension can do additional things once it is activated. What you are looking for sounds to me like a new feature request.
    Dustin Campbell (@DustinCampbell) yes, this does not seem to help with your use case. I am not sure when you activate your c# extension, probably on first open of a c# file

  16. DustinCampbell commented on Sep 22, 2016

    @DustinCampbell
    MemberAuthor

    The is activated on a handful of events, but primarily onLanguage:csharp, which is defined as .cs and .csx files.

  17. isidorn commented on Apr 13, 2017

    @isidorn

    This is supported now by the startDebug action
    Example how the node debug is generating a configuration dynamically can be found here https://github.com/Microsoft/vscode-node-debug/blob/master/src/node/extension.ts#L364

  18. DustinCampbell commented on Apr 13, 2017

    @DustinCampbell
    MemberAuthor

    Yes, you said this before, but I'm still not sure how this solves our scenario. Our extension doesn't execute the startDebug command. The user is the one pressing F5. Perhaps I'm missing something, but it's not clear to me at what point we can introduce a custom launch configuration. Could you please clarify?

  19. isidorn commented on Apr 13, 2017

    @isidorn

    I am explaining it in this comment microsoft/vscode-go#745 (comment)

    Please note that this is startSessionCommandnot startDebug I made a typo in the previous comment, this is a new feature which we support for the last couple of milestone

    Also here https://github.com/Microsoft/vscode-docs/blob/master/release-notes/v1_9.md#debugger-extension-authoring

  20. DustinCampbell commented on Apr 13, 2017

    @DustinCampbell
    MemberAuthor

    Thanks, I'll take a look.

  21. locked and limited conversation to collaborators on Nov 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

debugfeature-request

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions