uyha / tree-sitter-cmake

A Tree-sitter parser for CMake
MIT License
41 stars 9 forks source link

Modifications to get nodes including parenthesis #12

Closed gzmorell closed 1 year ago

gzmorell commented 1 year ago

Adds a node with parenthesis. This is needed in helix-editor to allow match parenthesis to work.

uyha commented 1 year ago

I prefer "(" and ")" stay as anonymous nodes, is there a reason Helix can't match on anonymous nodes?

gzmorell commented 1 year ago

I first tried with anonymous node, "_paren_argument" instead of "paren_argument", as in this case tests and queries were still valid ones, but matching did not work in Helix. I don't know the reason. AFAIK other tree-sitter grammars has some non-anonymous node starting with parenthesis.

uyha commented 1 year ago

So I think the quotes being anonymous nodes is not the problem, hence I won't merge this PR. I will leave this PR open and please feel free to suggest changes if you found the underlying cause with Helix.

gzmorell commented 1 year ago

Just to be clear, with non-anonymous nodes, matching parenthesis works in Helix.

uyha commented 1 year ago

yes, I understand that, what I'm suggesting is you should discuss this issue with the Helix maintainers, and if they say that the problem is with the parentheses being anonymous nodes, then I will consider changing them to non-anonymous nodes.

gzmorell commented 1 year ago

I have been looking at Helix source. They use this function to iterate the nodes: let mut node = tree.root_node().named_descendant_for_byte_range(pos, pos)?; No idea why they use the named version.

uyha commented 1 year ago

an oversight, maybe?

gzmorell commented 1 year ago

I have tested with anonymous nodes and changing named_descendant with descendant, still not work. Furthermore, testing the grammar for anonymous nodes, seems not to be easy. "tree-sitter parse" only prints named nodes.

uyha commented 1 year ago

image

neovim has a feature for it and it's quite easy to set up for debugging if you need

uyha commented 1 year ago

@gzmorell is this needed anymore? can you close it?