tree-sitter / py-tree-sitter

Python bindings to the Tree-sitter parsing library
https://tree-sitter.github.io/py-tree-sitter/
MIT License
889 stars 106 forks source link

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

Closed earthPerson-001 closed 8 months ago

earthPerson-001 commented 1 year ago

I opened this issue in the repo but was instructed to open it here.

tree_sitter version: 0.20.1 language_repo: https://github.com/tree-sitter/py-tree-sitter

The error occurs after calling the parser through the language parser.

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

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

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 relevant, the parser is used in the pygls server along with vs code extension client.

where the code is passed for parsing: https://github.com/Prabigyaa/prabigya-vscode/blob/c126f41ef2b3085fa713af01826961a951dbb9e6/server/src/nlpserver/server.py#L297

ObserverOfTime commented 8 months ago

Closing this for now. Please reopen with a minimal reproducible example if it's still relevant.