Skip to content

Variables that are built-in constants are not highlighted, like $Error and $PSVersionTable #218

Closed

Description

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Steps to reproduce

Noticed that both VSCode and GitHub doesn't highlight some variables, like $Error and $PSVersionTable

This:

```powershell
#Requires -Version 5.1
<#
    .SYNOPSIS
        This is just to test code highlighting.
#>

# Input and expected output
[OutputType([System.Void])]
Param()

# Preference variables
$ErrorActionPreference = 'Stop'
$InformationPreference = 'Continue'

# User defined variable
$SomeVariable = [string] 'Text'

# Built-in constants
$Error
$PSHOME
$PSVersionTable

# Values
string without quotes
'string with quotes'
```

Looks like this on GitHub:

#Requires -Version 5.1
<#
    .SYNOPSIS
        This is just to test code highlighting.
#>

# Input and expected output
[OutputType([System.Void])]
Param()

# Preference variables
$ErrorActionPreference = 'Stop'
$InformationPreference = 'Continue'

# User defined variable
$SomeVariable = [string] 'Text'

# Built-in constants
$Error
$PSHOME
$PSVersionTable

# Values
string without quotes
'string with quotes'
image

And in VSCode:

Image

Expected behavior

Highlight.js demo https://highlightjs.org/demo does as I expect it to:

image

PowerShell ISE and the PowerShell terminal too:

image

Actual behavior

Steps to reproduce

Error details

No response

Environment data

PowerShell 7.4.1 x64 on Windows 11 23H2
VSCode 1.87.2, vscode-powershell v2024.0.0 and v2024.3.1-preview

Version

Latest?

Visuals

No response

Activity

  1. changed the title [-]Some variables are not highlighted, like `$Error` and `$PSVersionTable`[/-] [+]Variables that are built-in constants are not highlighted, like `$Error` and `$PSVersionTable`[/+] on Mar 17, 2024
  2. o-l-a-v commented on Mar 1, 2026

    @o-l-a-v
    ContributorAuthor

    Is the problem that the defined textmate scope does not have a theme selector?

    Image

    In https://github.com/microsoft/vscode/blob/main/extensions/powershell/syntaxes/powershell.tmLanguage.json I see:

    {
      "captures": {
        "0": { "name": "support.constant.variable.powershell" },
        "1": { "name": "punctuation.definition.variable.powershell" },
        "3": { "name": "variable.other.member.powershell" }
      },
      "comment": "These are the other built-in constants.",
      "match": "(\\$)(?i:(Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID))\\b"
    }

    Which results in textmate scopes support.constant.variable.powershell source.powershell, which says foreground No theme selector.

    So maybe it just uses wrong textmate scope?

  3. o-l-a-v commented on Mar 1, 2026

    @o-l-a-v
    ContributorAuthor

    Dracula theme have worked around this like so https://github.com/dracula/visual-studio-code/blob/main/src/dracula.yml:

      - name: Powershell constants mistakenly scoped to `support`, rather than `constant` (edge)
        scope:
        - support.constant
        settings:
          fontStyle: normal
          foreground: *PURPLE

    VSCode built in themes does not have it, like "Dark Modern":


    I think the fix should be to use a TextMate scope that is more common in VSCode themes.

    This was suggested to me by Gemini Fast and worked in my testing with VSCode + Dark Modern theme:

    • From support.constant.variable.powershell.
    • To variable.other.readwrite.constant.powershell.
    Image

    C# uses variable.other.readwrite.cs:

  4. andyleejordan commented on Apr 23, 2026

    @andyleejordan
    Member

    Did #223 resolve this?

  5. RedCMD commented on Apr 24, 2026

    @RedCMD

    yup

    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions