tree-sitter-haskell icon indicating copy to clipboard operation
tree-sitter-haskell copied to clipboard

In Neovim the parent node is selected when cursor is on first character of a child node

Open grddavies opened this issue 8 months ago • 1 comments

I am using this parser for haskell files in neovim, and want to select the node under the cursor. I've noticed that when the cursor is on the first character of a node, the parent node is currently selected in the InspectTree window. This seems like a bug to me, but I'm not sure if its a bug in this parser or in the way that neovim is using it.

Examples :

Parent 'haskell' node selected while cursor on import statement

Image Image

Parent do block is selected while the cursor is on the tidal binding

Image Image

If I call vim.treesitter.get_captures_at_cursor() while the cursor is on the first character of tidal, it correctly returns { "variable" }

Can anyone help me understand why this is?

grddavies avatar Apr 26 '25 14:04 grddavies

huh. That really is highly peculiar...

It appears that not all nodes are affected, so I would speculate that this is caused by some of the zero-width nodes parsed by the C extension.

If I'm reading the tree-sitter code involved in the query correctly, it only skips empty nodes when their end point is before the cursor position. My intuition is that our empty nodes would start and end at the same position as the real node, but I'll have to investigate further.

tek avatar Apr 28 '25 00:04 tek