all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Denis Zubarev <dvzubarev@yandex.ru>
Cc: 66989@debbugs.gnu.org
Subject: bug#66989: 30.0.50; tree-sitter: treesit-defun-at-point wrong behavior in python-ts-mode
Date: Tue, 7 Nov 2023 23:08:53 -0800	[thread overview]
Message-ID: <1D1196AE-7E7F-4887-B9FE-4EBA61042A4F@gmail.com> (raw)
In-Reply-To: <87pm0l1qtu.fsf@yandex.ru>



> On Nov 7, 2023, at 8:16 AM, Denis Zubarev <dvzubarev@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




  reply	other threads:[~2023-11-08  7:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-07 16:16 bug#66989: 30.0.50; tree-sitter: treesit-defun-at-point wrong behavior in python-ts-mode Denis Zubarev
2023-11-08  7:08 ` Yuan Fu [this message]
2023-11-08 20:37   ` Zubarev Dv
2023-11-09  8:13     ` Yuan Fu
2023-11-10  5:46       ` Yuan Fu
2023-11-10  7:40         ` Eli Zaretskii
2023-11-10 22:58         ` Zubarev Dv
2023-11-11  2:31           ` Yuan Fu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1D1196AE-7E7F-4887-B9FE-4EBA61042A4F@gmail.com \
    --to=casouri@gmail.com \
    --cc=66989@debbugs.gnu.org \
    --cc=dvzubarev@yandex.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.