diff --git a/assets/highlighting-tests/powershell.ps1 b/assets/highlighting-tests/powershell.ps1 index e2bb01f39c6..b95bbc47245 100644 --- a/assets/highlighting-tests/powershell.ps1 +++ b/assets/highlighting-tests/powershell.ps1 @@ -76,3 +76,8 @@ Write-Host "2 + 2 = $($array[0] + $array[1])" # Command substitution $pwdPath = $(Get-Location).Path Write-Host "Current directory: $pwdPath" + +# Commands and operators that begin with a keyword +Get-ChildItem | ForEach-Object { $_.Name } | Format-Table +Invoke-WebRequest -Uri "https://example.com" +if (42 -in $array) { Exit-PSSession } diff --git a/crates/lsh/definitions/powershell.lsh b/crates/lsh/definitions/powershell.lsh index cdcfb7e41a3..98081dc1fc3 100644 --- a/crates/lsh/definitions/powershell.lsh +++ b/crates/lsh/definitions/powershell.lsh @@ -49,6 +49,11 @@ pub fn powershell() { else if /"/ { yield string; break; } await input; } + } else if /[\w\d?:]+-[\w\d?:-]*/ { + // Commands like ForEach-Object or Invoke-WebRequest, which may begin with a keyword + yield method; + } else if /-[a-zA-Z]\w*/ { + // Operators and parameters like -in or -Path, which may contain a keyword } else if /(?i:begin|class|clean|data|define|dynamicparam|end|enum|filter|from|function|hidden|in|param|process|static|using|var)/ { if /\w+/ { yield other; @@ -75,8 +80,6 @@ pub fn powershell() { } } else if /[$@][\w\d?:]+/ { yield variable; - } else if /[\w\d?:]+-[\w\d?:-]*/ { - yield method; } else if /[\w\d?:]+/ { // Gobble any other tokens that should not be highlighted }