TextArea improvements - lazy language import and allow installation of only required languages#5639
Conversation
You obviously have a better understanding of tree-sitter than I do, but could this not be quite brittle if the language package version isn't compatible with the highlight query? |
|
It's more brittle than the syntax extras yeah, but you can still supply your own highlight query that aligns with the parser when you register the language. If you're just doing "pip install tree-sitter-python" then relying on the built-in highlight query, then that'd be quite brittle. You should probably be installing a specific version, and registering the language and matching highlight query pair with TextArea.register_language. |
|
Thanks |
Launching TextArea with the
syntaxextras has a large upfront cost the first time it's run in a new virtualenv.A one-off compilation step is performed when the language is imported, and since all languages were being imported at the module level, it was adding a 1-2 second overhead at startup on the first run.
Subsequent launches within the same venv had little overhead (a few milliseconds).
Lazy importing of tree-sitter languages
This PR updates the TextArea to lazily import the languages, only when they're used, trimming 1-2 seconds off of these "cold starts".
Allowing users to install only what they need
With this PR, users don't need to install the
syntaxextras which includes a bunch of languages. They can instead just installtree-sitterplus the languages they require.For example, with Posting I uninstalled the syntax extras then done this:
...and it just worked without any code changes. Apps no longer need to pull in a bunch of transitive dependencies that they don't need.
Please review the following checklist.