Giter Club home page Giter Club logo

Comments (5)

davep avatar davep commented on September 24, 2024 1

Yeah, I had a very quick play yesterday (not enough to draw any useful conclusions) and it felt like it was a tree-sitter issue; for example when I loaded the file as-is but said it was python code it loaded pretty much instantly. Didn't seem to be an actual problem with TextArea itself.

from textual.

TomJGooding avatar TomJGooding commented on September 24, 2024

I think the problem is the size of the html file. I experimented with reducing this to ~1,000 lines and eventually the app does load.

Running the original example with gdb shows a segfault related to treesitter:

Starting program: /home/tom/Projects/textual-sandbox/.venv/bin/python3 repro_4152.py
[Thread debugging using libthread_db enabled]                                                                                                                 
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7ffff29ff6c0 (LWP 82877)]                                                                                                                       
[New Thread 0x7ffff21fe6c0 (LWP 82878)]

Thread 1 "python3" received signal SIGSEGV, Segmentation fault.
ts_query_cursor__compare_captures (self=self@entry=0x5555556c9e40, left_state=left_state@entry=0x555556e897d0, right_state=right_state@entry=0x555556e897e0, left_contains_right=left_contains_right@entry=0x7fffffffc438, right_contains_left=right_contains_left@entry=0x7fffffffc490) at tree_sitter/core/lib/src/./query.c:3183
3183	tree_sitter/core/lib/src/./query.c: Bad file descriptor. 
Backtrace
#0  ts_query_cursor__compare_captures (self=self@entry=0x5555556c9e40, left_state=left_state@entry=0x555556e897d0, right_state=right_state@entry=0x555556e897e0, left_contains_right=left_contains_right@entry=0x7fffffffc438, right_contains_left=right_contains_left@entry=0x7fffffffc490) at tree_sitter/core/lib/src/./query.c:3183
#1  0x00007ffff5bed90c in ts_query_cursor__advance (self=self@entry=0x5555556c9e40, stop_on_definite_step=stop_on_definite_step@entry=true) at tree_sitter/core/lib/src/./query.c:3868
#2  0x00007ffff5bee60a in ts_query_cursor_next_capture (self=0x5555556c9e40, match=match@entry=0x7fffffffc680, capture_index=capture_index@entry=0x7fffffffc664) at tree_sitter/core/lib/src/./query.c:4116
#3  0x00007ffff5bcf763 in query_captures (self=0x7ffff5b480f0, args=<optimized out>, kwargs=<optimized out>) at tree_sitter/binding.c:1994
#4  0x00007ffff79f9ea1 in ?? () from /usr/lib/libpython3.11.so.1.0
#5  0x00007ffff7a13d35 in PyObject_Call () from /usr/lib/libpython3.11.so.1.0
#6  0x00007ffff79eb237 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.11.so.1.0
#7  0x00007ffff7a09560 in _PyFunction_Vectorcall () from /usr/lib/libpython3.11.so.1.0
#8  0x00007ffff79f1327 in PyObject_Vectorcall () from /usr/lib/libpython3.11.so.1.0
#9  0x00007ffff7aa60fa in ?? () from /usr/lib/libpython3.11.so.1.0
#10 0x00007ffff79d1565 in _PyObject_GenericSetAttrWithDict () from /usr/lib/libpython3.11.so.1.0
#11 0x00007ffff79d0da3 in PyObject_SetAttr () from /usr/lib/libpython3.11.so.1.0
#12 0x00007ffff79e6faa in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.11.so.1.0
#13 0x00007ffff7a2b583 in ?? () from /usr/lib/libpython3.11.so.1.0
#14 0x00007ffff7a2aaf8 in ?? () from /usr/lib/libpython3.11.so.1.0
#15 0x00007ffff79e722b in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.11.so.1.0
#16 0x00007ffff7ab06f2 in ?? () from /usr/lib/libpython3.11.so.1.0
#17 0x00007ffff79e6305 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.11.so.1.0
#18 0x00007ffff7ab06f2 in ?? () from /usr/lib/libpython3.11.so.1.0
#19 0x00007ffff79e6305 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.11.so.1.0
#20 0x00007ffff7ab06f2 in ?? () from /usr/lib/libpython3.11.so.1.0
#21 0x00007ffff79e6305 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.11.so.1.0
#22 0x00007ffff7ab06f2 in ?? () from /usr/lib/libpython3.11.so.1.0
#23 0x00007ffff79e6305 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.11.so.1.0
#24 0x00007ffff7ab06f2 in ?? () from /usr/lib/libpython3.11.so.1.0
#25 0x00007ffff79e6305 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.11.so.1.0
#26 0x00007ffff7ab06f2 in ?? () from /usr/lib/libpython3.11.so.1.0
#27 0x00007ffff79e6305 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.11.so.1.0
#28 0x00007ffff7ab06f2 in ?? () from /usr/lib/libpython3.11.so.1.0
#29 0x00007ffff79e6305 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.11.so.1.0
#30 0x00007ffff7ab06f2 in ?? () from /usr/lib/libpython3.11.so.1.0
#31 0x00007ffff79e6305 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.11.so.1.0
#32 0x00007ffff7ab06f2 in ?? () from /usr/lib/libpython3.11.so.1.0
#33 0x00007ffff79e6305 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.11.so.1.0
#34 0x00007ffff7ab06f2 in ?? () from /usr/lib/libpython3.11.so.1.0
#35 0x00007ffff6dd8886 in ?? () from /usr/lib/python3.11/lib-dynload/_asyncio.cpython-311-x86_64-linux-gnu.so
#36 0x00007ffff79f9165 in ?? () from /usr/lib/libpython3.11.so.1.0
#37 0x00007ffff798ff41 in ?? () from /usr/lib/libpython3.11.so.1.0
#38 0x00007ffff7990a35 in ?? () from /usr/lib/libpython3.11.so.1.0
#39 0x00007ffff79f210a in ?? () from /usr/lib/libpython3.11.so.1.0
#40 0x00007ffff79eb237 in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.11.so.1.0
#41 0x00007ffff7a9cd1a in ?? () from /usr/lib/libpython3.11.so.1.0
#42 0x00007ffff7a9c72c in PyEval_EvalCode () from /usr/lib/libpython3.11.so.1.0
#43 0x00007ffff7aba893 in ?? () from /usr/lib/libpython3.11.so.1.0
#44 0x00007ffff7ab6dda in ?? () from /usr/lib/libpython3.11.so.1.0
#45 0x00007ffff7acd0d3 in ?? () from /usr/lib/libpython3.11.so.1.0
#46 0x00007ffff7acc905 in _PyRun_SimpleFileObject () from /usr/lib/libpython3.11.so.1.0
#47 0x00007ffff7acb2f8 in _PyRun_AnyFileObject () from /usr/lib/libpython3.11.so.1.0
#48 0x00007ffff7ac5b98 in Py_RunMain () from /usr/lib/libpython3.11.so.1.0
#49 0x00007ffff7a8ef8b in Py_BytesMain () from /usr/lib/libpython3.11.so.1.0
#50 0x00007ffff7645cd0 in ?? () from /usr/lib/libc.so.6
#51 0x00007ffff7645d8a in __libc_start_main () from /usr/lib/libc.so.6
#52 0x0000555555555045 in _start ()

from textual.

TomJGooding avatar TomJGooding commented on September 24, 2024

Delving deeper...

from pathlib import Path

from textual.widgets._text_area import _HIGHLIGHTS_PATH
from tree_sitter_languages import get_language, get_parser

HTML_PATH = Path(".") / "snapshot_report.html"
HTML_TEXT = HTML_PATH.read_text(encoding="utf-8")


def read_callable(byte_offset: int, point: tuple[int, int]) -> bytes:
    row, column = point
    lines = HTML_TEXT.splitlines(keepends=False)
    newline = "\n"

    row_out_of_bounds = row >= len(lines)
    if row_out_of_bounds:
        return b""
    else:
        row_text = lines[row]

    encoded_row = row_text.encode("utf-8")
    encoded_row_length = len(encoded_row)

    if column < encoded_row_length:
        return encoded_row[column:] + newline.encode("utf-8")
    elif column == encoded_row_length:
        return newline[0].encode("utf-8")
    # elif column == encoded_row_length + 1:
    #     if newline == "\r\n":
    #         return b"\n"

    return b""


parser = get_parser("html")
syntax_tree = parser.parse(read_callable)

language = get_language("html")
highlight_query_path = Path(_HIGHLIGHTS_PATH.resolve()) / "html.scm"
highlight_query_text = highlight_query_path.read_text()
highlight_query = language.query(highlight_query_text)

captures = highlight_query.captures(syntax_tree.root_node)
print(len(captures))

from textual.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.