Skip to content

Don't colorize nested tokens when the parent token has the CommandName TokenFlag #3994

Open
@MartinGC94

Description

@MartinGC94

Prerequisites

  • Write a descriptive title.

Description of the new feature/enhancement

The PowerShell parser adds nested tokens when parsing command names with variables/subexpressions but don't actually evaluate them unless there's an invocation operator before the command.
This seems to be an intentional choice as noted in the parser code here: https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/engine/parser/Parser.cs#L6352
The syntax highlighting in PSReadLine should make this fact clear to users by coloring the whole token as a command when there's no invocation operator.
You can see the current behavior here:
image

Proposed technical implementation details (optional)

When looping over the tokens, set a flag when an invocation operator is encountered and reset it whenever a non line continuation token is encountered. If a command token is encountered and the flag is set, scan the nested tokens, otherwise skip them and color the whole token with the command color.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-EnhancementIt's a feature request.Needs-Triage 🔍It's a new issue that core contributor team needs to triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions