PSReadLine icon indicating copy to clipboard operation
PSReadLine copied to clipboard

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

Open MartinGC94 opened this issue 1 year ago • 0 comments

Prerequisites

  • [X] 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.

MartinGC94 avatar Apr 12 '24 23:04 MartinGC94