Will VS Code ever support the ability to execute top-level await operators in the debug console? Currently if you try to execute await
My hope is someday the new chrome dev tools functionality may be added to WebStorm. https://developers.google.com/web/updates/2017/08/devtools-release-notes#await
Steps to Reproduce:
async function testFunction() {
return new Promise((resolve) => {
resolve('test');
});
}
testFunction().then((res) => {
console.log(res);
});
Node-debug doesn't preprocess the user input in any way before sending it to node.js for evaluation.
So, what you are seeing is expected but I understand it would be nice if VS Code could wrap the expression automagically into a closure.
On the other hand this "magic" could result in strange bugs that are difficult to diagnose.
@roblourens ?
I believe this will come automatically with newer Chrome and Node versions. Will leave this open on myself to test and verify.
Chrome sends "(async () => {return (await Promise.resolve('hi'))})()", but the adapter needs to know that it's attached to an appropriate version of Node/Chrome.
So the Chrome DevTools front-end sends a special formatted expression for top-level operators @roblourens?
Right
Does the recently introduced experimental-repl-await in node v10 help with this?
Probably but it's not necessarily any easier than what I said before.
This issue is being closed to keep the number of issues in our inbox on a manageable level, we are closing issues that are not going to be addressed in the foreseeable future: We look at the number of votes the issue has received and the number of duplicate issues filed. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider.
If you wonder what we are up to, please see our roadmap and issue reporting guidelines.
Thanks for your understanding and happy coding!
This is actually a fairly easy vscode-chrome-debug-core feature request. I filed https://github.com/Microsoft/vscode-chrome-debug-core/issues/353
I would take a PR for this. The change will be entirely inside the debug adapter, see https://github.com/Microsoft/vscode-chrome-debug-core/issues/353 and https://github.com/Microsoft/vscode-node-debug2/blob/master/CONTRIBUTING.md
This appears to happen in the latest stable Chrome (77) and Node.js (12.11) versions.
await Promise.resolve('foo')
SyntaxError: await is only valid in async function
It appears that the Chrome console preprocesses expressions that contain await (if the results here have anything returned from this function), so unfortunately this does not look super trivial to do. I think it'd be appropriate for us to preprocess console input in the same way, as I imagine that most users will expect the debug console in VS Code to behave identically to the one in Chrome.
...waits patiently...
I noticed the below over at https://github.com/microsoft/vscode-js-debug

I tried it with https://github.com/request/request-promise-native but not sure how to resolve the promise:

@jcrben this happens because Chrome/V8 does not let us await if you're paused on a breakpoint. If you're not on a breakpoint and running normally, we can evaluate the given statement(s) and get the promise result back.
This is becoming more and more relevant. Deno (a TypeScript runtime) now supports top-level await.
I'll call this closed based on the fact that it's supported in https://github.com/microsoft/vscode-js-debug (as good as the runtime lets us) and that is the future of JS debugging
@roblourens @connor4312 is the plan to at some point be able to use this when paused at a breakpoint? That's where I see this as being the most useful.
You can follow this Chromium issue for that, Ben: https://bugs.chromium.org/p/chromium/issues/detail?id=833928
Most helpful comment
This appears to happen in the latest stable Chrome (77) and Node.js (12.11) versions.
It appears that the Chrome console preprocesses expressions that contain await (if the results here have anything returned from this function), so unfortunately this does not look super trivial to do. I think it'd be appropriate for us to preprocess console input in the same way, as I imagine that most users will expect the debug console in VS Code to behave identically to the one in Chrome.