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 487 forks source link

Not able to step through script after the latest update to VSCode #2144

Closed westerdaled closed 5 years ago

westerdaled commented 5 years ago

Issue Description

I work a lot with PowerShell in VSCode and it generally very stable. Today I upgraded VSCode to the latest release and this seems to have broken the PowerShell Preview Extension IMHO e.g. both "Step Over" & "Step Into" disabled No highlighting of current line. Help, I am back to using the ISE 😫 PowerShell extension log.txt

Attached Logs

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

Environment Information

Visual Studio Code

Name Version
Operating System Windows_NT x64 10.0.18362
VSCode 1.37.1
PowerShell Extension Version 2019.5.0

PowerShell Information

Name Value
PSVersion 5.1.18362.145
PSEdition Desktop
PSCompatibleVersions 1.0 2.0 3.0 4.0 5.0 5.1.18362.145
BuildVersion 10.0.18362.145
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand) |Extension|Author|Version| |---|---|---| |azure-account|ms-vscode|0.8.4| |bracket-pair-colorizer|CoenraadS|1.0.61| |code-spell-checker|streetsidesoftware|1.7.18| |csharp|ms-vscode|1.21.0| |debugger-for-chrome|msjsdiag|4.11.7| |githistory|donjayamanne|0.4.6| |gitlens|eamodio|9.9.3| |markdown-all-in-one|yzhang|2.4.2| |markdown-shortcuts|mdickin|0.11.0| |powershell-preview|ms-vscode|2019.5.0| |python|ms-python|2019.8.30787| |quicktype|quicktype|12.0.46| |rest-client|humao|0.22.0| |shell-launcher|Tyriar|0.3.0| |team|ms-vsts|1.149.2| |tslint|eg2|1.0.44| |vscode-apache|mrmlnc|1.2.0| |vscode-azurefunctions|ms-azuretools|0.18.0| |vscode-browser-preview|auchenberg|0.5.9| |vscode-docker|ms-azuretools|0.7.0| |vscode-edit-csv|janisdd|0.1.2| |vscode-guid|heaths|1.4.15| |vscode-icons|vscode-icons-team|9.2.0| |vscode-spfx-deploy-package|RencoreGmbH|1.1.0|
SydneyhSmith commented 5 years ago

@westerdaled sorry to hear that you are hitting crashes, and thanks for opening this issue and providing this info/logs---It would be really helpful if you could also attach diagnostic logging--instructions for how to do that are here

rjmholt commented 5 years ago

@westerdaled are there other indications the extension is working? Do you get completions? Does the Integrated Console work?

westerdaled commented 5 years ago

@rjmholt Yes the syntax completion works. Indeed most things but not the debugger Issue with debugger. I could debug this successfully in the IDE but in VSCode I never even see a breakpoint reached. very weird!

westerdaled commented 5 years ago

@SydneyhSmith Diagnostic level now set ( despite what is indicated in the logs). vscode-powershell.log PowerShell Log files

SydneyhSmith commented 5 years ago

@westerdaled thanks for providing that log...the one that would be most helpful in that folder is the EditorServices file (the whole folder is the best option)...if you could also provide a GIF or screenshots of the completions you are getting that would be awesome! Thanks!

westerdaled commented 5 years ago

@SydneyhSmith , I actually witnessed the debugger work today after starting the VScode in my project directory ( normally, I just start "Code" from the Windows 10 Start) . However, this was short lived so still have an issue. Looks to me that debugger just hangs after it gets used . issue2144_logs.zip VScode PowerShell Extension Code complete

Vscode-Powershell

SydneyhSmith commented 5 years ago

@westerdaled thanks for providing the GIF and logs, it would also be super helpful to know the debug configuration you have and any other PowerShell-related settings you have in VSCode

rjmholt commented 5 years ago

This seems to be the method experiencing an NRE, but it's not clear why and our logging (unusually) doesn't have a stack trace.

Reading through that method, there aren't any obvious places where an NRE would occur that I can see, so that implies that something has gone bad before that method is called.

You might be able to capture this NRE happening with procdump by running the extension, finding its process ID (easiest way is with $PID in the integrated terminal), from cmd running procdump -e 1 -f "NullReferenceException $PID. That will create a dump when that NRE occurs, which you can send to us at vscode-powershell@microsoft.com (the dump will be large, so you'll probably need to upload it somewhere and send a link).

It looks like we should also improve the logging on the debug adapter here. We're currently overhauling the extension, so some of that might come for free when we get to the debug adapter.

westerdaled commented 5 years ago

@SydneyhSmith

{
    "window.zoomLevel": 0,
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
    "powershell.developer.featureFlags": [ "PSReadLine" ],
    "git.autofetch": true,
    "markdown.extension.preview.autoShowPreviewToSide": true,
    "team.showWelcomeMessage": false,
    "workbench.colorTheme": "Monokai",
    "workbench.iconTheme": "vscode-icons",
    "vsicons.dontShowNewVersionMessage": true,
    "azureFunctions.enableSlots": true,
    "azureFunctions.projectLanguage": "PowerShell",
    "terminal.integrated.rendererType": "dom",
    "powershell.powerShellExePath": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
    "editor.fontSize": 12,
    "powershell.developer.editorServicesLogLevel": "Diagnostic"
}

My profile settings are

if ($env:TERM_PROGRAM -eq "vscode") {
    Set-PSReadLineKeyHandler -Chord 'Ctrl+w' -Function BackwardKillWord
    Set-PSReadLineKeyHandler -Chord 'Alt+D' -Function KillWord
    Set-PSReadLineKeyHandler -Chord 'Ctrl+@' -Function MenuComplete    
}
westerdaled commented 5 years ago

@rjmholt now done, please seem email . Incidentally the ISE seems to be locking/ going modal randomly , following the windows 10 update so my need for the VScode PowerShell support gets greater.

rjmholt commented 5 years ago

@westerdaled thanks so much for providing that! I had a lot of trouble trying to get symbols for that proc dump, so it looks like we should also add those to builds.

BUT I did get a line number: https://github.com/PowerShell/PowerShellEditorServices/blob/974bb1dfed3680dc8b4f8fc8841381520316599f/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs#L263-L264

It's not clear why anything there would be null, but it means we can stop a crash and put better logging in there at least.

rjmholt commented 5 years ago

Ah it actually seems this NRE is a red herring; it's occurring as a result of a disconnect request.

I'll do some more digging

westerdaled commented 5 years ago

@rjmholt I am glad we are getting close. I did look at the code: is this node or typescript?

rjmholt commented 5 years ago

It seems like VSCode is sending a disconnect here -- I'm guessing you're not doing anything to send that. Not sure why that would be, but we don't control the client for this and the server seems to be handling it correctly enough.

It feels like this is actually a VSCode bug, rather than one in the extension.

So I'd advise:

rjmholt commented 5 years ago

Ah didn't see your response there!

is this node or typescript?

C# actually. This repo is the client, which is TypeScript (transpiled to JS and running on node in VSCode), but it's more visible so easier to track issues here. The server is basically a gigantic and complicated PowerShell module written in C#.

westerdaled commented 5 years ago

Hmmmm I am running v1.371 so I am not sure how this will help. There must be others out there with the same issue.. Will look at your suggestions tomorrow.

westerdaled commented 5 years ago

@SydneyhSmith @rjmholt I have been doing some more testing on this issue and ..... I think my problem is due to typos in the script . Now these aren't being picked until I attempt to debug the script and then I see the issue. Thanks for your patience.

rjmholt commented 5 years ago

I just noticed the disconnect request you're receiving has "restart": true on it. I wonder if we handle that properly

TylerLeonhardt commented 5 years ago

I've got a fix for this out now.