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 00:13:24 -0800 Message-ID: <64784314-7290-47E6-A0B3-897D2FDC4D78@gmail.com> References: <87pm0l1qtu.fsf@yandex.ru> <1D1196AE-7E7F-4887-B9FE-4EBA61042A4F@gmail.com> <2908341699475865@izsosstglkfltgsl.vla.yp-c.yandex.net> 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="17112"; 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 Thu Nov 09 09:14:49 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 1r10Bd-0004K5-9I for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 09 Nov 2023 09:14:49 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r10BG-0001mD-3X; Thu, 09 Nov 2023 03:14: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 1r10BD-0001lx-Su for bug-gnu-emacs@gnu.org; Thu, 09 Nov 2023 03:14: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 1r10BD-0006HG-Ka for bug-gnu-emacs@gnu.org; Thu, 09 Nov 2023 03:14:23 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r10Bq-0000BI-7G for bug-gnu-emacs@gnu.org; Thu, 09 Nov 2023 03:15: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: Thu, 09 Nov 2023 08:15: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.1699517666639 (code B ref 66989); Thu, 09 Nov 2023 08:15:02 +0000 Original-Received: (at 66989) by debbugs.gnu.org; 9 Nov 2023 08:14:26 +0000 Original-Received: from localhost ([127.0.0.1]:46752 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r10BG-0000AF-7i for submit@debbugs.gnu.org; Thu, 09 Nov 2023 03:14:26 -0500 Original-Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]:45333) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r10BC-00009y-Hj for 66989@debbugs.gnu.org; Thu, 09 Nov 2023 03:14:24 -0500 Original-Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-5b99bfca064so459119a12.3 for <66989@debbugs.gnu.org>; Thu, 09 Nov 2023 00:13:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699517617; x=1700122417; 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=eQS4lOOulGKfz+oPQwAPRQ6sklQCzHH7ROB/eb3QUwM=; b=HXDN1Og5fwyToM4x3miaaauvQwArP1XDvKRX5jDqQdEWkWG55RTk3XikptFutoP4Nj QOtsrvqqA7ny0Yyl6fb7R4AvFlIB/RONyrIpRo7uQfjOldvaetjl13H2lsuTVwLUZI2J 835WlzDFCQ0iWYrqG/2MM4UCvDDwnb9z4W4rYbuHGikBIiKnDSnxtxIszi9qU1wf1ryV brt291mSTdIKfLU0RTpa0IngIJR29HFVzdLqEqUx6F3p5HCNeYzRlGffDDvsd4gy9E0m ntDTyn//W+TPTYHkzokPDtQmLk0at9WSrvnADPR7WPeO6hP70tMSfW4WjdzmcWjKTMrg LEEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699517617; x=1700122417; 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=eQS4lOOulGKfz+oPQwAPRQ6sklQCzHH7ROB/eb3QUwM=; b=Pcwkxn3JEvTJBnae4jrh/uRynfxTqKzPbqL3wlD9zkaqzFw9geBD/tpG6HX1JB6UKB oPtR2l2uUzFr32SPREeEuOpyNr4T9mBM7vjTIyZ5ZR827e8qXmapUu9BXLkJbD6PYj5i Q4sGzaX0WpyQAQoSgUtXhYQX+uhT8Sl5ZLGZvS/tQM4U3440HIOro/kavwQCe1VwHbld gYFPsZOo4gjNJaESbosSpbiV/wm+XQn1LdnZ76blJVbXob0gf+cWFU2DF0N/NMdkXjCW SmzMIV3DjrWUggYDif8qfgMogjU5anp9ci9vkf5tuYFEbqI9mJn6/IOtbF5G5KHCKPCe 727g== X-Gm-Message-State: AOJu0YxW0AdE/zsJHKbAfvs4GP2Jxd6+XgZudfyZo2idNN6oALMzK1Bh LrsbBIdCSTUy4UDheDNyKLN1HewLfgI= X-Google-Smtp-Source: AGHT+IHL15OgOfF5FIUNcTHP23uu3PZ+/lsAUz/UWogD3n94xXGpdUKmQveFJk4ijpwCFdf7yLiurg== X-Received: by 2002:a17:902:d4c5:b0:1c9:ea71:8032 with SMTP id o5-20020a170902d4c500b001c9ea718032mr4545436plg.31.1699517616650; Thu, 09 Nov 2023 00:13:36 -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 s16-20020a170902ea1000b001bb0eebd90asm2905033plg.245.2023.11.09.00.13.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Nov 2023 00:13:36 -0800 (PST) In-Reply-To: <2908341699475865@izsosstglkfltgsl.vla.yp-c.yandex.net> 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:274037 Archived-At: > 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. 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 > 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. 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. Yuan=