unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Zubarev Dv <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: Thu, 9 Nov 2023 00:13:24 -0800	[thread overview]
Message-ID: <64784314-7290-47E6-A0B3-897D2FDC4D78@gmail.com> (raw)
In-Reply-To: <2908341699475865@izsosstglkfltgsl.vla.yp-c.yandex.net>



> On Nov 8, 2023, at 12:37 PM, Zubarev Dv <dvzubarev@yandex.ru> wrote:
> 
> Initially I thought that it is the second definition.  It seems to be more intuitive. But after reading code, I was sure its the first case.
> 
> But I actually don't sure that all three "things" are needed at once.
> For example,  I think for `thing-at-point` only enclosing parent is needed.
> If parent is nil, it may optionally fallback to the next sibling thing.
> `treesit--navigate-thing` uses only `parent` and `next` or `prev`.
> I was playing with creating evil text objects, based on your awesome
> work with "things".
> I ended up extracting the second part (;; 2. Find the parent) from `treesit--things-around`.
> Since I only need to find enclosing parent and I don't want to pay for
> what I don't use.
> So it seems no function uses all results from `treesit--things-around`.
> 
> Maybe it makes sense to decompose `treesit--things-around` into two
> functions:
> 1. (treesit--enclosing-thing (pos thing)) - returns node or nil if no
> enclosing parent
> 2. (treesit--find-sibling (pos thing dir)) - return sibling node in
> specified direction.

Makes sense. I think separating into two functions is ok. For treesit--enclosing-thing, we might as well call it treesit--thing-at-point ;-) Tentative plan: retire treesit—things-around, add treesit--enclosing-thing (as --thing-at-point), add treesit--find-sibling (as --sibling-thing), add treesit-node-enclose-p which tests whether a node encloses another node.

> 
> BTW, I've found another unexpected behavior on the same code:
> 
> 
> 1. python-ts-mode
> 
> def premain():
>    pa|ss
> def main():
>    pass
> 2. after
> (goto-char (treesit--navigate-thing (point) 1 'end treesit-defun-type-regexp))
> 
> def premain():
>    pass
> def main():
>    pass|
> 
> cursor in the end of the second function
> 
> 3. but if you move cursor to the beginning of pass
> 
> def premain():
>    |pass
> def main():
>    pass
> 
> 4.  after
> (goto-char (treesit--navigate-thing (point) 1 'end treesit-defun-type-regexp))
> 
> def premain():
>    pass|
> def main():
>    pass
> 
> This behavior does not affected by the fix proposed in the first message.

In the first case, treesit--navigate-thing returns a non-nil NEXT node. And treesit—navigate will prioritize NEXT node over PARENT node (because it assumes PARENT node always encloses NEXT node). Fixing the original problem should fix this too.

Yuan




  reply	other threads:[~2023-11-09  8:13 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
2023-11-08 20:37   ` Zubarev Dv
2023-11-09  8:13     ` Yuan Fu [this message]
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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=64784314-7290-47E6-A0B3-897D2FDC4D78@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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).