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

Restart specific debugger using command #114467

Closed
DJ4ddi opened this issue Jan 16, 2021 · 12 comments
Closed

Restart specific debugger using command #114467

DJ4ddi opened this issue Jan 16, 2021 · 12 comments
Assignees
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues *question Issue represents a question, should be posted to StackOverflow (VS Code)

Comments

@DJ4ddi
Copy link

DJ4ddi commented Jan 16, 2021

Hi there.

A bit of background for the setup: I'm working with an Electron application, which requires two different debugging configurations - one for the main process, one for the renderer. I set up my launch.json so that the chrome attach automatically runs when the node launch is done starting (the same could also be achieved through a compound configuration).

But this setup has a major inconvenience: Whenever a task, extension or the user runs the "Debug: Restart" command, it restarts the configuration that is currently selected in the debugging widget (the one with the pause, continue and step buttons) or the "Debug Console" tab. By default, that's the main process launcher. Unfortunately, in 99% of cases the intended behavior is to restart the renderer, not the launcher, which means that the wrong debugger is restarted if the user doesn't pay attention to the currently selected one.

What I want to do is to configure a preferred debugger that will be restarted when the workbench.action.debug.restart command is invoked.

  • One possible solution would be to add a launch.json option for runtime priority so that the renderer can be selected, e.g. through a new presentation property (or by respecting the existing order option).
  • Another solution would be a parameter for the command, although I am not sure how that would interact with calling it from a task (using the ${command:<command>} syntax).

I am, of course, open for alternative solutions.

@ArturoDent
Copy link

Possibly this extension could help: Launch Debug and assign a keybinding to your renderer debug.

@weinand
Copy link
Contributor

weinand commented Jan 18, 2021

@DJ4ddi could you give Arturo's extension a try?

@weinand weinand added debug Debug viewlet, configurations, breakpoints, adapter issues info-needed Issue requires more information from poster labels Jan 18, 2021
@DJ4ddi
Copy link
Author

DJ4ddi commented Jan 18, 2021

Unfortunately the extension does not solve my issue. I like the approach (defining a command for a specific configuration), but the problem is that it always attempts to start the configuration. In my case, I need it to restart the active one. Attempting to do so using Launch Debug displays the following error: There is already a debug configuraton "testConfig" running.

@ArturoDent
Copy link

Good point, I'll look into stopping the matching debug session first before re-starting the same configuration. It looks doable.

@DJ4ddi
Copy link
Author

DJ4ddi commented Jan 18, 2021

Cool. Do keep in mind that stopping and starting is not the same as restarting for some debuggers (e.g. Debugger for Chrome, which is used for Electron, reloads the window on restart, but not on re-attach).

Edit: Opened and referenced issue on the Launch Configs repository. From looking into this, it does not seem like the VSCode API has access to the information needed to restart a debugging session (as neither the capability nor the restart function are exposed).

@DJ4ddi
Copy link
Author

DJ4ddi commented Jan 18, 2021

@weinand Looks like implementing this functionality in an extension would require an API to restart a DebugSession. I could imagine this being an option for debug.startDebugging or a separate function. Any chance of that happening?

@weinand
Copy link
Contributor

weinand commented Jan 18, 2021

Most built-in commands (like "Restart") have an ID ("workbench.action.debug.restart") and can be executed via the vscode.commands.executeCommand API.
You can find command IDs via the "Preferences > Keyboard Shortcuts" command.

@DJ4ddi
Copy link
Author

DJ4ddi commented Jan 18, 2021

The command you suggested restarts the currently selected debugging instance, which is not the desired behavior here and the reason why this ticket exists. There is no way to restart a different instance via commands or the API.

@weinand weinand added feature-request Request for new features or functionality and removed info-needed Issue requires more information from poster labels Jan 19, 2021
@weinand
Copy link
Contributor

weinand commented Jan 19, 2021

@isidorn any idea how to address this issue?
One solution would be a "Restart" command that does not work on the "active" session but takes the name (either via QuickPick or as a parameter when called through vscode.commands.executeCommand).

@isidorn
Copy link
Contributor

isidorn commented Jan 19, 2021

@weinand that sounds like a good approach and it might already work looking at the code here

@DJ4ddi you should be able to execute the workbench.action.debug.restart and pass the following object { sessiondId: YOUR_SESSION_ID }
Try passing it as the first argument, if that does not work, pass it as a second argument.

Let me know how it goes.

@DJ4ddi
Copy link
Author

DJ4ddi commented Jan 19, 2021

Great, that worked (second argument is the correct one).

Code sample for my use case:

var sessions = [];
function activate() {
  vscode.debug.onDidStartDebugSession(session => sessions.push(session.id));
  vscode.debug.onDidTerminateDebugSession(session => sessions = sessions.filter(sid => sid !== session.id));
  vscode.commands.registerCommand("workbench.action.debug.restartLatest",
    () => vscode.commands.executeCommand("workbench.action.debug.restart", "", { sessionId: sessions[sessions.length - 1] });
}

@ArturoDent this might interest you as well.

@DJ4ddi DJ4ddi closed this as completed Jan 19, 2021
@isidorn isidorn added *question Issue represents a question, should be posted to StackOverflow (VS Code) and removed feature-request Request for new features or functionality labels Jan 20, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Mar 5, 2021
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 *question Issue represents a question, should be posted to StackOverflow (VS Code)
Projects
None yet
Development

No branches or pull requests

5 participants
@DJ4ddi @weinand @isidorn @ArturoDent and others