GNU bug report logs -
#66989
30.0.50; tree-sitter: treesit-defun-at-point wrong behavior in python-ts-mode
Previous Next
Reported by: Denis Zubarev <dvzubarev <at> yandex.ru>
Date: Tue, 7 Nov 2023 16:20:02 UTC
Severity: normal
Found in version 30.0.50
Done: Yuan Fu <casouri <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
Message #8 received at 66989 <at> debbugs.gnu.org (full text, mbox):
> On Nov 7, 2023, at 8:16 AM, Denis Zubarev <dvzubarev <at> yandex.ru> wrote:
>
>
> Steps to reproduce:
> 1. emacs -Q
> 2. M-x find-file /tmp/t.py
> 3. paste to the buffer
>
> def premain():
> pa|ss
> def main():
> pass
>
> where | is cursor position for further steps
>
> 4. M-x python-ts-mode
> 5. M-x eval-expression (treesit-defun-at-point)
> treesit-defun-at-point returns nil, but I expect that it will return
> a node for `premain`.
> If you move the cursor to the beginning of the word `pass` and try again
> it will return node for `premain` function.
>
> If you eval `(treesit--things-around (point) treesit-defun-type-regexp)`,
> it returns `(nil #<treesit-node function_definition ...> nil)`
> It seems that when cursor is not on the beginning of the node, treesit
> erroneously finds next sibling.
> It prevents finding parent node correctly (premain function in this case).
> I managed to fix the problem by replacing
> `(cursor (or (nth 0 result) (nth 1 result) node)` with ~(cursor node)~ - here
> https://github.com/emacs-mirror/emacs/blob/12d1f33ceb37a2d0399af7e4054024c60a465ab8/lisp/treesit.el#L2383
> But I'm sure it is not the proper fix.
Thank you very much, Denis, your fix is actually the proper fix! But the problem is more complicated. I didn’t clearly define the (prev next parent) returned by treesit--things-around—maybe parent must enclose the prev and next node, and if there are prev and next node beyond the smallest parent node at point, they are not returned; maybe parent doesn’t have to enclose prev and next node, and we will include prev and next nodes in the return value as long as they exist.
It’s not clear which definition is more correct. I’m leaning towards the first. Maybe both are correct and useful and we should support both, hmm...
Yuan
This bug report was last modified 1 year and 277 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.