Skip to content

Commit 97b82a0

Browse files
committed
Fix 'this-is' problem (cmdlets with unapproved verbs wrong highliting)
1 parent 9b1808c commit 97b82a0

File tree

3 files changed

+38
-15
lines changed

3 files changed

+38
-15
lines changed

Support/PowershellSyntax.tmLanguage

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@
232232
</dict>
233233
<dict>
234234
<key>match</key>
235-
<string>-([ci]?[lg][te]|eq|ne)</string>
235+
<string>(?&lt;!\w)-([ci]?[lg][te]|eq|ne)</string>
236236
<key>name</key>
237237
<string>keyword.operator.logical.powershell</string>
238238
</dict>
@@ -244,43 +244,43 @@
244244
</dict>
245245
<dict>
246246
<key>match</key>
247-
<string>(?&lt;!\w)((?i:begin|break|catch|class|continue|data|define|do|dynamicparam|else|elseif|end|exit|filter|finally|for|foreach(?!=-object)|from|if|in|inlinescript|parallel|param|process|return|switch|throw|trap|try|until|using|var|where(?!=-object)|while|workflow)|%|\?)(?!\w)</string>
247+
<string>(?&lt;!\w)((?i:begin|break|catch|class|continue|data|define|do|dynamicparam|else|elseif|end|exit|filter|finally|for|foreach(?!-object)|from|if|in|inlinescript|parallel|param|process|return|switch|throw|trap|try|until|using|var|where(?!=-object)|while|workflow)|%|\?)(?!\w)</string>
248248
<key>name</key>
249249
<string>keyword.control.powershell</string>
250250
</dict>
251251
<dict>
252252
<key>match</key>
253-
<string>-(?i:is(?:not)?|as)\b</string>
253+
<string>(?&lt;!\w)-(?i:is(?:not)?|as)\b</string>
254254
<key>name</key>
255255
<string>keyword.operator.comparison.powershell</string>
256256
</dict>
257257
<dict>
258258
<key>match</key>
259-
<string>-(?i:[ic]?(?:eq|ne|[gl][te]|(?:not)?(?:like|match|contains|in)|replace))(?!\p{L})</string>
259+
<string>(?&lt;!\w)-(?i:[ic]?(?:eq|ne|[gl][te]|(?:not)?(?:like|match|contains|in)|replace))(?!\p{L})</string>
260260
<key>name</key>
261261
<string>keyword.operator.comparison.powershell</string>
262262
</dict>
263263
<dict>
264264
<key>match</key>
265-
<string>-(?i:join|split)(?!\p{L})|!</string>
265+
<string>(?&lt;!\w)-(?i:join|split)(?!\p{L})|!</string>
266266
<key>name</key>
267267
<string>keyword.operator.unary.powershell</string>
268268
</dict>
269269
<dict>
270270
<key>match</key>
271-
<string>-(?i:and|or|not|xor)(?!\p{L})|!</string>
271+
<string>(?&lt;!\w)-(?i:and|or|not|xor)(?!\p{L})|!</string>
272272
<key>name</key>
273273
<string>keyword.operator.logical.powershell</string>
274274
</dict>
275275
<dict>
276276
<key>match</key>
277-
<string>-(?i:band|bor|bnot|bxor)(?!\p{L})</string>
277+
<string>(?&lt;!\w)-(?i:band|bor|bnot|bxor)(?!\p{L})</string>
278278
<key>name</key>
279279
<string>keyword.operator.bitwise.powershell</string>
280280
</dict>
281281
<dict>
282282
<key>match</key>
283-
<string>-(?i:f)(?!\p{L})</string>
283+
<string>(?&lt;!\w)-(?i:f)(?!\p{L})</string>
284284
<key>name</key>
285285
<string>keyword.operator.string-format.powershell</string>
286286
</dict>
@@ -387,12 +387,25 @@
387387
</dict>
388388
<key>commands</key>
389389
<dict>
390-
<key>comment</key>
391-
<string>Verb-Noun pattern:</string>
392-
<key>match</key>
393-
<string>(?:(\p{L}|\d|_|-|\\|\:)*\\)?\b(?i:Add|Approve|Assert|Backup|Block|Checkpoint|Clear|Close|Compare|Complete|Compress|Confirm|Connect|Convert|ConvertFrom|ConvertTo|Copy|Debug|Deny|Disable|Disconnect|Dismount|Edit|Enable|Enter|Exit|Expand|Export|Find|Format|Get|Grant|Group|Hide|Import|Initialize|Install|Invoke|Join|Limit|Lock|Measure|Merge|Mount|Move|New|Open|Optimize|Out|Ping|Pop|Protect|Publish|Push|Read|Receive|Redo|Register|Remove|Rename|Repair|Request|Reset|Resize|Resolve|Restart|Restore|Resume|Revoke|Save|Search|Select|Send|Set|Show|Skip|Split|Start|Step|Stop|Submit|Suspend|Switch|Sync|Test|Trace|Unblock|Undo|Uninstall|Unlock|Unprotect|Unpublish|Unregister|Update|Use|Wait|Watch|Write)\-.+?(?:\.(?:exe|cmd|bat|ps1))?\b</string>
394-
<key>name</key>
395-
<string>support.function.powershell</string>
390+
<key>patterns</key>
391+
<array>
392+
<dict>
393+
<key>comment</key>
394+
<string>Verb-Noun pattern:</string>
395+
<key>match</key>
396+
<string>(?:(\p{L}|\d|_|-|\\|\:)*\\)?\b(?i:Add|Approve|Assert|Backup|Block|Checkpoint|Clear|Close|Compare|Complete|Compress|Confirm|Connect|Convert|ConvertFrom|ConvertTo|Copy|Debug|Deny|Disable|Disconnect|Dismount|Edit|Enable|Enter|Exit|Expand|Export|Find|Format|Get|Grant|Group|Hide|Import|Initialize|Install|Invoke|Join|Limit|Lock|Measure|Merge|Mount|Move|New|Open|Optimize|Out|Ping|Pop|Protect|Publish|Push|Read|Receive|Redo|Register|Remove|Rename|Repair|Request|Reset|Resize|Resolve|Restart|Restore|Resume|Revoke|Save|Search|Select|Send|Set|Show|Skip|Split|Start|Step|Stop|Submit|Suspend|Switch|Sync|Test|Trace|Unblock|Undo|Uninstall|Unlock|Unprotect|Unpublish|Unregister|Update|Use|Wait|Watch|Write)\-.+?(?:\.(?:exe|cmd|bat|ps1))?\b</string>
397+
<key>name</key>
398+
<string>support.function.powershell</string>
399+
</dict>
400+
<dict>
401+
<key>comment</key>
402+
<string>Builtin cmdlets with reserved verbs</string>
403+
<key>match</key>
404+
<string>(?&lt;!\w)(?i:foreach-object)(?!\w)</string>
405+
<key>name</key>
406+
<string>support.function.powershell</string>
407+
</dict>
408+
</array>
396409
</dict>
397410
<key>commentEmbeddedDocs</key>
398411
<dict>

tests/pester/Syntax.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Describe "Syntax highlighting" {
6262
}
6363
}
6464
# TODO: These are bugs, make it 0
65-
$errorCounter | Should be @(0..4)
65+
$errorCounter | Should be @(0..2)
6666
}
6767

6868
It "produces same tokens for lower case" {

tests/samples/test-file.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,16 @@ $a -notmatch $b
328328
$x -like $c
329329
100 -and 0
330330

331+
# Negative: these are cmdlets with unapproved verbs
332+
# we should not highlight keywords in them
333+
Foo-Is
334+
Foo-Not
335+
Foo-Join
336+
Foo-Bxor
337+
Foo-f
338+
Foo-eq
339+
Foo-match
340+
331341
# Logical operators
332342
$a -ceq 4 -and $a -ine $d -or
333343
$c -is [Type]

0 commit comments

Comments
 (0)