Add support for all token types with the new semantic highlighting
See original GitHub issueSummary of the new feature
Powershell has 20 tokentypes and it would be nice if the semantic highlighting supported all of them. See: https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.pstokentype
The current semantic highlighting implementation is currently missing the following types:
- Attribute
- CommandArgument
- GroupEnd/GroupStart
- LineContinuation (backtick)
- LoopLabel
- StatementSeparator (Semicolon)
If/When these gets added I would suggest changing the following mappings:
- Value in
Using namespace <Value>
should use CommandArgument scope. Currently it uses Function. - Attributes like
[cmdletbinding()]
should use Attribute scope. Currently it uses Type. - Names in functions and configurations should use CommandArgument scope. Currently they use the Function scope except functions with no dashes which has no semantic token type.
- Unquoted parameter values like “C:\SomePath” in
Get-ChildItem C:\SomePath
should use CommandArgument scope. Currently they use the function scope.
The following screenshot hopefully shows what I mean:
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (9 by maintainers)
Top Results From Across the Web
Semantic Highlight Guide | Visual Studio Code Extension API
Semantic tokenization allows language servers to provide additional token information based on the language server's knowledge on how to resolve symbols in the ......
Read more >How To Customize Semantic Token Colorization With Visual ...
Semantic tokenization allows language servers to improve and refine the syntax highlighting of tokens based on knowledge of how to resolve ...
Read more >Create new tokens for vs code semantic highlighting
The answer is that you can't define new types and modifiers--even though some programming languages do not fit into this classification ...
Read more >VS Code tips — Custom semantic token colorization - YouTube
VS Code lets you customize the color of your code based on its semantic meaning. You can use this to make async methods...
Read more >Add custom themes support for semantic highlighting
"semantic-styles": { "TOKEN": { "text-color": "#986801", // optional modifier "overwrites" "modifiers": { "readonly": { "bold": 1, } } },.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The problem is that no popular theme will support it, and we’ve just increased complexity without fixing the issue. Most people will continue using their Dark+/Monokai/Solarized theme and see attributes and types the same. So it’ll end up being like in https://github.com/PowerShell/vscode-powershell/issues/2856#issuecomment-669240917, where we correctly categorise the token differently and the colour is the same.
This is the real problem with themes. The themes themselves tend to be hacks designed to achieve nice coloration in the face of bad token categorisation. Which in turns forces the token classifiers to lie. I seem to recall there was a contentious change in the EditorSyntax repo where tokens were categorised more correctly and people complained because highlighting got worse.
I think the ideal here would be for us to define a correct token type, and a hack fallback, like:
attribute
->label
. That way the ISE theme could colour things with high specificity but users of popular themes will still get the color differentiation they’re looking for.Then you can do something 😃 Attributes have the “AttributeName” token flag which as far as I can tell is completely unique to attributes. Unquoted parameters have the kind+TokenFlag combination of “Generic” + “None” which would affect the same things I suggested “CommandArgument” would affect in the original post above.
For convenience here’s a table showing the relevant types and their Kind+TokenFlag combinations: