pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

Improve semantic highlighting of `TypeAlias`

Open xiaoxi-david opened this issue 3 years ago • 6 comments

I wonder if:

  • Pylance could use TypeAlias instead of the type alias name for the type hinting for type aliases. According to PEP 613, the type hinting for type aliases should be TypeAlias.

  • Pylance could use the same color to display type hintings regardless of whether they are native or type aliases. When I use the theme Horizon Extended Theme, native type hintings are in yellow and type aliases in red (like variables).

Example: alias_test

I am using:

  • VS Code: Version: 1.70.0-insider (system setup) Commit: 13ba7bb446a638d37ebccb1a7d74e31c32bb9790 Date: 2022-07-22T05:17:00.353Z OS: Windows_NT x64 10.0.19044
  • Python extension: 2022.11.12031009
  • Pylance extension: 2022.7.41

xiaoxi-david avatar Jul 24 '22 16:07 xiaoxi-david

Similarly, consider behavior of NewType -- https://github.com/microsoft/pylance-release/issues/3754

debonte avatar Mar 01 '24 23:03 debonte

Any updates on this?

jnooree avatar Jun 07 '24 03:06 jnooree

Sorry but this is not currently planned. However you can get this somewhat by yourself.

The TypeAlias is flagged with a typehint modifier in the semantic token. This allows you to override the color:

image

    "editor.semanticTokenColorCustomizations": {
        "[Default Dark Modern]": {
            "rules": {
                "*.typeHint": "#4EC9B0"
            }
        }
    }

Which for me, gives the same color for the typehint as the original type.

image

rchiodo avatar Jun 07 '24 16:06 rchiodo

Great, I'll try for it. Thanks!

jnooree avatar Jun 07 '24 17:06 jnooree

It works for type hints only, so I think pylance should still provide separate semantic tokes for type aliases (or mark them as types or classes at least).

Anyway, the type hint trick is better than nothing, thanks for the suggestion.

jnooree avatar Jun 07 '24 18:06 jnooree

Really need this feature!

Isuxiz avatar Sep 29 '24 03:09 Isuxiz

Even after the changes made, this still seems to be broken.

This is with changes submitted to the main branch:

Image

rchiodo avatar Jan 16 '25 19:01 rchiodo

Oh it seems it's only for unions that it doesn't work.

This does:

Image

rchiodo avatar Jan 16 '25 19:01 rchiodo

I'll enter a new issue for unions. https://github.com/microsoft/pylance-release/issues/6854

rchiodo avatar Jan 16 '25 19:01 rchiodo

This issue has been fixed in prerelease version 2025.1.100, which we've just released. You can find the changelog here: CHANGELOG.md

heejaechang avatar Jan 16 '25 20:01 heejaechang