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: Thu, 9 Nov 2023 21:46:01 -0800 Message-ID: <4EF82A33-6EA1-4EF1-A091-D1ED131FA62E@gmail.com> References: <87pm0l1qtu.fsf@yandex.ru> <1D1196AE-7E7F-4887-B9FE-4EBA61042A4F@gmail.com> <2908341699475865@izsosstglkfltgsl.vla.yp-c.yandex.net> <64784314-7290-47E6-A0B3-897D2FDC4D78@gmail.com> 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="34822"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 66989@debbugs.gnu.org To: Zubarev Dv Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Nov 10 06:47:48 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 1r1KMt-0008sL-2V for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 10 Nov 2023 06:47:47 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r1KMX-00087Z-Kx; Fri, 10 Nov 2023 00:47:25 -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 1r1KMV-00087O-Px for bug-gnu-emacs@gnu.org; Fri, 10 Nov 2023 00:47:23 -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 1r1KMU-0003Ik-Vp for bug-gnu-emacs@gnu.org; Fri, 10 Nov 2023 00:47:22 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r1KN8-0002ch-38 for bug-gnu-emacs@gnu.org; Fri, 10 Nov 2023 00:48: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: Fri, 10 Nov 2023 05:48: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.169959523210025 (code B ref 66989); Fri, 10 Nov 2023 05:48:02 +0000 Original-Received: (at 66989) by debbugs.gnu.org; 10 Nov 2023 05:47:12 +0000 Original-Received: from localhost ([127.0.0.1]:49341 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r1KMG-0002ba-KT for submit@debbugs.gnu.org; Fri, 10 Nov 2023 00:47:12 -0500 Original-Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]:58805) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r1KMB-0002b2-3r for 66989@debbugs.gnu.org; Fri, 10 Nov 2023 00:47:07 -0500 Original-Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-5a9bf4fbd3fso1392301a12.1 for <66989@debbugs.gnu.org>; Thu, 09 Nov 2023 21:46:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699595177; x=1700199977; 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=5neD7QUbHYdbUt0U/sKy/RVD3at6IgpO8PF+zD1U7DQ=; b=MY57VcJiS/uh5dctobLW67wkPrCyox9kke7GfEBKp6OHb0YNgOhJlSDSJWX6cKvYTJ zRW2elBX6Xki4NGgVvd4bFFrE1r/C/hHIpDLD8CNRf+LpFgLwLL6iO9B9QpWJagn0kg5 yboxiU+XfOD9U8kbPnBdpS8hJ3u4ai0O2eLL1mxu6lGz4zF4C0Adk5K3KJHhE+pQWucN r6Pkcgx6M2bkR1Vxt6AH8k89Hfa13YpLAoUBbtOdrjfDnhoB5eClGxW5jOvD+YYolcWb kpbRewSbTYSCQvNgyjXM5ERV96sA+YxF4+y+HxEA4JE72pn8yNs4gNbQB1DFL0MbHLT6 fnQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699595177; x=1700199977; 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=5neD7QUbHYdbUt0U/sKy/RVD3at6IgpO8PF+zD1U7DQ=; b=P1Lyx2hCcNxyOrv5CzqiMLMWbJwjiOiNchv9r+VZVJ8ylCJDZ3KfMkGxI5oyYbNqxl xAHUke6WRtM/VAofrTp8PejnPR1RpIS1yrXsVRuIciB9RnCnX6ftqueY/I3s1jumPjlp fcw8qo6h0ENFoVMMnVcfHLLzkQuw97YGCBya+F27vyCt7vpSPkEtXB2h0Hj2zgw/KDoP R1KlBm8G4hWu2klV/tU8X2BhIlwyMeC+QNhnTSyjyDlx6cuPcd5Em8COEjACnd4cPXZO KelXUj99DfQtKr5MMG0yQE4YctVofxS7XctTOiDx+uvBwOcT7Jjya3HMv4jiGWCllC6c YeEw== X-Gm-Message-State: AOJu0YyYF9rW5kziWP6x+Lq07IggRb0JR1yqJyFpcx2eBcB58rE7KFSg T7MfUEtHV+U6XzTXkBCmnGU= X-Google-Smtp-Source: AGHT+IHjlT/MwJ21M+l1jsHJtwjdSp7oY5rwMhy6i28xTQmRtZnwot+j+fCSD21K6a/fzdGeWF2j6A== X-Received: by 2002:a05:6a21:4982:b0:181:ed8b:481c with SMTP id ax2-20020a056a21498200b00181ed8b481cmr7959744pzc.14.1699595177398; Thu, 09 Nov 2023 21:46:17 -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 20-20020a17090a199400b0028028560c4bsm847423pji.57.2023.11.09.21.46.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Nov 2023 21:46:17 -0800 (PST) In-Reply-To: <64784314-7290-47E6-A0B3-897D2FDC4D78@gmail.com> 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:274085 Archived-At: > On Nov 9, 2023, at 12:13 AM, Yuan Fu wrote: >=20 >=20 >=20 >> On Nov 8, 2023, at 12:37 PM, Zubarev Dv wrote: >>=20 >> 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. >>=20 >> 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`. >>=20 >> 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. >=20 > 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=E2=80=94things-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. >=20 >>=20 >> BTW, I've found another unexpected behavior on the same code: >>=20 >>=20 >> 1. python-ts-mode >>=20 >> def premain(): >> pa|ss >> def main(): >> pass >> 2. after >> (goto-char (treesit--navigate-thing (point) 1 'end = treesit-defun-type-regexp)) >>=20 >> def premain(): >> pass >> def main(): >> pass| >>=20 >> cursor in the end of the second function >>=20 >> 3. but if you move cursor to the beginning of pass >>=20 >> def premain(): >> |pass >> def main(): >> pass >>=20 >> 4. after >> (goto-char (treesit--navigate-thing (point) 1 'end = treesit-defun-type-regexp)) >>=20 >> def premain(): >> pass| >> def main(): >> pass >>=20 >> This behavior does not affected by the fix proposed in the first = message. >=20 > In the first case, treesit--navigate-thing returns a non-nil NEXT = node. And treesit=E2=80=94navigate will prioritize NEXT node over PARENT = node (because it assumes PARENT node always encloses NEXT node). Fixing = the original problem should fix this too. >=20 > Yuan I=E2=80=99ve pushed to master four new functions: treesit--thing-prev, = treesit--thing-next, treesit--thing-at, treesit-node-enclosed-p. And I = updated other functions to use the new functions. Now your original = example and the later ones should all work right. Yuan=