tree-sitter / tree-sitter-python

Python grammar for tree-sitter
MIT License
374 stars 138 forks source link

Parsing python code failed with, ValueError: Parsing Failed. #213

Closed earthPerson-001 closed 1 year ago

earthPerson-001 commented 1 year ago

The cause of the error is unknown as there is an error after some compilation and not in some. And sometimes, if I open another document and parse code and move back into the previous document, it parses fine.

tree_sitter version: 0.20.1

tree = treesitter.PARSER.parse(read_callable)
ValueError: Parsing failed

Where the error is produced:

tree = treesitter.PARSER.parse(read_callable)

The read_callable function:

def read_callable(byte_offset, point) -> bytes | None:
    """
    Function for reading a document incrementally.
    """
    if DOCUMENT is None:
        return None

    row, column = point
    if row >= len(DOCUMENT.lines) or column >= len(DOCUMENT.lines[row]):
        return None
    return DOCUMENT.lines[row][column:].encode("utf8")

If it is relevant, the parser is used in pygls server along with vscode extension client.

Whole code: https://github.com/Prabigyaa/JS/blob/comment-extraction-python/server/src/nlpserver/comments_extraction_python.py

amaanq commented 1 year ago

belongs in py-tree-sitter, not here

earthPerson-001 commented 1 year ago

Okay, closing the issue here.