feat: add options to parsing and query execution#3843
Merged
amaanq merged 4 commits intotree-sitter:masterfrom Nov 1, 2024
Merged
feat: add options to parsing and query execution#3843amaanq merged 4 commits intotree-sitter:masterfrom
amaanq merged 4 commits intotree-sitter:masterfrom
Conversation
ee6c12a to
047a1e7
Compare
Member
Author
|
Ok this is now ready. I'm really happy with how the ergonomics for the Rust bindings turned out, and other bindings will have similar mechanisms involved for passing in the interrupt callback. This will also easily extend to passing in the decode callback too in #3833 |
671905e to
caa6a14
Compare
Contributor
maxbrunsfeld
left a comment
There was a problem hiding this comment.
This is definitely a good change. I left a few questions.
kennet31526
approved these changes
Oct 31, 2024
9683a0b to
4a8bf98
Compare
Currently, this allows users to pass in a callback that should be invoked to check whether or not to halt parsing
Currently, this allows users to pass in a callback that should be invoked to check whether or not to halt query execution
…ecate old functions The normal `with` functions are now deprecated in favor of the `with_options` ones.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2541
Would like #3833 to extend upon this
Problem
Currently, users have a hard time having manual control over when parsing or query execution is canceled. The API does offer a few ways to control this, typically by setting a timeout in microseconds or by setting a cancellation flag. However, this approach is very rigid, doesn't give the users flexibility to easily change this on the fly at runtime, and ties us to OS-specific time headers.
Solution
In the core library, two new functions,
ts_parser_parse_with_options&ts_query_cursor_exec_with_options, were added. These functions take in the same parameters as their -_with_optionsvariants, plus an additionalparse_optionsparameter of typeTSParseOptionsfor the parse function, and aquery_optionsparameter of typeTSQueryCursorOptions *.Currently, these options consist of a
payloadfield, and aninterrupt_callbackfield. If the interrupt callback is not null, it is invoked to check whether or not to halt parsing or query execution. The callback is to be set by the user, and takes in one parameter,state, of typeTSParseState/TSQueryCursorState, which currently only has apayloadfield (which makes working with FFI code easier). This type can easily be extended upon, in case we want to add additional data later on.The plan is to deprecate the
timeout_microsandcancellation_flagfunctions for the next version, and then eventually get rid of these functions + the platform-specific time code (clock.h) in the following version.