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

Allow debug launch configurations to be added dynamically #10861

Closed
DustinCampbell opened this issue Aug 23, 2016 · 18 comments
Closed

Allow debug launch configurations to be added dynamically #10861

DustinCampbell opened this issue Aug 23, 2016 · 18 comments
Assignees
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality
Milestone

Comments

@DustinCampbell
Copy link
Member

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.

@sandy081 sandy081 added the debug Debug viewlet, configurations, breakpoints, adapter issues label Aug 24, 2016
@weinand weinand added the feature-request Request for new features or functionality label Aug 24, 2016
@isidorn isidorn added this to the Backlog milestone Aug 26, 2016
@daviwil
Copy link
Contributor

daviwil commented Sep 16, 2016

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.

@DustinCampbell
Copy link
Member Author

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.

@isidorn
Copy link
Contributor

isidorn commented Sep 20, 2016

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!

@isidorn isidorn closed this as completed Sep 20, 2016
@DustinCampbell
Copy link
Member Author

@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.

@isidorn
Copy link
Contributor

isidorn commented Sep 20, 2016

@DustinCampbell thanks for claryfing -> reopening this

@isidorn
Copy link
Contributor

isidorn commented Sep 20, 2016

@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);
    });

@DustinCampbell
Copy link
Member Author

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.

@isidorn
Copy link
Contributor

isidorn commented Sep 20, 2016

  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

@isidorn isidorn reopened this Sep 20, 2016
@DustinCampbell
Copy link
Member Author

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

@isidorn
Copy link
Contributor

isidorn commented Sep 20, 2016

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

@daviwil
Copy link
Contributor

daviwil commented Sep 20, 2016

@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?

@DustinCampbell
Copy link
Member Author

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.

@isidorn
Copy link
Contributor

isidorn commented Sep 21, 2016

@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.
@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

@DustinCampbell
Copy link
Member Author

DustinCampbell commented Sep 22, 2016

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

@isidorn
Copy link
Contributor

isidorn commented Apr 13, 2017

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

@isidorn isidorn closed this as completed Apr 13, 2017
@DustinCampbell
Copy link
Member Author

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?

@isidorn
Copy link
Contributor

isidorn commented Apr 13, 2017

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

@DustinCampbell
Copy link
Member Author

Thanks, I'll take a look.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

5 participants