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

Change cursor to treat child's end point exclusive #3263

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

blmarket
Copy link

@blmarket blmarket commented Apr 7, 2024

...when running goto_first_child_for_{byte or point}.

My problem: I have a following markdown document

{Node document (0, 0) - (11, 0)} document 91
  {Node section (0, 0) - (8, 0)} section 101
    // .. ignorable details
  {Node section (8, 0) - (11, 0)} section 101
    // .. ignorable details

(indent describes child)

When I run goto_first_child_for_point with (8, 0), I expected to get the second section which spans (8, 0) to (11, 0). Instead I got the first section which spans (0, 0) to (8, 0).

My suggestion: Given that the range is start-inclusive and end-exclusive, I'm wondering tree-sitter can change the walk behavior to follow the same semantics, by excluding the end position of the node when considering the child.

Code change itself is trivial. Affected test cases were updated which I believe for a good reason. For example, even though ; is located at Point (6, 5), the test code previously had to call goto_first_child_for_point(6,6) to get to the ; node.

@amaanq amaanq requested a review from maxbrunsfeld April 7, 2024 16:55
@blmarket blmarket changed the title Change cursor to ignore child's end points Change cursor to treat child's end point exclusive Apr 7, 2024
...when running goto_first_child_for_{byte or point}.

My problem: I have a following markdown document

```
{Node document (0, 0) - (11, 0)} document 91
  {Node section (0, 0) - (8, 0)} section 101
    // .. ignorable details
  {Node section (8, 0) - (11, 0)} section 101
    // .. ignorable details
```

(indent describes child)

When I run `goto_first_child_for_point` with (8, 0), I expected to get
the second section which spans (8, 0) to (11, 0). Instead I got the
first section which spans (0, 0) to (8, 0).

My suggestion: Given that the range is start-inclusive and
end-exclusive, I'm wondering tree-sitter can change the walk behavior to
follow the same semantics, by excluding the end position of the node
when considering the child.

Code change itself is trivial. Affected test cases were updated which I
believe for a good reason.
@blmarket
Copy link
Author

blmarket commented Apr 12, 2024

I found the previous change was intentional - #1640

I don't understand... when I want to goto the child located at (6, 5) Point, I feel it's more intuitive to call the method with (6, 5) as parameter, instead of weird (6, 6). I can just add 1 as a workaround for my use cases but anyway please consider this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant