From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs 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 Message-ID: <1D1196AE-7E7F-4887-B9FE-4EBA61042A4F@gmail.com> References: <87pm0l1qtu.fsf@yandex.ru> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21172"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 66989@debbugs.gnu.org To: Denis Zubarev Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Nov 08 08:09:44 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r0ch6-0005LR-16 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 08 Nov 2023 08:09:44 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r0cgo-0003nj-1o; Wed, 08 Nov 2023 02:09:26 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r0cgm-0003dx-5j for bug-gnu-emacs@gnu.org; Wed, 08 Nov 2023 02:09:24 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r0cgl-0003DK-Tr for bug-gnu-emacs@gnu.org; Wed, 08 Nov 2023 02:09:23 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r0chO-0007nT-2A for bug-gnu-emacs@gnu.org; Wed, 08 Nov 2023 02:10:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 08 Nov 2023 07:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66989 X-GNU-PR-Package: emacs Original-Received: via spool by 66989-submit@debbugs.gnu.org id=B66989.169942739629955 (code B ref 66989); Wed, 08 Nov 2023 07:10:02 +0000 Original-Received: (at 66989) by debbugs.gnu.org; 8 Nov 2023 07:09:56 +0000 Original-Received: from localhost ([127.0.0.1]:43922 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r0chI-0007n4-C0 for submit@debbugs.gnu.org; Wed, 08 Nov 2023 02:09:56 -0500 Original-Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]:42357) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r0chF-0007mq-Nn for 66989@debbugs.gnu.org; Wed, 08 Nov 2023 02:09:55 -0500 Original-Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6b77ab73c6fso376162b3a.1 for <66989@debbugs.gnu.org>; Tue, 07 Nov 2023 23:09:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699427349; x=1700032149; darn=debbugs.gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=RLSya6QWYxWVjAOKMEKu2x7vtz5wGWoflctaNTBKR9k=; b=VrHM55bwwtuofnlZ9NmDA/Js1cnBH1Q4Bx4GvtgLm4slkm39uUpjX/9Z5BxMcdpHQx SrWWQU6nWnZ8Gt9kR6xES/sZaA8QyjuatLDhf+yMZM0ou5kFPh8zyXhiKFtuyhba3yIu qkmzs3xyuRvE+fPhFKfGxvXwkflxVQxut60cSpKsrsske7TFovglCq+BFyj9xWl5t+cs v+CDuF5TWO5BC1Vx5IeJo6TJFfMUWQLuzPcLmFHTb2bwNQ13z6Qx9nRWBlin6h8HanGY gMl74h/98W3ZJqq8CLEy50X/UIG3V8eEWgSyGOFbpZgNGxwkr8Z+IkvPJJ5g7qItEoCJ ueXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699427349; x=1700032149; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RLSya6QWYxWVjAOKMEKu2x7vtz5wGWoflctaNTBKR9k=; b=WS9jg7jWg/3boJxjgy6C6dqVZydBRPBidoeAygy9iqt+A6f7rihinDOM8RAqFXMaQH 9FasROeKB7qTB39M4A5z9HQ66EXTWvr+61tsxhatO01PovLCpoPHM+ePyKZQo8sCvfV7 v1qHLbkJnIAFsp0sVFwNFDaGMeNCdv0JP8cYpZc+oY2/VJcoLwb9QtFP9odfho/JzIBA JTbyUxiiADG0L+hV9IsAtiDqH2eeYX7gBoE4+E/yd1CHVIKhi1jugFAfEWDsLMhpxWYe vKrxDhZYaVQ1TRabfkfmIeDMtPbOjMwK84lCe0qqoQK06om0r7UA7cAJtc8W1NEOso2+ NjyA== X-Gm-Message-State: AOJu0Yx1L9K+fuLNRbNZinaaIPruQHiwrbq9icQXpjGHtmPDAOZVHl8j m091y2DTeFhkXxA/P6+9uPI= X-Google-Smtp-Source: AGHT+IGUv5FxLx7GTwgskemhEA1D8845OhECyGGcS/lQxEkzCOhFbP2r9+vqC5FUQsQ0LxV8JhKm5A== X-Received: by 2002:a05:6a00:244b:b0:6c3:450f:2b64 with SMTP id d11-20020a056a00244b00b006c3450f2b64mr1786922pfj.6.1699427349344; Tue, 07 Nov 2023 23:09:09 -0800 (PST) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id ka19-20020a056a00939300b006905f6bfc37sm8291392pfb.31.2023.11.07.23.09.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Nov 2023 23:09:09 -0800 (PST) In-Reply-To: <87pm0l1qtu.fsf@yandex.ru> X-Mailer: Apple Mail (2.3731.700.6) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:273967 Archived-At: > On Nov 7, 2023, at 8:16 AM, Denis Zubarev wrote: >=20 >=20 > Steps to reproduce: > 1. emacs -Q > 2. M-x find-file /tmp/t.py > 3. paste to the buffer >=20 > def premain(): > pa|ss > def main(): > pass >=20 > where | is cursor position for further steps >=20 > 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. >=20 > If you eval `(treesit--things-around (point) = treesit-defun-type-regexp)`, > it returns `(nil # nil)` > It seems that when cursor is not on the beginning of the node, treesit > erroneously finds next sibling.=20 > It prevents finding parent node correctly (premain function in this = case). > I managed to fix the problem by replacing=20 > `(cursor (or (nth 0 result) (nth 1 result) node)` with ~(cursor node)~ = - here=20 > = https://github.com/emacs-mirror/emacs/blob/12d1f33ceb37a2d0399af7e4054024c= 60a465ab8/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=E2=80=99t clearly define the (prev = next parent) returned by treesit--things-around=E2=80=94maybe 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=E2=80=99t 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=E2=80=99s not clear which definition is more correct. I=E2=80=99m = leaning towards the first. Maybe both are correct and useful and we = should support both, hmm... Yuan=