Closed QuantumStatic closed 3 years ago
Thanks for the feedback.
Semantic colorization takes precedence over the syntax colorization provided by textmate grammar. The current release is limited to the VS Code built in list of semantic token types. The known list of token and their mapping is available at https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#semantic-token-scope-map
In the next release, we've added some custom semantic token types to cover Python specific scenarios, such as the self parameter, cls parameter and dunder methods. Those will map to the existing python textmate scopes, such that colors for those identifiers will be the same with/without semantic colorization enabled.
As for decorators, we've decided to keep them colored based on their semantic type (class or function). If there's enough demand, we can add custom types for those.
For functions, we use the function
built in token type, which VS Code maps to entity.name.function
, so that is the color that will get picked up. We currently don't differentiate between function call/declaration, but is something we could potentially do.
FYI you can see the token/scopes via Developer: Inspect Editor Tokens and Scopes
command. That is the easiest way to validate that tokens are correct. With just the colors, it's more difficult to tell...
I am trying to inform you that I use my own custom syntax colouring by customising scopes that I get from the Developer: Inspect Editor Tokens and Scopes
. I paste my code in to my settings.json file and here is the snippet of the code, I'll also be adding this to the main issue.
"scope": "meta.function-call.generic.python",
"settings": {
"foreground": "#6adb3e"
}
When I do this for the Microsoft Language Server this seems to work fine but for Pylance this doesn't work among some other scopes as mentioned above. Hope the update allows me to change for more scopes using this json snippet.
Here's how you can customize colors for functions:
Using the semantic token:
"editor.semanticTokenColorCustomizations": {
"[One Dark Pro]": {
"rules": {
"function": "#8811ff"
}
}
}
Or using textmate scope:
"editor.tokenColorCustomizations": {
"[One Dark Pro]": {
"textMateRules": [
{
"scope": "entity.name.function",
"settings": {
"foreground": "#6087f3aa"
}
}
]
}
},
In addition to the above changes, the next release will support the declaration
semantic token modifier. This will allow a user/theme to customize colors differently for declarations of function
, property
, variable
and parameter
.
We've also added a decorator
semantic token modifier, and we map function.decorator
and class.decorator
to the meta.function.decorator.python
textmate scope. In One Dark Pro, this results in:
If you also want the module name and variable names under a decorator to be the same color as well, then you can customize module.decorator
and variable.decorator
(or simply *.decorator
) and achieve something like this:
This issue has been fixed in version 2020.9.7, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202097-30-september-2020
Environment data
Expected behaviour
Actual behaviour
variable.language.special.self.python, support.function.magic.python and variable.parameter.function.python aren't overriding default colouring scheme.
entity.name.function.decorator.python and entity.name.function.python aren't overriding the default colour scheme.
meta.function-call.generic.python isn't overriding the default colour scheme.
Logs
Code Snippet / Additional information