Skip to content

Recent updates, OS and or VSCode breaks integrated scripting environment. #1187

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

Closed
postanote opened this issue Feb 4, 2018 · 5 comments
Closed

Comments

@postanote
Copy link

postanote commented Feb 4, 2018

The integrated scripting environment will not run any function block code.
This started as of the last few VScode and OS updates.
Complete uninstall, reinstalls done, multiple times, using ia32 and x64 versions after manual registry cleanup of all VScode, Visual Studio Code keys and data.

Sample quick function

function new-test ($name)
{
$name
}
new-test -name 'tester'

(Get-CimInstance -ClassName CIM_OperatingSystem).Caption
$Host
code -v
$pseditor.EditorServicesVersion
code --list-extensions --show-versions
$PSVersionTable


### Issue Description

PowerShell Integrated Console
                    (Get-CimInstance -ClassName CIM_OperatingSystem).Caption
Microsoft Windows 10 Pro
PS C:\Users\postanote> $Host


Name             : Visual Studio Code Host
Version          : 1.5.1
InstanceId       : 22c91ac4-8014-466f-afeb-fbd147dea1e2
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      :
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace



PS C:\Users\postanote> code -v
1.19.3
7c4205b5c6e52a53b81c69d2b2dc8a627abaa0ba
ia32
PS C:\Users\postanote> $pseditor.EditorServicesVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
1      5      1      0


PS C:\Users\postanote> code --list-extensions --show-versions
abusaidm.html-snippets@0.2.1
alefragnani.Bookmarks@0.18.1
alefragnani.project-manager@0.24.0
AndersEAndersen.html-class-suggestions@1.0.7
bitzl.vscode-puppet@0.4.5
Borke.puppet@0.3.2
bradgashler.htmltagwrap@0.0.7
capaj.vscode-exports-autocomplete@0.5.4
christian-kohler.path-intellisense@1.4.2
DavidAnson.vscode-markdownlint@0.13.0
dbaeumer.vscode-eslint@1.4.5
DotJoshJohnson.xml@1.9.2
DougFinke.vscode-PSStackoverflow@0.0.2
eamodio.gitlens@7.5.10
ecmel.vscode-html-css@0.2.0
formulahendry.code-runner@0.8.7
HookyQR.beautify@1.3.0
ms-mssql.mssql@1.3.0
ms-python.python@2018.1.0
ms-vscode.cpptools@0.14.6
ms-vscode.csharp@1.13.1
ms-vscode.PowerShell@1.5.1
msjsdiag.debugger-for-chrome@4.1.0
msjsdiag.debugger-for-edge@0.4.1
Pendrica.chef@0.6.4
pranaygp.vscode-css-peek@2.1.0
qinjia.view-in-browser@0.0.5
robertohuertasm.vscode-icons@7.19.0
sidthesloth.html5-boilerplate@1.0.1
tht13.python@0.2.3
Tyriar.theme-sapphire@0.2.1
waderyan.gitblame@2.2.0
PS C:\Users\postanote> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.16299.98
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.98
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Simple function shows these errors. 

PS C:\Users\postanote> function new-test ($name)
Missing function body in function declaration.
At line:0 char:0
PS C:\Users\postanote> {
Missing closing '}' in statement block or type definition.
At line:0 char:0
PS C:\Users\postanote>     $name
PS C:\Users\postanote> }
At line:1 char:1
+ }
+ ~
Unexpected token '}' in expression or statement.
PS C:\Users\postanote> new-test -name 'tester'
new-test : The term 'new-test' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:1
+ new-test -name 'tester'
+ ~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (new-test:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


### Attached Logs

Follow the instructions in the [README](https://github.com/PowerShell/vscode-powershell#reporting-problems)
about capturing and sending logs.
@wsmelton
Copy link

wsmelton commented Feb 4, 2018

Your example function runs fine on my machine under the PowerShell integrated terminal by selecting all the code and hitting F8:

image

The errors you show with unexpected token and such would tell you tried to paste that into the PowerShell Integrated terminal:

image

Which right now, does not work. I'm not sure if there is another issue on supporting this exact ability or not, it may be tied into the fact that multi-line support is limited in the extension's terminal.

@postanote
Copy link
Author

postanote commented Feb 4, 2018

Thanks for getting back and the comments. Yet, your assumptions are not valid.

This code was directly typed in not copy/paste. That is not something I do in VSCode, ever.

The code runs fine in the console host using F5/F8, just not in the integrated with F5/F8.
If I could post a video as proof, I 'd do that.
This code and all my other code runs as expected in the Windows PowerShell ISE.

I have been using Monad/PowerShell/ISE and VSCode since their release and even teach courses / workshops on the topics. Full disclosure: I've been teaching IT Pro/Dev courses since 2000 as an MCT and been in IT since the late 1970's. So, you know, not a newbie at this stuff. Not saying I know everything, but well, you know.

I have multiple machines in my labs all running PoSH/VSCode, and many are used for the Windows Insider programs and other testing, so are all pristine systems, no other extensions, other than the PowerShell one.

This is my main machine, daily dev/admin/class delivery workstation. On one of the recent VSCode updates, it continually prompted me to install git, which I do not use form this system. I finally decided to install it and from that day forward, F5/F8 on any code typed in, or opening an saved .ps1 with functions in it fail to run with F5/F8.

I have not changed this environment, added / removed any other software - tools, in more than a year.

This F5/F8 issue in the integrated environment, is a recent thing. All was working as designed as of December 2017. Sometime in Jan - today, something, from some update, OS or VScode, has broken this feature on this system. It's the only one I regularly keep updated with any update OS/VSCode that comes out and have more extensions on for daily work and workshops/classes I deliver.

This is beginning to look like I will need to flatten and rebuild this machine, Just to get VSCode back to normal, since despite all my rollback, uninstalls / reinstalls, registry cleans, etc. have not fixed it. A very ugly proposition, or just never try to run code in the VSCode integrated editor ever again or spin up a separate pristine VM, just to be able to use VSCode again. Another ugly proposition.

I am just trying to get all things back to normal and after a week, of troubleshooting this thing, I felt it prudent to report, not only for me but just in case others hit this wall.

@postanote
Copy link
Author

Update on troubleshooting...
F5/F8 only works when the entire function code is on one line.
Very strange.

PowerShell Integrated Console

When the same function sample is all on one line --- success

function new-test ($name){ $name }
new-test -name 'tester'

Results

PS C:\Users\postanote> function new-test ($name){ $name }
PS C:\Users\postanote> new-test -name 'tester'
tester

Moving the braced variable to a new line --- errors

function new-test ($name)
{ $name }
new-test -name 'tester'

PS C:\Users\postanote> function new-test ($name)
Missing function body in function declaration.
At line:0 char:0
PS C:\Users\postanote> { $name }
$name
PS C:\Users\postanote> new-test -name 'tester'
tester

Putting the variable on it's own line --- errors as before

function new-test ($name)
{
$name
}
new-test -name 'tester'

PS C:\Users\postanote> function new-test ($name)
Missing function body in function declaration.
At line:0 char:0
PS C:\Users\postanote> {
Missing closing '}' in statement block or type definition.
At line:0 char:0
PS C:\Users\postanote> $name
PS C:\Users\postanote> }
At line:1 char:1

  • }
  • ~
    Unexpected token '}' in expression or statement.
    PS C:\Users\postanote> new-test -name 'tester'
    tester

So, something about the integrated environment is corrupt. Argh!!!
It's obviously has to do with how it is reading the on screen file, when line formatted vs the all on one line thing.

function FunctionName ($OptionalParameters){'hello'}

PS C:\Users\postanote> function FunctionName ($OptionalParameters){'hello'}
PS C:\Users\postanote>

function FunctionName ($OptionalParameters)
{'hello'}

PS C:\Users\postanote> function FunctionName ($OptionalParameters)
Missing function body in function declaration.
At line:0 char:0
PS C:\Users\postanote> {'hello'}
'hello'

Just not sure what. 8^{

@postanote
Copy link
Author

Finally found the issue in an unexpected place while comparing one of my pristine VM's to my main daily machine. Looking at every default and user config one line at a time.

Root cause to this dilemma. --- *** Default Key bindings. *** updates!!!

In earlier versions of VSCode, there was not a default option to run PowerShell Selected text, like we could with the Windows PowerShell ISE. So, creative people suggest adding a key binding at the Workbench level.

https://blogs.technet.microsoft.com/heyscriptingguy/2016/12/07/make-visual-studio-code-more-like-the-integrated-scripting-environment/
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "f8", "command":"workbench.action.terminal.runSelectedText",
"when": "editorTextFocus && editorLangId == 'powershell'"
}
]

Which I called, 'Run selected Text in the Active Terminal' Which I did of course and all things hummed along as expected.

Well, in the wisdom of I guess someone on the PowerShell Dev team. Some enterprising person(s) added this ('let's make this VSCode ISE a bit more on par with the Windows PowerShell ISE') now to the default keybindings.
(obviously, I missed that little line entry in the readme file)

Well, that little optimization ended up, conflicting with my previous user key binding. So, now I had my user key binding as noted above and a new key binding for the same hotkey called 'Run Selection'. Greaaate!, just greaaate!

So, the VSC ISE was now confused. I guess trying to run both on F8. Now that still did not explain the F5 wonkiness, but whatever. So, deleted my custom F8 Keybinding, and all things appear to be back to normal from that perspective.

PowerShell Integrated Console

PS C:\Users\postanote> function new-tester ($name) {
$name
}
PS C:\Users\postanote> function new-tester ($name)
{
$name
}
PS C:\Users\postanote> function new-tester ($name)
{
$name
}
new-tester -name 'tester'
tester
PS C:\Users\postanote>

Wow, just Wow.

Moral of the story folks, is to make sure you read every line of the ReadMe on new releases as to not get bitten by customizations you had to do, before new features or modified features ensue.

Oh well, live and learn.

Still, odd that it would run correctly as long as all things were on one line. But oh well.

@zisom-stamps
Copy link

Thank you postanote, the issue showed up for my after installing and using Powershell 7. recently, Dr. Scripto's insight and your saved me from future frustration.

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label May 8, 2020
@TylerLeonhardt TylerLeonhardt removed the Needs: Maintainer Attention Maintainer attention needed! label May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants