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

vscode.debug.activeDebugSession is updated asynchronously #70125

Closed
hbenl opened this issue Mar 9, 2019 · 4 comments
Closed

vscode.debug.activeDebugSession is updated asynchronously #70125

hbenl opened this issue Mar 9, 2019 · 4 comments
Assignees
Labels
*as-designed Described behavior is as designed debug Debug viewlet, configurations, breakpoints, adapter issues

Comments

@hbenl
Copy link

hbenl commented Mar 9, 2019

  • VSCode Version: 1.32.1, 1.33.0-insider from 2019-03-08T06:57:33.004Z
  • OS Version: Arch Linux, Windows 10, MacOS

In 2 of my extensions, I start a debug session and then try to read vscode.debug.activeDebugSession, like this:

await vscode.debug.startDebugging(workspaceFolder, debugConfig);
const session = vscode.debug.activeDebugSession;

Starting with version 1.32.1, the session I get is undefined. However, I found a very simple workaround:

await vscode.debug.startDebugging(workspaceFolder, debugConfig);
await new Promise(resolve => setImmediate(resolve));
const session = vscode.debug.activeDebugSession;

So it seems that vscode.debug.activeDebugSession is updated asynchronously immediately after the promise from vscode.debug.startDebugging() is resolved.

I think that this is probably related to #69534, maybe the fix for that issue will also solve this one. I will check this as soon as there is an Insiders build containing that fix.

@hbenl
Copy link
Author

hbenl commented Mar 11, 2019

I just checked with the Insiders version from 2019-03-11T08:42:16.804Z and the bug is still there.

@weinand weinand added the debug Debug viewlet, configurations, breakpoints, adapter issues label Mar 11, 2019
@weinand
Copy link
Contributor

weinand commented Mar 12, 2019

This issue and #69534 are probably originating from the same change: some internal method has become asynchronous. This was breaking the vscode.debug.onDidStartDebugSession and we had to fix it.

But vscode.debug.activeDebugSession is not broken by this: you cannot assume that vscode.debug.activeDebugSession is updated immediately after you are calling startDebugging. Previously you might have been able to observe this, but there is no guarantee for this.

A better approach would be to register a vscode.debug.onDidChangeActiveDebugSession handler.
But be aware: the debug session that you receive via onDidChangeActiveDebugSession is not necessarily the one you've started with startDebugging.

A safe way to find the correct debug session is to pass a magic property to startDebugging and then listen on vscode.debug.onDidStartDebugSession and trying to find the magic property in the session's configuration...

@weinand weinand closed this as completed Mar 12, 2019
@weinand weinand added the *as-designed Described behavior is as designed label Mar 12, 2019
@hbenl
Copy link
Author

hbenl commented Mar 12, 2019

I am not assuming that vscode.debug.activeDebugSession is updated immediately after calling startDebugging. But since startDebugging returns a Promise one would assume that it is resolved after the asynchronous operation is finished, not before.
The way it is now, I find the API to be misleading. What's the point of returning a Promise if it doesn't signify anything useful? I think the Promise should either be removed or made to work as one would expect.
I know how to work around this, so it's not a big issue, but I'm sure others will be confuses by this as well.

@weinand
Copy link
Contributor

weinand commented Mar 12, 2019

startDebugging returns a promise that resolves to true when debugging could be successfully started. It does not say anything about the value of activeDebugSession.

The activeDebugSession is driven by the UI (and the users). It is asynchronous by nature and unrelated to startDebugging.

@vscodebot vscodebot bot locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*as-designed Described behavior is as designed debug Debug viewlet, configurations, breakpoints, adapter issues
Projects
None yet
Development

No branches or pull requests

2 participants