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

Consider to support a server mode for debug adapters #22080

Closed
weinand opened this issue Mar 6, 2017 · 10 comments
Closed

Consider to support a server mode for debug adapters #22080

weinand opened this issue Mar 6, 2017 · 10 comments
Assignees
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality
Milestone

Comments

@weinand
Copy link
Contributor

weinand commented Mar 6, 2017

Today VS Code starts a new debug adapter process for every debug session.

Only in "debug adapter development mode" we support to have a debug adapter running as a server and to have VS Code just connect to it for a debug session.

We should consider to make the "server mode" an official run option for debug adapters.

/cc @isidorn @daviwil

@weinand weinand self-assigned this Mar 6, 2017
@weinand weinand added debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality labels Mar 6, 2017
@daviwil
Copy link
Contributor

daviwil commented Mar 6, 2017

Oh, I didn't realize debugServer was only enabled in development mode. I'd definitely like to have this since the default path of the PowerShell extension will be for the debugging session to be shared with the current editing session. If the debug configuration can specify the TCP port to the long-running debug session (and have it modified by my startSessionCommand if needed), then I think this will be great!

@weinand weinand added this to the Backlog milestone Mar 6, 2017
@gorkem
Copy link

gorkem commented Mar 6, 2017

There are some limitations on server mode in its current form. 1) It has a fixed port number which will not allow two vscode instances to run the same debugger at the same time. 2) It does not allow an extension to run a prepare code for instance to find an available port or init debugger.

@weinand
Copy link
Contributor Author

weinand commented Mar 6, 2017

@daviwil no, debugServer works in production too. But it was only meant to be used in development mode.
(And if the statically assigned port is already in use, debugging will most likely fail).

@daviwil
Copy link
Contributor

daviwil commented Mar 6, 2017

debugServer defines a local TCP port of an already-running server, correct? When I intercept my extension's debug requests with a startSessionCommand handler, can I add debugServer to the configuration and send it to vscode.startDebug? That's all I would need.

@isidorn
Copy link
Contributor

isidorn commented Mar 6, 2017

@daviwil I think that would work. Try it out :)

@daviwil
Copy link
Contributor

daviwil commented Mar 6, 2017

Had been planning to, just didn't get around to it yet :) I'm finally at the point now with my extension where using debugServer makes sense, so I'll give it a shot soon and let you know.

@weinand weinand modified the milestones: April 2017, Backlog Mar 9, 2017
@weinand
Copy link
Contributor Author

weinand commented Mar 12, 2017

@gorkem the "fixed port" is configurable, so there is no problem running multiple instances of the same debugger.

@gorkem
Copy link

gorkem commented Mar 13, 2017

@weinand Is this a configuration per instance or per installation? Is it possible for a bit of code to be executed to calculate the next available port?

@weinand
Copy link
Contributor Author

weinand commented Mar 13, 2017

@gorkem You are in control of the configuration. So it can be anything you like.

I've just prototyped this for your case.

In your extension you can register a hook for the 'startSession' event, which is triggered when a new debug session is launched. In this hook you determine the port on which the java debug adapter listens (or you can even start the debug adapter there). Then you assign the port number to the debugServer attribute (if this is still undefined).

Here is the complete extension code that goes into the activate hook:

context.subscriptions.push(vscode.commands.registerCommand('extension.java.startSession', config => {
	if (!config.debugServer) {
		config.debugServer = 12345;	// determine debug port 
	}
	vscode.commands.executeCommand('vscode.startDebug', config);
});

In the package.json you need these contributions:

"activationEvents": [
	// ...
	"onCommand:extension.java.startSession"
	// ...
],
"contributes": {
	"debuggers": [
		{
			"type": "java",
			// ...
			"startSessionCommand": "extension.java.startSession"
			// ...
		}
	]
}

@daviwil so your suggestion works as expected by @isidorn

@weinand
Copy link
Contributor Author

weinand commented Mar 13, 2017

I do not see a need for anything else at the moment.

@weinand weinand closed this as completed Mar 13, 2017
@weinand weinand modified the milestones: March 2017, April 2017 Mar 13, 2017
@kieferrm kieferrm mentioned this issue Mar 13, 2017
58 tasks
@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

4 participants