GNU bug report logs - #66989
30.0.50; tree-sitter: treesit-defun-at-point wrong behavior in python-ts-mode

Previous Next

Package: emacs;

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


View this message in rfc822 format

From: Zubarev Dv <dvzubarev <at> yandex.ru>
To: Yuan Fu <casouri <at> gmail.com>
Cc: 66989 <at> debbugs.gnu.org
Subject: bug#66989: 30.0.50; tree-sitter: treesit-defun-at-point wrong behavior in python-ts-mode
Date: Wed, 08 Nov 2023 23:37:45 +0300
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.

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.




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.