From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#74963: Ambiguous treesit named and anonymous nodes in ruby-ts-mode Date: Wed, 25 Dec 2024 19:39:28 +0200 Organization: LINKOV.NET Message-ID: <87msgjy8lj.fsf@mail.linkov.net> References: <87plox4mtp.fsf@masteringemacs.org> <87zflac68t.fsf@mail.linkov.net> <87jzcdlxdp.fsf@mail.linkov.net> <87o71jocgs.fsf@mail.linkov.net> <5192B278-66C0-48AE-B881-E57CCBB6B501@gmail.com> <87frmtbc9z.fsf@mail.linkov.net> <86bjxh1h86.fsf@gnu.org> <87y10l8h6k.fsf@mail.linkov.net> <87ldwl8g60.fsf@mail.linkov.net> <87wmg53rdj.fsf@mail.linkov.net> <87a5d0n651.fsf@mail.linkov.net> <87zfktphks.fsf@mail.linkov.net> <87ttb0rwni.fsf_-_@mail.linkov.net> <4DFCFBC8-A353-48F2-8257-D6CFB155A030@gmail.com> <875xn9j7d6.fsf@mail.linkov.net> <49EB9C70-DB16-4846-9646-F0C89B2D28D8@gmail.com> <87o7102oar.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7145"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) Cc: Dmitry Gutov , 74963@debbugs.gnu.org To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 25 18:51:25 2024 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 1tQVXY-0001jg-OO for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 25 Dec 2024 18:51:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tQVXF-0006n2-0r; Wed, 25 Dec 2024 12:51:05 -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 1tQVXC-0006lm-Lf for bug-gnu-emacs@gnu.org; Wed, 25 Dec 2024 12:51:02 -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 1tQVXC-0000Eg-D5 for bug-gnu-emacs@gnu.org; Wed, 25 Dec 2024 12:51:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=Sf6TMV2bYNYHt/HdtGzPTT57gu8D8qUm+vTx21EUdx8=; b=BTSJfgZFmRmK+rlOsypDYgx0PMTx75Qa0OtHsTeH7dKROlKfcSk/m/u2DcZtQAoI7IHDj+yyBLTO8zqp2dJuTDcM+I4aZlLzaju4Nv4Ao3/BHJuTf3u6/dqUhx7BlGPWAv2MJ40M55rwQveJjGyT6Z6FukAV2NikgfhcqxrQcOI7xmeez2A+8zhl/DscUjla+6YTB7HtxsGB9F9ij5tzYZsIpVT10Su+1kzqhZX77+kqtnXXN8bjmCPZ75sRWBiAqozEFyXrl8lMoNuqupV8xQK1aK5s/f41wTg5wAzR6jRu/Pa/JoSljTtBroiW6L+tWmuAgviN2HdGbRCQ5Jo+NA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tQVXC-0008MB-4t for bug-gnu-emacs@gnu.org; Wed, 25 Dec 2024 12:51:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 25 Dec 2024 17:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74963 X-GNU-PR-Package: emacs Original-Received: via spool by 74963-submit@debbugs.gnu.org id=B74963.173514905032098 (code B ref 74963); Wed, 25 Dec 2024 17:51:02 +0000 Original-Received: (at 74963) by debbugs.gnu.org; 25 Dec 2024 17:50:50 +0000 Original-Received: from localhost ([127.0.0.1]:38728 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tQVX0-0008Lc-3g for submit@debbugs.gnu.org; Wed, 25 Dec 2024 12:50:50 -0500 Original-Received: from relay5-d.mail.gandi.net ([217.70.183.197]:48295) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tQVWx-0008LH-DI for 74963@debbugs.gnu.org; Wed, 25 Dec 2024 12:50:47 -0500 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id 7D7DA1C0004; Wed, 25 Dec 2024 17:50:17 +0000 (UTC) In-Reply-To: (Yuan Fu's message of "Wed, 25 Dec 2024 01:11:32 -0800") X-GND-Sasl: juri@linkov.net 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:297733 Archived-At: >> Not sure if a possible flexibility is better than unintended matches. >> >> When the authors of a ts-mode carefully selected a list of named nodes to match, >> why treesit should try to match some random and unintended anonymous nodes? > > I don’t know and can’t prove how much the flexibility is worth, but the > cost on complexity is real. If everywhere else uses thing predicates as-is, > but sexp navigation auto-converts thing predicates into named predicate, > that’s a cognitive burden and a special case that’s guaranteed to trip > people over. > > OTOH, what’s the downside of wrapping the sexp predicate with (and named …), > if you only want named nodes to match? > > I just think the cost outweighs the benefit, if there is any to begin with. Actually, what I had in mind is not to enable named-only mode by default, but only to allow the authors of ts-modes to specify this condition. For example, if it will be possible to write (setq-local treesit-thing-settings `((typescript (sexp (and named ,(regexp-opt typescript-ts-mode--sexp-nodes 'symbols)))))) this should be fine. This is similar to how the authors of ts-modes decide whether to restrict matches to exact names by using "^...$" with regexp-opt. BTW, I'm thinking about adding such simple helper: (defun treesit-regexp-opt (strings) (concat "^" (regexp-opt strings) "$")) to use like this: (setq-local treesit-thing-settings `((typescript (sexp (and named ,(treesit-regexp-opt typescript-ts-mode--sexp-nodes))))))