microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.71k stars 765 forks source link

Syntax highlighting for ``match`` and ``case`` #1215

Closed cdce8p closed 3 years ago

cdce8p commented 3 years ago

It would be nice if syntax highlighting for match and case could be added.

Screen Shot 2021-04-30 at 17 04 04

def http_error(status: int):
    match status:
        case 400:
            return "Bad request"
        case 404:
            return "Not found"
        case 418:
            return "I'm a teapot"
jakebailey commented 3 years ago

Thanks for the report; at the moment we rely on the TextMate profile built into VS Code to display these kinds of keywords. I'm surprised they haven't been added there, but I do think we should be emitting keywords as tokens in the semantic highlighter as well.

cdce8p commented 3 years ago

After searching a bit more, I found these two existing issues: https://github.com/microsoft/vscode/issues/120734 https://github.com/MagicStack/MagicPython/issues/235

I've also opened a PR https://github.com/MagicStack/MagicPython/pull/237 to recognize match and case as keywords, at least in a match statement.

jakebailey commented 3 years ago

In the meantime while we wait for VS Code and such to pull in those changes, I've modified our semantic tokenizer to output match and case as keyword tokens:

matchcase

cdce8p commented 3 years ago

@jakebailey That's great! Thanks 🚀

jakebailey commented 3 years ago

This issue has been fixed in version 2021.5.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202150-5-may-2021

Jaakkonen commented 2 years ago

For people using pyright extension for development of it I think there's no other workaround than using a MagicPython extension built from the PR branch (rebased or not).

scarf005 commented 2 years ago

default themes and github themes support match case syntax, however majority of other themes does not support them out of the box.

running Inspect editor tokens and scopes shows result like this: _01

_02

could there be any way to overwrite custom themes to support match case? (using editor.tokenColorCustomizations for every single themes would too much work)

debonte commented 2 years ago

@scarf005, this issue has been closed for a long time. Please open a new issue for your suggestion.

scarf005 commented 2 years ago

@scarf005, this issue has been closed for a long time. Please open a new issue for your suggestion.

alright, referenced in new issue.