Allow using `tree-sitter-language-pack` if installed
Resolves #6324
- https://github.com/Textualize/textual/discussions/6324
In [1]: import tree_sitter_language_pack as tslp
In [2]: tslp.get_language('python')
Out[2]: <Language id=140111323851968, version=15, name="python">
In [3]: from textual._tree_sitter import get_language
In [4]: get_language('python')
Out[4]: <Language id=140111323851968, version=15, name="python">
In [5]: get_language??
Signature: get_language(language_name: 'str') -> 'Language | None'
Docstring: <no docstring>
Source:
def get_language(language_name: str) -> Language | None:
try:
return tslp.get_language(language_name)
except LookupError:
log.warning(f"Could not load language {language_name!r}.")
return None
File: ~/code/github/textualize/textual/src/textual/_tree_sitter.py
Type: function
In [6]:
bump!
:pray:
Hi, I noticed this PR is inactive, I'm also interested in adding support for tree-sitter-language-pack in textual and also use it to get highlight queries.
@dhirschfeld Are you still interested in this ?
Should I make my own follow-up PR ?
Feel free to pick this up. I invited you to collaborate so you can push to this branch, or feel free create a new branch - I'm not precious.
I had planned to get around to this, but am super smashed with life & work currently :pensive:.
If you don't get around to it, I will try and pick it up as I can find time (likely measured in months, not weeks as it's a nice-to-have, but not on my critical path)
Hi, I did a few changes to make it work with a newer version of tree-sitter-language-pack, and added support to get highlight query from it.
I also added an extra dependency for it, tests and tried to update the documentation from which you will probably want some changes.
Also since you have an AI policy, I already mentioned it in the relevant commit description but I did use AI (ChatGPT 5.5) to generate the code samples used in the snapshots test. No AI was used for anything else.
Don't hesitate to ask for any change. Thanks for your time.
I updated tree-sitter-language-pack, it should be stable now (had to report a few issue with the binding upstream).
Ready for review.