PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items/ms-vscode.PowerShell
MIT License
1.69k stars 481 forks source link

Cannot inspect variables or use debug commands in Azure Functions in terminal #3137

Closed yobyot closed 2 years ago

yobyot commented 3 years ago

Issue Description

Debugging an Azure Function using the PowerShell extension for VS Code.

Attached Logs

Follow the instructions in the README about capturing and sending logs.

Environment Information

Visual Studio Code

Name Version
Operating System Darwin x64 20.2.0
VSCode 1.52.1
PowerShell Extension Version 2020.6.0

PowerShell Information

Name Value
PSVersion 7.1.1
PSEdition Core
GitCommitId 7.1.1
OS Darwin 20.2.0 Darwin Kernel Version 20.2.0: Wed Dec 2 20:39:59 PST 2020, root:xnu-7195.60.75~1/RELEASE_X86_64
Platform Unix
PSCompatibleVersions 1.0 2.0 3.0 4.0 5.0 5.1.10032.0 6.0.0 6.1.0 6.2.0 7.0.0 7.1.1
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand) |Extension|Author|Version| |---|---|---| |aws-toolkit-vscode|amazonwebservices|1.18.0| |azure-account|ms-vscode|0.9.4| |azurerm-vscode-tools|msazurermtools|0.14.0| |gitlens|eamodio|11.1.3| |powershell|ms-vscode|2020.6.0| |vscode-azurefunctions|ms-azuretools|1.1.0| |vscode-dotnet-runtime|ms-dotnettools|1.0.0| |vscode-icons|vscode-icons-team|11.1.0| |vscode-logicapps|ms-azuretools|1.0.2|

Problem description

I hope the two attached animations make the point: I cannot debug an Azure Function in VS Code. As you can see, it's possible to do so in pwsh consoles. If there's a setting that enables a regular debugging session in VS Code, I can't find it so I am reporting this as a bug. I hope it's a user error (caused by pitiful doc) and not one of those "You just can't do it in VS Code" issues that seem to plague the PowerShell environment in VS Code.

Debugging in a pair of consoles (works):

2021-01-18_16-17-17 (1)

Debugging in VS Code (no input possible):

2021-01-18_15-57-26 (1)

SydneyhSmith commented 3 years ago

Thanks @yobyot it would be really helpful if you could also attach the logs--instructions for how to do that are here ! Thanks for providing the GIFs and description those are great!

yobyot commented 3 years ago

@SydneyhSmith

Hi. I've sent a .zip of the requested logs to vscode-powershell@microsoft.com.

yobyot commented 3 years ago

FWIW, here's a screenshot from a virgin Windows 10 machine, running pwsh 7.1.1, latest pwsh extension and Core Tools running the default Azure Functions HTTP project with a breakpoint set. This VM is in a client environment completely separate from the macOS environment from which I first reported this problem.

It's been, literally, years and years now that the PowerShell extension hasn't played nice with the VS Code debugger. I've reporting only a few of the issues I've experienced, all of which either were closed with pointed fingers elsewhere or were "wait for us to rearchitect." It makes one long for the ISE -- however limited it was, it was reliable. I just don't understand how PowerShell developers can be expected to depend on this extension, which is still labelled "preview" (and not to be confused with the "preview, preview" version of the extension).

2021-01-21_15-47-16

If I'm doing something wrong, I'd be happy to fix it -- providing it's documented. As it is, the paragraph or two on debugging a function in VS Code is embarrassingly thin.

SydneyhSmith commented 3 years ago

Thanks @yobyot for all the detailed information, we really appreciate it. Unfortunately, this will take more investigation on our part--thanks for your patience!

yobyot commented 3 years ago

Hello, pwshTeam.

Any update on this issue? A workaround? Anything?

It's so hard to write an Az Function using the command line debugger.

Thanks.

andyleejordan commented 3 years ago

Can you confirm it's not working in the same manner with the latest release? We switched to use the Debug Adapter Protocol in February. On that note, the debugger is actually getting rewired (again, but it's necessary) as part of https://github.com/PowerShell/PowerShellEditorServices/issues/1295

yobyot commented 3 years ago

Confirmed. Exactly the same problem.

andyleejordan commented 3 years ago

Dang, well, we're actively fixing some threading issues in https://github.com/PowerShell/PowerShellEditorServices/issues/1295 which will also change the underlying debugger implementation quite a bit, perhaps it'll be fixed then.

yobyot commented 3 years ago

Perhaps? Maybe? Possibly? That's not especially comforting -- especially when this Azure Functions PowerShell support is GA and debugging a function has never worked correctly. Isn't anyone at Microsoft embarrassed that one cannot accurately and conveniently debug PowerShell Azure Functions? (Even a local PowerShell script debug session isn't all that reliable, either.)

Sorry to be a pain but the agony inflicted on PowerShell developers by never really completely replacing the ISE has gone on too long.

andyleejordan commented 3 years ago

We're working on it!

yobyot commented 2 years ago

Hello, is this problem being worked on as part of https://github.com/PowerShell/vscode-powershell/projects/9?

andyleejordan commented 2 years ago

Yes @yobyot! And it's under review, @rjmholt has made excellent progress.

CallumCrowley commented 2 years ago

Is there an update on this?

andyleejordan commented 2 years ago

@CallumCrowley the previously mentioned work has been long since merged and we've been stabilizing it. Can you please test the PowerShell Preview for VS Code and let me know if this is resolved?

yobyot commented 2 years ago

Preview extension didn’t work for me.

andyleejordan commented 2 years ago

Oh, oh, I see you are trying to use attach to runspace. This is almost fixed! @SeeminglyScience has been hard at work on it and https://github.com/PowerShell/PowerShellEditorServices/pull/1752 is under review!

CallumCrowley commented 2 years ago

@andschwa great! I'll give it a go 😊

yobyot commented 2 years ago

Let's pause for a moment and remind ourselves that GA of Azure Functions support for PowerShell was announced in November of 2019.

In the nearly three year since, nobody AFAIK has ever been able to use VS Code to write and debug a Function. Since the ISE is long dead, in essence that means nobody has been able to write a Function in PowerShell suitable for production deployment.

Yes, I'm being critical of the PowerShell team here for their lack of understanding the requirements of production-quality code in their product and in the customers' environments. And, yes, they had every excuse in the book ready: we don't have people, this requires a re-write, and on and on.

As a PowerShell fan, this is a tragedy.

JustinGrote commented 2 years ago

@yobyot good news! The latest preview 2022.4.1 when it releases should have fixed this finally. It was a very difficult bug to remediate.

image

yobyot commented 2 years ago

Preview? What I care about is GA code. My client that does not permit public preview tools or resources.

JustinGrote commented 2 years ago

@yobyot this latest preview is a release candidate, it's expected to make it to stable in the next few weeks!

andyleejordan commented 2 years ago

Preview? What I care about is GA code. My client that does not permit public preview tools or resources.

@yobyot things take time! Please be patient, there was a ton that went into fixing this, and it is fixed now. Please test the preview extension (if you cannot do so for work, test it in another environment).

ghost commented 2 years ago

This issue has been marked as fixed. It has been automatically closed for housekeeping purposes.

CallumCrowley commented 2 years ago

@JustinGrote @andschwa thanks for your work on this! 😄

andyleejordan commented 2 years ago

It was @SeeminglyScience that fixed it!