python: Fix Python exception highlighting - #58176
Conversation
MrSubidubi
left a comment
There was a problem hiding this comment.
As for this one, I am somewhat unsure whether this is desirable or not - I see VSCode does this, but Helix does not.
To me this seems that it introduces some inconcistency based on the error type used which might be unexpected and odd for highlighting, but I am happy to listen to your opinion here.
|
That's a fair point. My reasoning is that these exceptions are part of Python's built-in classes, so highlighting them as I would add that putting Python's exceptions under Let me know what you think. nvim-treesitter: https://github.com/nvim-treesitter/nvim-treesitter/blob/main/runtime/queries/python/highlights.scm VSCode (MagicPython): https://github.com/MagicStack/MagicPython/blob/master/grammars/MagicPython.tmLanguage |
|
I very much appreciate you doing your research on these topics and providing the context here, helps a lot with reviewing. That said, I almost find this to be the most controversial of your PRs to a degree, because I very much dislike the ambiguity this introduces. How about we meet in the middle and go with |
|
You're welcome !
I’ve updated the branch, please let me know if anything else is needed here. Thanks for the review ! |
MrSubidubi
left a comment
There was a problem hiding this comment.
Think this is looking good now. Thanks for this improvement and your input! Appreciate it.
In the current Python Tree-sitter `highlights.scm`, exception (https://docs.python.org/3/library/exceptions.html) are highlighted under `@type.class` which is inconsistent compared to other editors (VS Code, Neovim, Helix). This PR adds `#any-of?` with a list of python's exceptions and highlight them under `@type.builtin`. | Before | After | | :---------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------: | | <img width="1237" height="1160" alt="image" src="https://github.com/user-attachments/assets/05e1ae34-7637-413a-9785-ad696c2bf751" /> | <img width="1237" height="1154" alt="image" src="https://github.com/user-attachments/assets/105c61ca-b6a7-4c26-acc8-3e300f044510" /> | Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [ ] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - Added the ability to stylize builtin python exceptions and warnings using the `type.class.builtin` syntax capture.
In the current Python Tree-sitter `highlights.scm`, exception (https://docs.python.org/3/library/exceptions.html) are highlighted under `@type.class` which is inconsistent compared to other editors (VS Code, Neovim, Helix). This PR adds `#any-of?` with a list of python's exceptions and highlight them under `@type.builtin`. | Before | After | | :---------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------: | | <img width="1237" height="1160" alt="image" src="https://github.com/user-attachments/assets/05e1ae34-7637-413a-9785-ad696c2bf751" /> | <img width="1237" height="1154" alt="image" src="https://github.com/user-attachments/assets/105c61ca-b6a7-4c26-acc8-3e300f044510" /> | Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [ ] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - Added the ability to stylize builtin python exceptions and warnings using the `type.class.builtin` syntax capture.
In the current Python Tree-sitter `highlights.scm`, exception (https://docs.python.org/3/library/exceptions.html) are highlighted under `@type.class` which is inconsistent compared to other editors (VS Code, Neovim, Helix). This PR adds `#any-of?` with a list of python's exceptions and highlight them under `@type.builtin`. | Before | After | | :---------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------: | | <img width="1237" height="1160" alt="image" src="https://github.com/user-attachments/assets/05e1ae34-7637-413a-9785-ad696c2bf751" /> | <img width="1237" height="1154" alt="image" src="https://github.com/user-attachments/assets/105c61ca-b6a7-4c26-acc8-3e300f044510" /> | Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [ ] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - Added the ability to stylize builtin python exceptions and warnings using the `type.class.builtin` syntax capture.
In the current Python Tree-sitter
highlights.scm, exception (https://docs.python.org/3/library/exceptions.html) are highlighted under@type.classwhich is inconsistent compared to other editors (VS Code, Neovim, Helix).This PR adds
#any-of?with a list of python's exceptions and highlight them under@type.builtin.Self-Review Checklist:
Release Notes:
type.class.builtinsyntax capture.