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

tsc-make-cursor and tsc-goto-xxxx does not appear to work when created against a non-root node #145

Open
mickeynp opened this issue May 21, 2021 · 2 comments
Labels
bug Something isn't working external-issue Issue caused by another library, or an external source

Comments

@mickeynp
Copy link

mickeynp commented May 21, 2021

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.

@mickeynp mickeynp changed the title tsc-make-cursor' + tsc-goto-xxxx` does not appear to work when created against a non-root node tsc-make-cursor and tsc-goto-xxxx does not appear to work when created against a non-root node May 21, 2021
@shackra shackra added the bug Something isn't working label May 23, 2021
@ubolonton
Copy link
Collaborator

The current behavior is that tree cursor is scoped to the node it's created against.
There are more details in tree-sitter/tree-sitter#567.

@ubolonton ubolonton added the external-issue Issue caused by another library, or an external source label Jul 24, 2021
@mickeynp
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working external-issue Issue caused by another library, or an external source
Projects
None yet
Development

No branches or pull requests

3 participants