Skip to content

lsh: Fix PowerShell commands and operators matching keyword rules - #999

Closed
Jae Birdsall (jaeminbird) wants to merge 1 commit into
microsoft:mainfrom
jaeminbird:fix-powershell-cmdlet-highlighting
Closed

Jae Birdsall (jaeminbird) wants to merge 1 commit into
microsoft:mainfrom
jaeminbird:fix-powershell-cmdlet-highlighting

Conversation

@jaeminbird

Copy link
Copy Markdown

The keyword rules ran before the command rule, so cmdlets whose verb starts with a keyword were mis-highlighted: ForEach-Object showed ForEach as a keyword, and Format-Table, Invoke-WebRequest and Install-Module got no highlight at all. The in of -in was also highlighted as a keyword.

This matches Verb-Noun commands and -operator/-Parameter tokens before the keyword rules.

  • lsh render of the existing powershell.ps1 sample is byte-identical before and after.
  • Added the cases above to assets/highlighting-tests/powershell.ps1.
  • cargo test --workspace and clippy -D warnings pass.

Commands like ForEach-Object, Format-Table or Invoke-WebRequest were matched by the keyword rules before the command rule, so they were highlighted partially as a keyword or not at all. The same happened to the "in" of the -in operator. Match commands and -operators before keywords.
@jaeminbird

Copy link
Copy Markdown
Author

Rebased onto current main (b7f8322). Still reproduces there: lshc render of Get-Process | ForEach-Object { $_ } | Format-Table colors ForEach as a keyword and leaves Format-Table plain, and -in gets a keyword in; with this branch all three commands get the command color and -in stays plain. cargo test --workspace passes.

@jaeminbird
Jae Birdsall (jaeminbird) force-pushed the fix-powershell-cmdlet-highlighting branch from 60e0247 to 771554d Compare November 13, 2026 05:20
@jaeminbird

Copy link
Copy Markdown
Author

Closing this since it has been quiet for a while. Thanks for taking a look.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant