You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
else: The term 'else' is not recognized as a name of a cmdlet, function, script file, or executable program. #3087
I am experiencing a problem with...
else is not recognized as a name of a cmdlet, function, script file, or executable program when using the "Format Document" feature.
BOTH of these work when run from PowerShell ISE or running the code via a normal powershell console.
vscode for some reason does not like else being on a new line.
This behaviour is the same for Windows PowerShell 5.2 and PowerShell 7.1.0
I use Format Document for all my scripts and I've never run into this issue with 'else' previously so do not know if this is a new bug introduced recently??
I use Format Document for all my scripts and I've never run into this issue with 'else' previously so do not know if this is a new bug introduced recently??
There hasn't been a new release in several months, so unless you just upgraded it seems unlikely.
There is a known issue with formatting where it seems to race the extension's file system abstraction, discussed in #2569. I suspect this is the same issue -- which also explains why you might not have hit it before.
PART FIXED:
I had "powershell.integratedConsole.showOnStartup": false,
changed it to "powershell.integratedConsole.showOnStartup": true, and the issue is now resolved in the sense that it now works as long as the terminal is running the PS Integrated Console:
If I change the console to powershell it fails again:
That's because pressing F8 when dealing with "not the PowerShell Integrated Console" just throws the text in the editor into the terminal window.
With the "PowerShell Integrated Console", we do something differently (sending a message behind the scenes with the full script to make sure the full script gets run). We can do this because it's "Integrated".
I'm not sure what can really be done about this behavior unless PSReadLine supported Paste Bracketing: PowerShell/PSReadLine#1471
Reacted by Rob Holt, Guyver1wales, André Smit and Balázs Orbán
That's because pressing F8 when dealing with "not the PowerShell Integrated Console" just throws the text in the editor into the terminal window.
With the "PowerShell Integrated Console", we do something differently (sending a message behind the scenes with the full script to make sure the full script gets run). We can do this because it's "Integrated".
I'm not sure what can really be done about this behavior unless PSReadLine supported Paste Bracketing: PowerShell/PSReadLine#1471
Thanks for the clarification Tyler. At least I know going forward to use the integrated console and I now understand a bit better what it does in the background. 👍
Activity
rjmholt commentedon Dec 10, 2020
There hasn't been a new release in several months, so unless you just upgraded it seems unlikely.
There is a known issue with formatting where it seems to race the extension's file system abstraction, discussed in #2569. I suspect this is the same issue -- which also explains why you might not have hit it before.
rjmholt commentedon Dec 10, 2020
One remaining question -- the first script snippet you posted is valid and runs as I expect (PowerShell allows you to hang the
else):Are you seeing the parse error on that particular script?
Guyver1wales commentedon Dec 11, 2020
executing code snippet directly in vscode after Ctrl+A to select all and then F8:

rjmholt commentedon Dec 11, 2020
Can you report the output of
gmo PSReadLinein the integrated console?Guyver1wales commentedon Dec 11, 2020
dont have an integrated console??:
Guyver1wales commentedon Dec 11, 2020
So I uninstalled the PowerShell extension and reinstalled it and its now working as expected.

closed vscode and opened it again and the integrated terminal is gone and the issue returns
Guyver1wales commentedon Dec 11, 2020
this is my settings.json
{ "workbench.colorTheme": "Atom One Dark", "window.zoomLevel": 0, "files.trimTrailingWhitespace": true, "files.trimFinalNewlines": true, "files.autoSave": "off", "files.associations": { "*.ps1": "powershell" }, "files.defaultLanguage": "powershell", "editor.rulers": [ 115 ], "editor.mouseWheelZoom": true, "editor.minimap.enabled": false, "editor.renderWhitespace": "all", "editor.renderControlCharacters": true, "editor.wordWrap": "wordWrapColumn", "editor.formatOnType": true, "editor.formatOnPaste": true, "editor.tabSize": 4, "editor.minimap.maxColumn": 115, "editor.tabCompletion": "on", "editor.insertSpaces": false, "editor.detectIndentation": false, "editor.wordWrapColumn": 115, "terminal.integrated.fontFamily": "Consolas", "terminal.integrated.fontSize": 14, "terminal.integrated.lineHeight": 1, "terminal.integrated.rendererType": "dom", "emmet.triggerExpansionOnTab": true, "powershell.enableProfileLoading": true, "powershell.integratedConsole.focusConsoleOnExecute": true, "powershell.integratedConsole.showOnStartup": false, "powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationAfterEveryPipeline", "powershell.codeFormatting.autoCorrectAliases": true, "powershell.codeFormatting.useCorrectCasing": true, "editor.fontFamily": "Fira Code", "editor.fontSize": 16, "editor.codeActionsOnSave": null, "git.enableSmartCommit": true, "git.autofetch": true, "powershell.powerShellDefaultVersion": "Windows PowerShell (x64)" }Guyver1wales commentedon Dec 11, 2020
PART FIXED:

I had "powershell.integratedConsole.showOnStartup": false,
changed it to "powershell.integratedConsole.showOnStartup": true, and the issue is now resolved in the sense that it now works as long as the terminal is running the PS Integrated Console:
If I change the console to powershell it fails again:

TylerLeonhardt commentedon Dec 11, 2020
That's because pressing F8 when dealing with "not the PowerShell Integrated Console" just throws the text in the editor into the terminal window.
With the "PowerShell Integrated Console", we do something differently (sending a message behind the scenes with the full script to make sure the full script gets run). We can do this because it's "Integrated".
I'm not sure what can really be done about this behavior unless PSReadLine supported Paste Bracketing:
PowerShell/PSReadLine#1471
Guyver1wales commentedon Dec 11, 2020
Thanks for the clarification Tyler. At least I know going forward to use the integrated console and I now understand a bit better what it does in the background. 👍
TylerLeonhardt commentedon Dec 11, 2020
Be sure to give that PSReadLine issue a like :)
Guyver1wales commentedon Dec 11, 2020
done 👍