From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#62086: 29.0.60; ruby-ts-mode regressions Date: Wed, 5 Apr 2023 17:58:38 +0300 Message-ID: <0bd5f2b8-6f0b-09d6-6240-38c742eca19f@yandex.ru> References: <86y1o5op2v.fsf@mail.linkov.net> <5abcf765-f8ce-9563-63aa-20c558409898@yandex.ru> <86cz4l7zjk.fsf@mail.linkov.net> <86ttxww12o.fsf@mail.linkov.net> <865yaakfs7.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6028"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Cc: 62086@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Apr 05 16:59:24 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 1pk4bb-0001KF-Hk for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 05 Apr 2023 16:59:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pk4bI-0001LJ-TB; Wed, 05 Apr 2023 10:59:04 -0400 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 1pk4bH-0001L4-8K for bug-gnu-emacs@gnu.org; Wed, 05 Apr 2023 10:59:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pk4bG-0008Fk-W5 for bug-gnu-emacs@gnu.org; Wed, 05 Apr 2023 10:59:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pk4bG-0006J5-IH for bug-gnu-emacs@gnu.org; Wed, 05 Apr 2023 10:59:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 05 Apr 2023 14:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62086 X-GNU-PR-Package: emacs Original-Received: via spool by 62086-submit@debbugs.gnu.org id=B62086.168070672924219 (code B ref 62086); Wed, 05 Apr 2023 14:59:02 +0000 Original-Received: (at 62086) by debbugs.gnu.org; 5 Apr 2023 14:58:49 +0000 Original-Received: from localhost ([127.0.0.1]:52410 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pk4b2-0006IZ-WE for submit@debbugs.gnu.org; Wed, 05 Apr 2023 10:58:49 -0400 Original-Received: from mail-wm1-f46.google.com ([209.85.128.46]:51793) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pk4b0-0006IK-Fy for 62086@debbugs.gnu.org; Wed, 05 Apr 2023 10:58:47 -0400 Original-Received: by mail-wm1-f46.google.com with SMTP id o32so21050072wms.1 for <62086@debbugs.gnu.org>; Wed, 05 Apr 2023 07:58:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680706720; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=tJtDUUVgDh1d28BrA6vxFldiq1mABxcCycN3n3AwbUU=; b=pPYORPBKV71m7XHnI8gviwEjEDbEbs2LB85VoXLYvrV0JNfJgsLQSLwAKCoe4tTEIG qxmy1BGJLgPQyLRwBHeYkmJNngxZrmrT0P6q270NeUDIz9Uz/isYiyfCCibpYVqWev7F c2r0/gOSQOOZnz0HS29xLyGg87qF36s0FgjssYPV3IuuBI+end5A3vPTd4vuedSGggfa g8YCY+1rqbRcRSi07AUs55s0x0tGPHBc/ROtY+D98/Lxn799aVBl/FeGM6wcAfEjCqB4 5314ce+Eg0a4AMTa0pdh51B8T2Hh1NlCdqMyPcdM1n0X7a3y8U7RPZFPM9NDpCeBXzsl XxnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680706720; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tJtDUUVgDh1d28BrA6vxFldiq1mABxcCycN3n3AwbUU=; b=VesVH9vhiPtWcQMBXb3pgF2w4m3S22pQo314NdpnO9HujuzsmbBppTaupeIAIQvGhp ybW35xaSQxdSFOJfE1DN2sImWcUJvnCxNgF8wCvdqEvUIS0M1OGOsVeVRkPc+pBWEL/P 6sRtGrJm7EGZg7HO3EU24QRDPuF8wITyblwMsgt548mOHPdNb73gKAGsSf9llTMyyLix qzOJFQXi79/4Hcwr3k/8IL5SRxQsm965xYOuAzqBUShOzW4A+wN3sNbmCZ8Ksnfp4Iz0 2dQFtUTSjllfJjx8YnXUkFXazYtBrmBt2dSSGfOPOUeWAFH7kGDBreTCAB8Lbo+0Oorz un3Q== X-Gm-Message-State: AAQBX9cCXsdeGPa5e0pqDfenVTf/QRzYIvgqgnaSUpZADmm5Hch9hz5+ x6bmf5fgxMyfMnQT3Qf18pA= X-Google-Smtp-Source: AKy350Z+QseVRveqjcmNnKuWr+kGUdmPY2iyPEmJmA7VFKNXzlTh+RLoVDfrKQRjSeQcn2lnmEtnyQ== X-Received: by 2002:a05:600c:3b0e:b0:3ee:f91:19aa with SMTP id m14-20020a05600c3b0e00b003ee0f9119aamr2140054wms.0.1680706720371; Wed, 05 Apr 2023 07:58:40 -0700 (PDT) Original-Received: from [192.168.1.2] ([31.216.80.60]) by smtp.googlemail.com with ESMTPSA id j1-20020a05600c1c0100b003f0548d00f1sm5496339wms.1.2023.04.05.07.58.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 Apr 2023 07:58:39 -0700 (PDT) Content-Language: en-US In-Reply-To: <865yaakfs7.fsf@mail.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:259271 Archived-At: On 05/04/2023 09:24, Juri Linkov wrote: >>> I wonder is it possible to fix more. >>> Many parens/brackets are still not matched in e.g. >>> test/lisp/progmodes/ruby-mode-resources/ruby.rb >>> such as parens in def argument list: >>> def test1(arg) >> >> This one was a regression from the addition of strict bos/eos anchors, now >> fixed. > > Maybe there are more types that now are not found, but probably easier > to add them one by one after testing than to try finding all of them in > https://github.com/tree-sitter/tree-sitter-ruby/blob/master/src/node-types.json > or in > https://github.com/tree-sitter/tree-sitter-ruby/blob/master/src/grammar.json Yep. And we've hopefully more-or-less covered the existing grammar at this point. >>> and in >>> method (a + b), >> >> When you say that this is broken, do you mean that these parens get jumped >> over unexpectedly (with forward-sexp movement ending at the end of the >> arguments list)? > > It seems natural to expect that when point is on an opening paren/bracket > then 'C-M-f' should jump to its closing pair. At least, this is more WYSIWYG. > >> This is an artefact of the implementation of treesit-forward-sexp. >> It might be possible to improve, but from a brief dig, it has some >> internal logic. So some care would need to be taken to decide which >> contract nedds changing. > > This is an example where explicit parens conflict with implicit parens. > Visible parens have the type "parenthesized_statements", but invisible > parens have the type "argument_list". Both start at the same position. > So maybe treesit-forward-sexp should prefer the former over the latter? > And in a similar case > > method [], > arg2 > > maybe "array" should take precedence over "argument_list". There is no mechanism for precedence in the current implementation. We can try ignoring the implicit parens in the parenless method calls, though. Like this: diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el index ddf2ee98c3b..cf8f1b0d315 100644 --- a/lisp/progmodes/ruby-ts-mode.el +++ b/lisp/progmodes/ruby-ts-mode.el @@ -1086,6 +1086,15 @@ ruby-ts--syntax-propertize (put-text-property pos (1+ pos) 'syntax-table (string-to-syntax "!")))))))) +(defun ruby-ts--sexp-p (node) + ;; Skip parenless calls (implicit parens are both non-obvious to the + ;; user, and might take over when we want to just over some physical + ;; parens/braces). + (or (not (equal (treesit-node-type node) + "argument_list")) + (equal (treesit-node-type (treesit-node-child node 0)) + "("))) + (defvar-keymap ruby-ts-mode-map :doc "Keymap used in Ruby mode" :parent prog-mode-map @@ -1114,6 +1123,7 @@ ruby-ts-mode (setq-local treesit-defun-type-regexp ruby-ts--method-regex) (setq-local treesit-sexp-type-regexp + (cons (rx bol (or "class" "module" @@ -1147,7 +1157,8 @@ ruby-ts-mode "instance_variable" "global_variable" ) - eol)) + eol) + #'ruby-ts--sexp-p)) ;; AFAIK, Ruby can not nest methods (setq-local treesit-defun-prefer-top-level nil) >>> Also square brackets are not matched by 'C-M-f' in >>> h[:key] >> >> And this, surprisingly, seems impossible to handle just using >> treesit-sexp-type-regexp. The brackets are present in the tree, but they >> are not at the ends of any node. So that will require some custom Lisp, >> I guess. > > This is the same problem that occurs in other places such as in "#{ddf}" > where only '#' but not '{' matches '}'. So adding "element_reference" > will allow to jump only from the beginning of an identifier. Right, except it's worse because the identifier is usually much longer than one character.