microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.7k stars 770 forks source link

Syntax Highlighting not for working for some scopes #401

Closed QuantumStatic closed 3 years ago

QuantumStatic commented 4 years ago

Environment data

Expected behaviour

  1. Self should be orange as a parameter and when being returned .
  2. magic method named call should be green should be green. Screenshot 2020-09-22 at 5 52 16 PM
  3. Decorator name should be highlighted as green.
  4. Function name should be green. Screenshot 2020-09-22 at 6 03 46 PM
  5. Member Function calls are supposed to be green. Screenshot 2020-09-22 at 6 09 22 PM

Actual behaviour

Screenshot 2020-09-22 at 5 56 59 PM

variable.language.special.self.python, support.function.magic.python and variable.parameter.function.python aren't overriding default colouring scheme.

Screenshot 2020-09-22 at 6 01 41 PM

entity.name.function.decorator.python and entity.name.function.python aren't overriding the default colour scheme.

Screenshot 2020-09-22 at 6 11 15 PM

meta.function-call.generic.python isn't overriding the default colour scheme.

Logs

XXX

Code Snippet / Additional information

"scope": "meta.function-call.generic.python",
 "settings": {
              "foreground": "#6adb3e" 
             }
huguesv commented 4 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...

QuantumStatic commented 4 years ago

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.

huguesv commented 4 years ago

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"
          }
        }
         ]
    }
  },
huguesv commented 4 years ago

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: image

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: image

jakebailey commented 3 years ago

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