emacs-tree-sitter / elisp-tree-sitter

Emacs Lisp bindings for tree-sitter
https://emacs-tree-sitter.github.io
MIT License
816 stars 73 forks source link

Python syntax highlighting got worse on new versions #153

Closed KaratasFurkan closed 2 years ago

KaratasFurkan commented 3 years ago

Hi, I wasn't updating emacs-tree-sitter for a very long time but a few days ago, I accidentally deleted it and re-installed it with newest version. Now, in python-mode, variables doesn't get highlighted, and when I try to install the version I used before (which is 759e3c4aeace2f4224aec071249b7a8794bfe3fa) it gives the same error in this issue: #152 (but with tree-sitter-grammars-linux-0.5.0.tar.gz in my old version)

Syntax highlighting comparison:

Without tree-sitter (variable declarations are red but less highlighting in general): disabled-cut

With old version tree-sitter (variable declarations are red and everything gets highlighting, perfect): old-cut

With new version tree-sitter (variable declarations doesn't get highlighted): new-cut

KaratasFurkan commented 3 years ago

I also realized that decorators (e.g. @method_decorator... in screenshots) changed too, when run M-x describe-text-properties on it, it gives two faces: (tree-sitter-hl-face:function\.call tree-sitter-hl-face:function\.special) first one is orange, second one is white which I prefer. Can I make tree-sitter-hl-face:function\.special come first?

ubolonton commented 2 years ago

This is an issue in tree-sitter-langs, probably because the grammar was updated, but the hl queries were not modified accordingly. Can you open a bug there?

In the mean time, you can work around this by adding a custom pattern in your config code:

(tree-sitter-hl-add-patterns 'python
  [(assignment left: (identifier) @variable)])

I also realized that decorators (e.g. @method_decorator... in screenshots) changed too, when run M-x describe-text-properties on it, it gives two faces: (tree-sitter-hl-face:function\.call tree-sitter-hl-face:function\.special) first one is orange, second one is white which I prefer. Can I make tree-sitter-hl-face:function\.special come first?

You can add a custom pattern to override that:

(tree-sitter-hl-add-patterns 'python
  [(decorator (call (identifier) @function.special))])
KaratasFurkan commented 2 years ago

Your workarounds fixed the problem :tada: Thank you so much. I opened an issue in tree-sitter-langs as you suggested. I will remove the custom patterns from my config when it fixed :+1: