EditorSyntax icon indicating copy to clipboard operation
EditorSyntax copied to clipboard

Hashtable BareWord key highlighting changes with presence of inline comment

Open liamjpeters opened this issue 5 months ago • 2 comments

Prerequisites

  • [x] I have written a descriptive issue title.
  • [x] I have searched all open and closed issues to ensure it has not already been reported.
  • [x] I have read the troubleshooting guide.
  • [x] I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • [x] 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

The syntax highlighting of a BareWord key that is followed by an inline comment in a Hashtable is different in a new unsaved editor vs when it is saved.

Before the file is saved:

Image

After the file is saved:

Image

Removing the inline comment (re-adding the inline comment goes back to how it is above):

Image

I would expect the keys to be consistently highlighted, regardless of a following inline comment or not.

I'm using the Default Dark Modern theme - in case that's relevant.

Edit: I noticed while filling in this issue template, that GitHub's syntax highlighting also does the same thing!

Image

The two key's are subtly different colours

PowerShell Version

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


Name             : Visual Studio Code Host
Version          : 2025.2.0
InstanceId       : 703b8fce-f163-4396-8543-54cfa0a5ba7c
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-GB
CurrentUICulture : en-GB
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Visual Studio Code Version

1.104.2
e3a5acfb517a443235981655413d566533107e92
x64

Extension Version

[email protected]

Steps to Reproduce

Open a new file and paste in:

@{
    Key1 <#Sneakycomment#> = "Value1"
    Key2 = "Value2"
}

Note the highlighting.

Save the file.

Note the highlighting changes.

Remove the inline comment.

Visuals

No response

Logs

No response

liamjpeters avatar Sep 29 '25 20:09 liamjpeters

Edit: I noticed while filling in this issue template, that GitHub's syntax highlighting also does the same thing!

This tells me that it's an issue with the TextMate grammar in the EditorSyntax repo, hence transferred.

andyleejordan avatar Oct 07 '25 20:10 andyleejordan

regex currently doesn't support comments https://github.com/PowerShell/EditorSyntax/blob/a08b55bf1146c210f58e844be53c2aa78fd5e610/PowerShellSyntax.tmLanguage#L1536

Image

RedCMD avatar Oct 08 '25 07:10 RedCMD