Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
MartinGC94 opened this issue Apr 12, 2024 · 0 comments
Open
1 task done
Labels
Issue-Enhancement It's a feature request. Needs-Triage 🔍 It's a new issue that core contributor team needs to triage.

Comments

@MartinGC94
Copy link

MartinGC94 commented Apr 12, 2024

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.

@MartinGC94 MartinGC94 added the Issue-Enhancement It's a feature request. label Apr 12, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement It's a feature request. Needs-Triage 🔍 It's a new issue that core contributor team needs to triage.
Projects
None yet
Development

No branches or pull requests

1 participant