-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Improve Python syntax highlighting #1762
Comments
PR welcome. The Python tokenizer is here. |
Part of the issue is that Monaco's default theme differs from VSCode's Dark+ and Light+. It would be great if these could be reconciled to make it possible to implement Monarch tokenization that follows the same TextMate patterns. For example, if you try to update the Python tokenizer to support themes such as https://github.com/brijeshb42/monaco-themes/blob/master/themes/Monokai.json then it will break with the default Monaco themes. |
My understanding is that that's not possible, at least not without sacrificing performance or platforms where WASM isn't available, TextMate uses a different regex engine and its regexes can't just be converted to JS regexes. |
It should be possible to implement a Monarch tokenizer which results in a token stream similar to what the TextMate grammars result in. Right now implementing a Monarch tokenizer which approximates TextMate will result in a loss of syntax highlighting as Monaco's default theme does not support all of the tokens. I did extend the Monarch Python syntax highlighting to be closer to TextMate, but this required a number of customizations to the theme as well, would be great if I could make a PR to monaco-languages without it requiring theme customizations. Python editor with my customizations: https://colab.research.google.com/gist/blois/00fa28cdb0433e62c8106a4b5812d024/syntax-highlighting.ipynb |
More importantly, this seems to be missing Python 3 features like recognizing |
This supports microsoft/monaco-editor#1762. Note the new Python 3 keywords are: * `async` * `await` * `nonlocal` I also reorganized the list a bit because it seems like it contains a mixture of keywords and builtins (and `self`, which is neither...), so it is helpful to be specific to illustrate how to properly maintain the list.
@hediet, @bpasero, @alexdima |
Is it expected that the f-string support that was merged works in |
monaco-editor version: 0.19.2
Browser: Chrome 79 maybe
OS: macOS Mojave
Playground code that reproduces the issue:
Basically some import statements in Python aren't highlighted properly.
How Monaco/Monarch highlights things:
How VSCode highlights things:
The text was updated successfully, but these errors were encountered: