elisp-tree-sitter
elisp-tree-sitter copied to clipboard
`tsc-make-cursor` and `tsc-goto-xxxx` does not appear to work when created against a non-root node
I'm encountering a weird issue and I'm fairly certain it's a bug.
If you create a cursor against a non-root node the cursor movement code does not work.
Version: 0.15.1 Test case:
(ert-deftest cursor::walk-from-root-node ()
(let ((parser (tsc-make-parser))
(language (tree-sitter-require 'rust)))
(tsc-set-language parser language)
(let* ((tree (tsc-parse-string parser "fn foo() {}"))
(root-node (tsc-root-node tree))
(tree-sitter-tree tree)
(cursor (tsc-make-cursor root-node)))
(ert-info ("Moving a cursor that was made against a non-root should work")
;; test that the root node can navigate independently
;; this works
(should (eq (tsc-node-type (tsc-current-node cursor)) 'source_file))
(should (tsc-goto-first-child cursor))
(should (eq (tsc-node-type (tsc-current-node cursor)) 'function_item))
;; this too
(let* ((sub-node (tsc-current-node cursor))
(sub-cursor (tsc-make-cursor sub-node)))
(should (tsc-node-p sub-node))
(should (tsc-cursor-p sub-cursor))
(should (eq (tsc-node-type (tsc-current-node cursor)) 'function_item))
;; this should move us back from whence we came but this fails with a nil response.
(should (tsc-goto-parent sub-cursor)))))))
EDIT: I amended the test slightly to make it more specific.
The current behavior is that tree cursor is scoped to the node it's created against. There are more details in https://github.com/tree-sitter/tree-sitter/issues/567.
Hm. Yeah, I did actually see the documentation in tree-sitter that said that, but I clearly misunderstood what they meant by that.
It's a shame as text editing with tree-sitter most often revolves around the idea of acting on/around where point is. I'll stick to the other helper methods then in the interim.
Thanks for clarifying!