Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax Highlighting not for working for some scopes #401

Closed
QuantumStatic opened this issue Sep 22, 2020 · 5 comments
Closed

Syntax Highlighting not for working for some scopes #401

QuantumStatic opened this issue Sep 22, 2020 · 5 comments
Assignees
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@QuantumStatic
Copy link

QuantumStatic commented Sep 22, 2020

Environment data

  • Language Server version: 2020.9.5
  • OS and version: MacOS 10.15.6
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.5

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
Copy link
Contributor

huguesv commented Sep 22, 2020

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...

@jakebailey jakebailey added the enhancement New feature or request label Sep 22, 2020
@github-actions github-actions bot removed the triage label Sep 22, 2020
@QuantumStatic
Copy link
Author

QuantumStatic commented Sep 24, 2020

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
Copy link
Contributor

huguesv commented Sep 24, 2020

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 huguesv self-assigned this Sep 28, 2020
@huguesv
Copy link
Contributor

huguesv commented Sep 28, 2020

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

@huguesv huguesv added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Sep 28, 2020
@jakebailey
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants