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

Formatting no longer works #2543

Closed
motowilliams opened this issue Mar 9, 2020 · 37 comments · Fixed by PowerShell/PowerShellEditorServices#1262
Closed

Formatting no longer works #2543

motowilliams opened this issue Mar 9, 2020 · 37 comments · Fixed by PowerShell/PowerShellEditorServices#1262
Labels

Comments

@motowilliams
Copy link

motowilliams commented Mar 9, 2020

System Details

System Details Output

### VSCode version: 1.42.1 c47d83b293181d9be64f27ff093689e8e7aed054 x64

### VSCode extensions:
bencoleman.armview@0.3.3        
bibhasdn.unique-lines@1.0.0     
cssho.vscode-svgviewer@2.0.0    
eamodio.gitlens@10.2.1
EditorConfig.EditorConfig@0.14.4
GrapeCity.gc-excelviewer@2.1.34
humao.rest-client@0.23.2
JuliaBay.spellcheck@1.1.4
ms-azure-devops.azure-pipelines@1.165.1
ms-azuretools.vscode-azurefunctions@0.21.0
ms-dotnettools.csharp@1.21.13
ms-mssql.mssql@1.9.0
ms-vscode-remote.remote-wsl@0.42.3
ms-vscode.azure-account@0.8.8
ms-vscode.powershell@2020.3.0
ms-vsts.team@1.161.0
Zignd.html-css-class-completion@1.19.0


### PSES version: 2.0.0.0

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Description

Latest version of extension no longer formats scripts

Expected Behaviour

It should format the script like it has forever.

Actual Behaviour

Nothing happens

Attached Logs

Follow the instructions in the troubleshooting docs
about capturing and sending logs.
1583792484-d9b584fd-a4f6-4b7e-9d35-4bec4545762c1583792481203.zip

Copy-ReleaseVariablesToVariableGroup.zip

@ghost ghost added the Needs: Triage Maintainer attention needed! label Mar 9, 2020
@rjmholt
Copy link
Contributor

rjmholt commented Mar 9, 2020

Hi @motowilliams, can you please attach your logs as described in the last link in your issue description?

@TylerLeonhardt
Copy link
Member

Also your script that wasn't formatted correctly would also be hugely helpful.

@TylerLeonhardt TylerLeonhardt added Needs-Repro-Info and removed Needs: Triage Maintainer attention needed! labels Mar 9, 2020
@ghost
Copy link

ghost commented Mar 11, 2020

apologies if the format is incorrect.
i wanted to comment on this issue instead of starting a new issue

System Details
PowerShell Details
PowerShell version: 5.1.14409.1018
Language mode: FullLanguage

Environment Details
OS description: Microsoft Windows 6.3.9600
OS architecture: X64
Process bitness: 64

.code -v
1.42.1 c47d83b293181d9be64f27ff093689e8e7aed054 x64

.code --list-extensions --show-versions
aws-scripting-guy.cform@0.0.24
bmewburn.vscode-intelephense-client@1.3.11
DotJoshJohnson.xml@2.5.0
esbenp.prettier-vscode@3.20.0
felixfbecker.php-debug@1.13.0
felixfbecker.php-intellisense@2.3.14
formulahendry.code-runner@0.9.17
lonefy.vscode-JS-CSS-HTML-formatter@0.2.3
ms-azuretools.vscode-azurefunctions@0.21.0
ms-dotnettools.csharp@1.21.13
ms-mssql.mssql@1.9.0
ms-vscode.azure-account@0.8.8
ms-vscode.powershell@2020.3.0
mtxr.sqltools@0.21.6
qcz.text-power-tools@1.11.1
redhat.vscode-yaml@0.7.2
tht13.html-preview-vscode@0.2.5

.$psEditor.EditorServicesVersion
2 0 0 0

.$PSVersionTable
PSVersion 5.1.14409.1018
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14409.1018
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Issue Description
same as @motowilliams
Latest version of extension no longer formats scripts

Expected Behaviour
same as @motowilliams
It should format the script like it has forever.

Actual Behaviour
same as @motowilliams
Nothing happens

Attached Logs
1583915615-503d9cd1-21e3-4b1a-8553-4faf1ab3e9181583915105557.zip

any .ps1 file will do, here's one example;
Get-Assemblies.zip

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Mar 11, 2020
@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Mar 11, 2020

Aha - @elrod-johnson yours has something very interesting... a stack trace!

2020-03-11 01:50:40.251 -07:00 [FTL] Failed to handle notification textDocument/formatting
System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.PowerShell.EditorServices.Handlers.DocumentFormattingHandler.<Handle>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at OmniSharp.Extensions.LanguageServer.Server.Pipelines.ResolveCommandPipeline`2.<Handle>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MediatR.Pipeline.RequestPostProcessorBehavior`2.<Handle>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MediatR.Pipeline.RequestPreProcessorBehavior`2.<Handle>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at OmniSharp.Extensions.JsonRpc.RequestRouterBase`1.<RouteRequest>d__6.MoveNext()

I'm very suspicious of the exclamation marks in the path... I need to do more testing.

2020-03-11 01:33:56.393 -07:00 [DBG] Resolved path: e:\__FVHS\!!!!!__Azure_AD_etc\_Powershell\Intune_Graph_Samples/RBAC/RBAC_ScopeTags_PolicyUnAssign.ps1

@motowilliams logs didn't have anything useful, I'm afraid. Can you turn on Diagnostic logging and try again?

"powershell.developer.editorServicesLogLevel": "Diagnostic"

My guess is that you both are having the same issue though.

@ghost
Copy link

ghost commented Mar 12, 2020

i just tried formatting this file and saw the same response. i.e., no formatting.
E:__FVHS\LDAP_Users_CN.ps1
do you want to see the logs for that?

my powershell files have always been in e:\__FVHS\!!!!!\__Azure_AD_etc\_Powershell\ and they have formatted correctly prior to this latest update.

@rjmholt
Copy link
Contributor

rjmholt commented Mar 12, 2020

i just tried formatting this file and saw the same response. i.e., no formatting.
E:__FVHS\LDAP_Users_CN.ps1

Ok, that's useful information

@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Mar 12, 2020

@elrod-johnson yes your logs now would be helpful!

We'll be pushing an update to the preview version of the extension (next week likely) that has some more logging so we can better diagnose this issue.

@SydneyhSmith SydneyhSmith removed the Needs: Maintainer Attention Maintainer attention needed! label Mar 12, 2020
@rjmholt
Copy link
Contributor

rjmholt commented Mar 12, 2020

psvsix.zip

@motowilliams @elrod-johnson can you install this VSIX with the following steps:

  • Expand archive to get the VSIX
  • code --install-extension ./PowerShell-insiders.vsix
  • Disable the PowerShell extension in VSCode and ensure the PowerShell Preview extension is now installed
  • Restart VSCode

I've added some logging here to give us a better idea of the specific issue that's occurring

@TylerLeonhardt
Copy link
Member

Can you all give the PowerShell Preview extension a try? We just did a release of it.

Don't forget to disable the regular PowerShell extension for VS Code when you enable the PowerShell Preview extension for VS Code

@ghost
Copy link

ghost commented Mar 13, 2020

logs running ms-vscode.powershell-preview@2020.3.0

.code --list-extensions --show-versions
aws-scripting-guy.cform@0.0.24
bmewburn.vscode-intelephense-client@1.3.11
DotJoshJohnson.xml@2.5.0
esbenp.prettier-vscode@3.20.0
felixfbecker.php-debug@1.13.0
felixfbecker.php-intellisense@2.3.14
formulahendry.code-runner@0.9.17
lonefy.vscode-JS-CSS-HTML-formatter@0.2.3
ms-azuretools.vscode-azurefunctions@0.21.0
ms-dotnettools.csharp@1.21.14
ms-mssql.mssql@1.9.0
ms-vscode.azure-account@0.8.8
ms-vscode.powershell@2020.3.0 << disabled
ms-vscode.powershell-preview@2020.3.0
mtxr.sqltools@0.21.6
qcz.text-power-tools@1.11.1
redhat.vscode-yaml@0.7.2
tht13.html-preview-vscode@0.2.5

a number of format attempts on several files, none succeeded
1584096315-e492a07e-5241-484f-973f-59e365b09ea61584096313716.zip

thanks for working on it.
great extension, especially when formatting works!

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Mar 13, 2020
@rjmholt
Copy link
Contributor

rjmholt commented Mar 13, 2020

@elrod-johnson can you try running the steps in #2543 (comment) as well.

I put together the extension in that comment to log the formatting issue better so that we might be able to trace the null-ref exception

@TylerLeonhardt TylerLeonhardt removed the Needs: Maintainer Attention Maintainer attention needed! label Mar 13, 2020
@ghost
Copy link

ghost commented Mar 14, 2020

here you go Tyler
let me know if you need anything else.
1584186319-1a75101c-90f0-4d66-8dc0-e8b4e0fa578f1584186150151.zip

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Mar 14, 2020
@SydneyhSmith
Copy link
Collaborator

SydneyhSmith commented Mar 17, 2020

@elrod-johnson were you also able try running the steps in #2543 (comment)?
Thanks for the additional logs as well!

@SydneyhSmith SydneyhSmith removed the Needs: Maintainer Attention Maintainer attention needed! label Mar 17, 2020
@ghost
Copy link

ghost commented Mar 18, 2020

@SydneyhSmith
I tried to do those steps.
are you seeing that i didn't do them?
here's a new log after i tried to do them again.
here's what i did:

  1. disabled PowerShell Preview since it was already installed,
  2. ran code --install-extension ./PowerShell-insiders.vsix
  3. it installed successfully
  4. reenabled PowerShell Preview
  5. closed and reopened vscode
  6. tried to format a ps1

regular Powershell ext was disabled for all of this
thanks

1584522859-b2c730ed-d03a-437d-a7f1-7d9e01abf0c11584522856881.zip

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Mar 18, 2020
@SydneyhSmith
Copy link
Collaborator

Thanks @elrod-johnson! Unfortunately we still don't have enough information to determine an exact cause but it looks to be a race condition issue on the surface. We will have to do more investigation here, thanks again for all the info you have provided, we will update you when we have more steps to try!

@SydneyhSmith SydneyhSmith added Area-Code Formatting Issue-Bug A bug to squash. and removed Needs: Maintainer Attention Maintainer attention needed! labels Mar 24, 2020
@ghost
Copy link

ghost commented Apr 10, 2020

sorry, i was groggy this morning. here ya go.

1586485494-93ca9de9-3e8e-454f-a4a2-1d9eb8d5cd511586443543789.zip

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Apr 10, 2020
@TylerLeonhardt
Copy link
Member

@elrod-johnson still not seeing the crash anymore... Can you elaborate on what you're seeing (or not seeing) when you run Format in VS Code?

@TylerLeonhardt TylerLeonhardt removed the Needs: Maintainer Attention Maintainer attention needed! label Apr 10, 2020
@ghost
Copy link

ghost commented Apr 10, 2020

i tried to start over from scratch with the extension.
please read the readme file for details.

vscode.powershell-preview_README.txt

1586509074-407a2197-18d8-4b06-a23b-bc3dac17cd971586509071629.zip

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Apr 10, 2020
@TylerLeonhardt
Copy link
Member

@elrod-johnson from the logs you've sent me, it doesn't show that you ran the Formatter.

Can you run it a few times in VS Code and attach those logs?

Another thing, can you also try selecting all the text in your file and run the "Format Selection" command in VS Code? I'm curious if that behaves differently.

Before you do this make sure you're still using the build I gave you. You can see the version number in the Extension pane.

@TylerLeonhardt
Copy link
Member

Once again thank you for going through this with me 😅 there was another person who opened a similar issue so I'm hoping they'll come over here to help as a tester for me as well

@TylerLeonhardt TylerLeonhardt removed the Needs: Maintainer Attention Maintainer attention needed! label Apr 10, 2020
@ghost
Copy link

ghost commented Apr 11, 2020

i disabled extension auto-update after installing ms-vscode.powershell-preview-2020.4.0-CI.49627.
that might have been causing log problems.
i clicked 'format document', then ctrl-a, 'format selection' for the files in this log.

1586603996-5f580f96-8801-43e7-a8ac-b8629678e0601586603598431.zip

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Apr 11, 2020
@TylerLeonhardt
Copy link
Member

Ha! Today I learned that the text editor I use on my phone to open your logs cut out the content about half way 😅now on my laptop, I can see the crash perfectly.

@TylerLeonhardt
Copy link
Member

It looks like I was also groggy when I gave you that last build to try as I forgot to push my changes for more logging when I snapped a dev build to give you... 🤦‍♂️

This build has the logging in it:
psvsix.zip

Thanks for your patience, @elrod-johnson

@TylerLeonhardt TylerLeonhardt removed the Needs: Maintainer Attention Maintainer attention needed! label Apr 11, 2020
@ghost
Copy link

ghost commented Apr 12, 2020

this log is using ms-vscode.powershell-preview-2020.4.2-CI.49933

1586682518-cdf71ef4-4bb7-4057-8aad-e422c88775921586682515734.zip

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Apr 12, 2020
@TylerLeonhardt
Copy link
Member

Ok @elrod-johnson nothing useful in that... how about this one? I've basically added line-by-line logging (nothing sensitive just a bunch of null checks).

psvsix.zip

Keep in mind, the vsix's name is now:

powershell-preview-2020.4.3-CI.50071-Windows.vsix 

@TylerLeonhardt TylerLeonhardt removed the Needs: Maintainer Attention Maintainer attention needed! label Apr 15, 2020
@ghost
Copy link

ghost commented Apr 16, 2020

attached the two scripts i tried to format.
ran format document and format selection for each.

1587017167-4fd38891-1e6a-4d96-b2c2-43c721cc30991587017164072.zip

__powershell-preview.zip

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Apr 16, 2020
@TylerLeonhardt
Copy link
Member

@elrod-johnson that put the pieces all together for me...

here's what was happening... you had this setting:

"powershell.scriptAnalysis.enable": false,

this disables PSScriptAnalyzer capabilities in the extension including:

  • "Problems" in your open editor file
  • Formatting

Since that was off, formatting wasn't working.

With that said, I don't see why this needs to be the case. You should be able to run the formatter and have "Problems" turned off.

I think I have an idea for a fix and will report back.

@TylerLeonhardt
Copy link
Member

@elrod-johnson I think this build might just fix your problem 😄 please let me know!

psvsix.zip

@ghost
Copy link

ghost commented Apr 17, 2020

sure looks fixed to me guys!
i hammered on it as much as i could and it does everything the pre-update version did.

thanks a lot for staying on this for so long.
it sure makes my job a lot easier.
i have a hard time reading my own code when it's not formatted consistently.
i spend almost all my time writing posh code these days and it's been very frustrating.
i really appreciate your work.

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Apr 17, 2020
@TylerLeonhardt
Copy link
Member

Glad to hear @elrod-johnson ! This will probably be in the PowerShell Preview extension next week so you'll be able to update to that then. My guess is that this well make it into Stable probably in a few weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants