vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

Version v2021.2.2 doesn't highlight the #Requires statements

Open vivere-dally opened this issue 4 years ago • 8 comments

Environment

  • Editor and Version (VS Code, Atom, Sublime): VSCode 1.53.2
  • Your primary theme: Dark+ (default dark)

Issue Description

I just opened some PowerShell scripts and the extension got updated. Right in front of my eyes, I had some #requires statements and they got their highlight stripped off.

Screenshots

image

Expected Behavior

image

The only Theme which still highlights those statements that I found is Night Owl. I have like 10 themes installed and went through all of them and the Night Owl is the only one.

Code Samples

# Az modules
#Requires -Module @{ ModuleName = 'Az.Accounts'; RequiredVersion = '1.9.5' }
#Requires -Module @{ ModuleName = 'Az.ApplicationInsights'; RequiredVersion = '1.1.0' }
#Requires -Module @{ ModuleName = 'Az.Compute'; RequiredVersion = '4.5.0' }
#Requires -Module @{ ModuleName = 'Az.Network'; RequiredVersion = '3.5.0' }
#Requires -Module @{ ModuleName = 'Az.Resources'; RequiredVersion = '2.5.1' }
#Requires -Module @{ ModuleName = 'Az.ServiceBus'; RequiredVersion = '1.4.1' }
#Requires -Module @{ ModuleName = 'Az.Storage'; RequiredVersion = '2.7.0' }
#Requires -Module @{ ModuleName = 'Az.Websites'; RequiredVersion = '1.11.0' }

vivere-dally avatar Feb 26 '21 06:02 vivere-dally

EditorSyntax is no longer used in VS Code when you have the PowerShell extension installed. It uses a feature called "Semantic Highlighting" that provides better accuracy overall. Unfortunately that doesn't handle #Requires yet.

@rjmholt @andschwa can you transfer this issue to vscode-powershell?

TylerLeonhardt avatar Feb 26 '21 17:02 TylerLeonhardt

EditorSyntax is no longer used in VS Code when you have the PowerShell extension installed.

Incorrect. Unless your theme is marked as supporting semantic highlighting, you will 100% use the EditorSyntax grammar highlighting. (this is what the OP is running in to) Secondly, anything the symantic highlighting doesn't handle directly, falls back to the EditorSyntax grammar highlighting.

Third, semantic highlighting was not intended to be a replacement for TextMate grammar's, but instead a supplement. TextMate is still going to handle things better and be more flexible. In the case of PowerShell, the symantic highlighter is almost useless, as everything can be determined by the TextMate grammar. I am not implying that the current EditorSyntax grammar handles everything, but that a TextMate grammar CAN handle everything PowerShell has to syntax, which so implemented.

My suggestion, STOP semantically highlighting comments, and let that fall back on the TextMate grammar.

Include in that Text Strings, as the semantic highlighting prevents the TextMate grammar from highlighting character escapes. (actually the sematic highlighting will fail on a text string (doublequote) if an intepolated variable appears, so it should just give up trying text strings in general.)

msftrncs avatar Mar 02 '21 01:03 msftrncs

Thanks everyone, we agree that we should mark comments so that they are not semantically highlighted, and fall back to the TextMate grammar

SydneyhSmith avatar Mar 02 '21 20:03 SydneyhSmith

There is also an issue where the methods are the same color as the variable which is calling the method. The code is very hard to read in general. I'm also using the Dark+ theme.

JeeBee14 avatar Mar 04 '21 03:03 JeeBee14

#3220

GreatTeacherBasshead avatar Mar 04 '21 08:03 GreatTeacherBasshead

As a workaround until semantic highlighting improves enough, you can disable it: https://github.com/PowerShell/vscode-powershell/issues/3221#issuecomment-790584315

andyleejordan avatar Mar 09 '21 22:03 andyleejordan

Other issue I've had with the semantic highlighting are $true / $false / $null / $Script: etc.

I feel like there should be a general catch all issue for highlighting at it's current state. I'd rather not spam issues with every semantic issue I find.

Cohors1316 avatar Mar 25 '21 23:03 Cohors1316

@Cohors1316 good suggestions we will use https://github.com/PowerShell/vscode-powershell/issues/3221

SydneyhSmith avatar Mar 30 '21 20:03 SydneyhSmith