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

How vscode knows about the server port no of debug adapter when it itself starts debug adapter ? #54173

Closed
tarunbansal11 opened this issue Jul 12, 2018 · 6 comments
Assignees
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues *dev-question VS Code Extension Development Question

Comments

@tarunbansal11
Copy link

tarunbansal11 commented Jul 12, 2018

As I know, there are following two ways to run debug adapter. My confusion lies in the second way.

  1. Run debug server explicitly on some port no and specify this port no in launch.json as value of "debugServer" attribute. In this case vscode connects on this port no. Debug server is spawned as a separate process and the code to spawn it is written typically in extension.

  2. Debug adapter is started by vscode itself. Debug adapter's executable is mentioned in package.json as the value of "program" attribute under "debuggers" section.

Now my question is regarding second point. vscode is the client of Debug adapter (which is DAP server). vscode must know the port no of the server started within the debug adapter in order to connect to it and later send request.

Now suppose if my debug adapter is creating a server on port 9990, than how should I tell vscode to use 9990 as port no to connect to debug adapter which will be started by vscode itself.

@vscodebot
Copy link

vscodebot bot commented Jul 12, 2018

@weinand
Copy link
Contributor

weinand commented Jul 12, 2018

@tarunbansal11 in the second case VS Code talks to DA via stdin/stdout, it doesn't use a port.

See https://code.visualstudio.com/docs/extensions/example-debuggers

@weinand weinand added debug Debug viewlet, configurations, breakpoints, adapter issues *dev-question VS Code Extension Development Question labels Jul 12, 2018
@vscodebot
Copy link

vscodebot bot commented Jul 12, 2018

We have a great developer community over on slack where extension authors help each other. This is a great place for you to ask questions and find support.

Happy Coding!

@vscodebot vscodebot bot closed this as completed Jul 12, 2018
@tarunbansal11
Copy link
Author

Thanks @weinand.
So it means in the second case I can not use same executable for debug adapter which I use in first case. what changes I need to make in the code of debug adapter in second case than first case.

I saw the code of mock debugger extension. In the first case, debugger adapter is started with --server =4711 and we mention this port no (4711) in "debugServer" in launch.json.
In the second case, the same debugger adapter is used by VScode as mentioned in package.json as following -
"debuggers": [
{
"program": "./out/debugAdapter.js",
"runtime": "node",
}.................
...................
]

@weinand
Copy link
Contributor

weinand commented Jul 12, 2018

It is very simple to support both modes from the same DA executable.

For instance if you are basing your DA on the vscode-debugadapter node module, then the resulting DA supports both modes automatically: if the DA is launched without arguments then it communicates via stdin/stdout. If an argument --server=1234 is passed, it communicates via a socket.

The code from the vscode-debugadapter node module for both cases is here:
https://github.com/Microsoft/vscode-debugadapter-node/blob/7b97e42f1ed19777044850c5f18bfce8e21fc598/adapter/src/debugSession.ts#L348-L369

The socket mode is very helpful for debugging the DA: you can just run the DA as a server inside the debugger and VS Code will connect to it instead of always a launching a new instance of the DA.
See https://code.visualstudio.com/docs/extensions/example-debuggers#_development-setup-for-mock-debug.

@tarunbansal11
Copy link
Author

tarunbansal11 commented Jul 12, 2018

Now I see, thank you very much @weinand for your quick resolving my doubt.

One suggestion - It would be nice if this information (i.e. in the second case VS Code talks to DA via stdin/stdout, it doesn't use a port) is documented somewhere though there is a high probability that It is already documented and I missed it.

@vscodebot vscodebot bot locked and limited conversation to collaborators Aug 26, 2018
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 *dev-question VS Code Extension Development Question
Projects
None yet
Development

No branches or pull requests

2 participants