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

FieldNameForChild returns false results #80

Open
vjerci opened this issue Aug 25, 2022 · 1 comment
Open

FieldNameForChild returns false results #80

vjerci opened this issue Aug 25, 2022 · 1 comment

Comments

@vjerci
Copy link

vjerci commented Aug 25, 2022

When selecting ruby language and when doing this query

log.info($ARGUMENTS)

If we take the tree we will get this tree:

[program](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [1, 0]
  [call](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [0, 20]
    receiver: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [0, 3]
    method: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 4] - [0, 8]
    arguments: [argument_list](https://tree-sitter.github.io/tree-sitter/playground#) [0, 8] - [0, 20]
      [global_variable](https://tree-sitter.github.io/tree-sitter/playground#) [0, 9] - [0, 19]

As we can see there are 3 field names receiver, method and arguments

Now iterating or namedChildCount of call node with following code

for j := 0; j < int(node.NamedChildCount()); j++ {
	log.Println("it is "+ strconv.Itoa(j), node.FieldNameForChild(j))
}

we get results

it is 0 method
it is 1 arguments
it is 2

As we can see order is messed up (method should be on index 1, on index 0 it should be receiver)
field name receiver is also missing.

@lcaballero
Copy link

I've noticed similar behavior when traversing the tree through the Node interface vs using the TreeCursor. The TreeCursor seems to find the correct Field and the Node.FieldNameForChild doesn't.

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

No branches or pull requests

2 participants