Skip to content

Unsaved Script Errors Out If Last Line is Commented #3965

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
6 tasks done
mjhelto opened this issue May 10, 2022 · 3 comments · Fixed by PowerShell/PowerShellEditorServices#1804
Closed
6 tasks done
Assignees
Labels

Comments

@mjhelto
Copy link

mjhelto commented May 10, 2022

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

When attempting to run an unsaved PS script in the PowerShell Integrated Console, if you comment out the last line, and don't add an extra blank line after the commented one, the extension attempts to close the executed script by putting the closing bracket '}' on the same line as the comment, leading to a missing closing bracket in the code, which leads to a parser error.

After attempting to execute the unsaved code, if a comment is the last line of the script, you will receive, "Missing closing '}' in statement block or type definition." If you add a blank line at the end of the code, or don't comment out the last line, it works fine. I am unsure if this was an issue before the recent rework of the extension (great work on it, btw).

Obviously, this is not a severe bug. If this is a known, addressed, and/or intentionally left "bug," please disregard this issue and accept my apologies. I searched for, but may not have used the correct terminology, before posting.

PowerShell Version

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

Visual Studio Code Version

1.67.0
57fd6d0195bb9b9d1b49f6da5db789060795de47
x64

Extension Version

Steps to Reproduce

  1. Double click anywhere in the top workspace bar and select 'PowerShell' from the list of available languages (this is my way of getting a new file, but you may have an alternative way to do this).
  2. Write or copy/paste code to run.
  3. Comment the last line of the script.
  4. Attempt to run it.

Visuals

No response

Logs

Code as written

# To make powrshell beep
[console]::beep(500,525)
# Different way
# [System.Media.SystemSounds]::Beep.Play()
# [System.Media.SystemSounds]::Hand.Play()
# [System.Media.SystemSounds]::Asterisk.Play()
# [System.Media.SystemSounds]::Exclamation.Play()

Code executed by the console

The below shows the input from the code and the output. Notice the '}' on the commented line

> . { # To make powrshell beep
[console]::beep(500,525)
# Different way
# [System.Media.SystemSounds]::Beep.Play()
# [System.Media.SystemSounds]::Hand.Play()
# [System.Media.SystemSounds]::Asterisk.Play()
# [System.Media.SystemSounds]::Exclamation.Play() }
Missing closing '}' in statement block or type definition.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingEndCurlyBrace
@mjhelto mjhelto added the Issue-Bug A bug to squash. label May 10, 2022
@ghost ghost added the Needs: Triage Maintainer attention needed! label May 10, 2022
@andyleejordan
Copy link
Member

Ha! I see what happened here. Easy to fix, thanks for the bug report!

@andyleejordan
Copy link
Member

Hey, it was a doozy, but I got this covered with a regression test 😄

@mjhelto
Copy link
Author

mjhelto commented Jun 15, 2022

Hey, it was a doozy, but I got this covered with a regression test 😄

Thank you for the update! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants