[BUG] Docs: "Adding support for custom languages" example fails with current tree-sitter (TypeError from tree_sitter_languages.get_language)

Open Beginner friendly
#6,753 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
documentation

Research direction

Read docs/widgets/text_area.md and docs/examples/widgets/text_area_custom_language.py, then check the custom language installation note and example against the current tree-sitter packages. Update the documentation and example so Java language registration works with the supported dependency versions. Done when the walkthrough and included example run and the install note accurately describes what textual[syntax] installs.

Written by the indexing model from the issue text.

Description

Have you checked closed issues? Yes — searched for tree-sitter-languages / get_language / custom languages / text_area_custom_language. No existing issue covers this docs example breakage (related closed items were dependency upgrades or missing binaries, not this walkthrough).

Have you checked against the most recent version of Textual? Yes — textual 8.2.8 (current on PyPI) with textual[syntax] (tree-sitter 0.26.0), Python 3.12, clean virtualenv.

The bug

Docs: https://textual.textualize.io/widgets/text_area/#adding-support-for-custom-languages
Source: docs/widgets/text_area.md and docs/examples/widgets/text_area_custom_language.py

The example does:

from tree_sitter_languages import get_language
java_language = get_language("java")

This raises:

TypeError: __init__() takes exactly 1 argument (2 given)

tree-sitter-languages 1.10.2 is not compatible with tree-sitter >= 0.25, which textual[syntax] now requires. The included example file fails the same way. The install note near the top of the page also still says textual[syntax] installs tree-sitter-languages, which it no longer does (it installs individual tree-sitter-<lang> packages).

Suggested fix using the per-language package Textual already depends on:

import tree_sitter_java
from tree_sitter import Language
java_language = Language(tree_sitter_java.language())

With that change the example registers Java and highlights it (tested).

Dominant language
Python
Stars
37.6k
Forks
1.4k
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Textualize/textual

All issues in Textualize/textual

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.