-
Notifications
You must be signed in to change notification settings - Fork 20
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
clarify cursor API initial offsets #628
Comments
Merged
github-merge-queue bot
pushed a commit
that referenced
this issue
Nov 10, 2023
- rename `with_colour` to `with_color` as we are using a single `en-US` locale in the entire project. - use `SUPPORTED_VERSIONS.binary_search()` in `Language::new()` - use functions instead of properties for expensive operations -> #628 - require specifying an initial offset when creating a CST cursor -> #628
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
functions vs gettersI also suggest also not using getters, but functions, with a prefix likecreate_
instead ofget_
, since cursors returned should be persisted long-term and reused. Additionally, it is meant to be mutated, so it is no longer a property of the node that creates it. And last, that prevents bugs because of patterns like below, where users can wrongly expect the cursor to be persisted on the node:initial cursor offsetcurrently callingnode.cursor
would create one at offsetZERO
. This is correct for the root node, but problematic for any sub-nodes, and can cause user confusion. Let's replace this API with a few distinct methods:node.create_cursor_at(offset)
parse_result.create_root_cursor()
that would callself.root_node.create_cursor_at(ZERO)
for convenience.This way, the user is informed with the expected offset during creation.fast cursors (no offsets)
There are use cases that need to analyze the CST without tracking offsets. This means they shouldn't pay the cost of maintaining these numbers as the cursor is running. One idea is to provide another
node.create_*()
API that creates a fastCursor
that can implement all same API, but won't track or provideoffset
values.However, this is a nice-to-have feature, and we can put it aside for later if it will result in two divergent implementations.
The text was updated successfully, but these errors were encountered: