Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UTF-16 encoding support is wanted #204

Closed
CallmeNezha opened this issue Mar 7, 2024 · 1 comment · Fixed by #235
Closed

UTF-16 encoding support is wanted #204

CallmeNezha opened this issue Mar 7, 2024 · 1 comment · Fixed by #235
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Milestone

Comments

@CallmeNezha
Copy link
Contributor

I'm using py-tree-sitter in my PyQt written text editor, and since Qt's QPlainTextEdit QTextDocument using UTF-16, I was wondering if you could add UTF-16 encoding support to this Python binding. Because tree-sitter supports UTF-16 and I see in binging.c it has UTF-8 as default input. Now I have to convert Qt's string to UTF-8 and pass it to py-tree-sitter's parser, and I have to calculate the correct position and byte position from the returned value and map it to the QTextDocument's cursor position. This conversion is complex and error-prone.

@ObserverOfTime
Copy link
Member

PR welcome.

This should be replaced with ts_parser_parse_string_encoding based on the encoding of the buffer:

new_tree = ts_parser_parse_string(self->parser, old_tree, source_bytes, length);

I don't know if the callable version has any way of finding the encoding:

.encoding = TSInputEncodingUTF8,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants