Discussion: VSCode Debug Experience Improvement
See original GitHub issueThe “wait-debugger” method seems fraught with issues and slows down the write/test loop, for instance if I place one and forget to take it out, suddenly my code will “freeze” in production (assuming it misses a code review or I’m just testing).
Due to BreakAll, I understand the need for it, but perhaps when the function host is running in “vscode debug mode”, an environment variable can be set to show this, so that the wait-debugger can be conditional? E.G.:
if ($AZFUNC_IS_POSHDEBUG) {wait-debugger}
Method 1: Launch Configuration modify local.settings.json
Unfortunately launch configurations still don’t support postLaunchTask, otherwise my workaround for this would be:
- prelaunch task to backup local.settings.json and then modify it to add the environment variable
- postlaunch task to restore the original local.settings.json
This is not a great method because something going wrong can potentially leave the debug local.settings.json in place, but there aren’t any other obvious “hooks” into the azure function host that can be defined at runtime that safely remove the item. However since local.settings.json doesn’t get published or saved in git by default with the azure functions templates, it’s a “safe” item to work with that won’t affect a production deployment.
Method 2: Language Worker Parameter
Could maybe a language worker parameter be added that would add the environment variable natively and add that to the task? For instance the launch task would be:
func host start --language-worker "-poshdebug"
and the powershell language worker if that parameter is specified sets the AZFUNC_IS_POSHDEBUG environment variable (or whatever). Then in my code I can add:
if ($AZFUNC_IS_POSHDEBUG) {wait-debugger}
And that way my code is the same in both debug and production. I personally would place this at the top of pretty much every function so when debugging it stops at the top of the script, and since VSCode breakpoints work from then on, I’d just click continue once and get to where I really wanted to be, without having to constantly “add debugger line, save, debug,remove debugger line,save,continue”
Just some thoughts unless there’s already a plan for GA. Thanks!
EDIT: The environment variable should be AZURE_FUNCTIONS_ENVIRONMENT since it already exists for this “purpose”
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (4 by maintainers)
Top GitHub Comments
Breakpoints now work in 2022.4.1-preview FINALLY! Thanks to @seeminglyscience for the work on this. Closing this issue unless I come across a significant enough regression.
https://github.com/PowerShell/vscode-powershell/releases/tag/untagged-0b17b3c1ec11c7dda14a
@JustinGrote Of course, as I mentioned in https://github.com/Azure/azure-functions-powershell-worker/issues/204#issuecomment-489368383, that PR is the first step toward the desired experience.