emacs-tree-sitter / elisp-tree-sitter

Emacs Lisp bindings for tree-sitter
https://emacs-tree-sitter.github.io
MIT License
816 stars 73 forks source link

Zero-length node ranges cannot be found with tsc-get-descendant-for-position-range #119

Open mickeynp opened 3 years ago

mickeynp commented 3 years ago

First of all, great package!

Consider the following Python example:

if True:

And the following tree:

module (1 . 9)
  if_statement (1 . 9)
    true (4 . 8)
    block (9 . 9)

Putting point at the end of the line of code and calling either (tsc-node-byte-range (tree-sitter-node-at-point)) or (tsc-node-byte-range (tsc-get-descendant-for-position-range (tsc-root-node tree-sitter-tree) (point) (point))) yields (1 . 9) or the module block range and not (9 . 9) as expected.

Is this a bug or a quirk in tree-sitter?

ubolonton commented 3 years ago

IIRC, tree-sitter disallows zero-length rules, and has a generation-time check for this. This looks like a bug in either the (CLI) generator, or in tree-sitter-python.