Skip to content

Unsaved Script Errors Out If Last Line is Commented #3965

Closed
PowerShell/PowerShellEditorServices
#1804
@mjhelto

Description

@mjhelto

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

ms-vscode.powershell@2022.5.1

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

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions