From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Lo=C3=AFc_?= =?UTF-8?Q?Lema=C3=AEtre?= Newsgroups: gmane.emacs.bugs Subject: bug#66988: 30.0.50; treesit-forward-sexp not working properly in js-ts-mode and tsx-ts-mode Date: Sat, 11 Nov 2023 16:43:06 +0100 Message-ID: <102c3f66-4d74-49b9-a099-0c54e5d1c635@gmail.com> References: <9cf7d7d0-33a3-4c07-bd66-bc4c59bdfefb@gmail.com> <39b0057b-ac0c-8271-0fe2-f4deef7ae8d3@gutov.dev> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="------------3zN0kKWv67kudEL5Gi0YLJyw" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16502"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird To: Dmitry Gutov , 66988@debbugs.gnu.org, Yuan Fu , Theodor Thornhill Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 11 16:43: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 1r1q9D-0004Aq-FG for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 11 Nov 2023 16:43:47 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r1q8p-0004Ce-Mt; Sat, 11 Nov 2023 10:43:23 -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 1r1q8n-0004CG-Mg for bug-gnu-emacs@gnu.org; Sat, 11 Nov 2023 10:43:21 -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 1r1q8n-00079T-DQ for bug-gnu-emacs@gnu.org; Sat, 11 Nov 2023 10:43:21 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r1q9R-00025n-O9 for bug-gnu-emacs@gnu.org; Sat, 11 Nov 2023 10:44:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Lo=C3=AFc_?= =?UTF-8?Q?Lema=C3=AEtre?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 11 Nov 2023 15:44:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66988 X-GNU-PR-Package: emacs Original-Received: via spool by 66988-submit@debbugs.gnu.org id=B66988.16997174388024 (code B ref 66988); Sat, 11 Nov 2023 15:44:01 +0000 Original-Received: (at 66988) by debbugs.gnu.org; 11 Nov 2023 15:43:58 +0000 Original-Received: from localhost ([127.0.0.1]:53964 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r1q9N-00025M-LQ for submit@debbugs.gnu.org; Sat, 11 Nov 2023 10:43:58 -0500 Original-Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:49567) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r1q9L-000254-1R for 66988@debbugs.gnu.org; Sat, 11 Nov 2023 10:43:55 -0500 Original-Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-32d9d8284abso1890127f8f.3 for <66988@debbugs.gnu.org>; Sat, 11 Nov 2023 07:43:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699717388; x=1700322188; darn=debbugs.gnu.org; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=7DB2JawNbtaEmE9xXgifP+V41AkfRHKBnSKYfTGXHVk=; b=g06CEDt28tKYdDrMkmbYrMsow8v7GF6yE5qXAgenth+eybQOKzYGzBvxxl2cfa+Op0 u3oh1r8acbMjUeqlF5AZHpVBvA/+411bBfWQx7ouASJ9CihKvWhxmHM53xq6DAHGma5G k58ngLYxrfEg7LIpmuhlZvocRCxzcINLPWMuY+h0HYsjEHuuc8w7AzMpCEiV7a5O9Gx1 YCTGw7Q6BCYSt1zmiojH13uM2swaMGK+DHLSwEfvygCdsgMukPtWjQ2zZUs8WRl3wbES syh76qkQo0MnqkuxsKoZ3n247MUw03uXhwoFsvVSKeI1Hwkjc4gufZoVuMs17rthJHHp 1D7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699717388; x=1700322188; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=7DB2JawNbtaEmE9xXgifP+V41AkfRHKBnSKYfTGXHVk=; b=aa5ZZkkPddyXrhb2ubEFzonGBn9CXHoTKqqqR4RWvtn51FISPclR4y3dOeeeMsVoY3 Jkwfk+ce/8i1JwqolP2U0oXQsf82qMGsKr+OEMxmOtD2M2v16Dtefor3Cn2PUBvlR/2b qeWBEZuxmnbqIu7GWUTW/z1x5XrtbcNZZiBRGTupgOAVsbAXynxK/GgyMREmjPSDh8qv 2kuPfkev9RHbpO2s5zIU/GDtlM6anj6t43EI9TXtEqt42Hpe2JgNTkUaX779MJ6NcET2 0UVfvzFPNuNSvM5o9L5b/rRmW6wbh3rVarmVi2kEBAaOtmSRRxobrZgoJEJMXME5LWg+ I9eg== X-Gm-Message-State: AOJu0Yzu59GIMmmC+zI2Y4dBQT1fObHyW3nVejpTAk5sZ00EmzH9nZ5e crnwzR3vIAp2/tYHCL5/Tk0= X-Google-Smtp-Source: AGHT+IEvxbU9MfL21lak/SrxZ6D6i8PIi8jkJMFU1EZu1Lj6EpkJwVs1F1H130bnz2iWly6jfXYFXA== X-Received: by 2002:a5d:45c6:0:b0:31a:d450:c513 with SMTP id b6-20020a5d45c6000000b0031ad450c513mr1204998wrs.26.1699717388376; Sat, 11 Nov 2023 07:43:08 -0800 (PST) Original-Received: from ?IPV6:2a02:8428:2fa4:4b01:6dfd:3e89:8000:413c? ([2a02:8428:2fa4:4b01:6dfd:3e89:8000:413c]) by smtp.gmail.com with ESMTPSA id k16-20020adff290000000b00323287186aasm1693836wro.32.2023.11.11.07.43.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 11 Nov 2023 07:43:07 -0800 (PST) Content-Language: fr In-Reply-To: <39b0057b-ac0c-8271-0fe2-f4deef7ae8d3@gutov.dev> 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:274164 Archived-At: This is a multi-part message in MIME format. --------------3zN0kKWv67kudEL5Gi0YLJyw Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Thanks for the patch ! It fixes the bug. But unfortunatly, there is another similar bug in /treesit-forward-sexp/, that you can reproduce with that example: ({()}); /(treesit-forward-sexp)/ does not work as expected for both the opening parentheses and the brace. I have checked that it is not a regression due to the patch. That said,  the patch changes the results (that are not what we expect in any cases). Loïc Le 10/11/2023 à 02:41, Dmitry Gutov a écrit : > Hi! > > On 07/11/2023 16:56, Loïc Lemaître wrote: >> Hi Emacs team, >> >> Here the steps to demonstrate the bug : >> >> 1. Compile Emacs from master branch with tree-sitter support >> 2. Install javascript and tsx languages >> 3. Run Emacs >> 4. Create a new buffer >> 5. Turn major mode to either js-ts-mode or tsx-ts-mode >> 6. Past the following content into the buffer: >> ( >>   
>>   
>> ); >> 7. Place point before opening parenthese >> 8. M-x forward-sexp (which will call treesit-forward-sexp) >> >> => New position is right after the semi-colon instead of being before >> the semi-colon. >> >> Note that the bug disappear if the buffer content is changed for : >> const component = ( >>   
>>   
>> ); >> >> But previous content, while not being very usefull, is valid JSX, as >> far as I know. >> I use this syntax for unit test purpose, since it is very short. > > Thanks for the report. > > The patch below should fix it. > > Yuan, what do you think? A similar change (bos and eos anchors) might > be useful for other things and other modes. > > Alternatively, treesit-thing-settings could be interpreted to imply > full matches, then the code using it should not only match against the > regexps but also check that the entire string (type name) is matched. > > Also Cc'ing Theodor. > > diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el > index 5a669fdbd42..d81fa9ed322 100644 > --- a/lisp/progmodes/js.el > +++ b/lisp/progmodes/js.el > @@ -3843,6 +3843,7 @@ js--treesit-sexp-nodes >      "undefined" >      "arguments" >      "pair" > +    "parenthesized_expression" >      "jsx") >    "Nodes that designate sexps in JavaScript. >  See `treesit-thing-settings' for more information.") > @@ -3886,7 +3887,7 @@ js-ts-mode > >      (setq-local treesit-thing-settings >                  `((javascript > -                   (sexp ,(regexp-opt js--treesit-sexp-nodes)) > +                   (sexp ,(format "\\`%s\\'" (regexp-opt > js--treesit-sexp-nodes))) >                     (sentence ,(regexp-opt js--treesit-sentence-nodes)) >                     (text ,(regexp-opt '("comment" >                                          "template_string")))))) > --------------3zN0kKWv67kudEL5Gi0YLJyw Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Thanks for the patch ! It fixes the bug.
But unfortunatly, there is another similar bug in treesit-forward-sexp, that you can reproduce with that example:
({(<A></A>)});

(treesit-forward-sexp) does not work as expected for both the opening parentheses and the brace.

I have checked that it is not a regression due to the patch. That said,  the patch changes the results (that are not what we expect in any cases).

Loïc

Le 10/11/2023 à 02:41, Dmitry Gutov a écrit :
Hi!

On 07/11/2023 16:56, Loïc Lemaître wrote:
Hi Emacs team,

Here the steps to demonstrate the bug :

1. Compile Emacs from master branch with tree-sitter support
2. Install javascript and tsx languages
3. Run Emacs
4. Create a new buffer
5. Turn major mode to either js-ts-mode or tsx-ts-mode
6. Past the following content into the buffer:
(
   <div>
   </div>
);
7. Place point before opening parenthese
8. M-x forward-sexp (which will call treesit-forward-sexp)

=> New position is right after the semi-colon instead of being before the semi-colon.

Note that the bug disappear if the buffer content is changed for :
const component = (
   <div>
   </div>
);

But previous content, while not being very usefull, is valid JSX, as far as I know.
I use this syntax for unit test purpose, since it is very short.

Thanks for the report.

The patch below should fix it.

Yuan, what do you think? A similar change (bos and eos anchors) might be useful for other things and other modes.

Alternatively, treesit-thing-settings could be interpreted to imply full matches, then the code using it should not only match against the regexps but also check that the entire string (type name) is matched.

Also Cc'ing Theodor.

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 5a669fdbd42..d81fa9ed322 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3843,6 +3843,7 @@ js--treesit-sexp-nodes
     "undefined"
     "arguments"
     "pair"
+    "parenthesized_expression"
     "jsx")
   "Nodes that designate sexps in JavaScript.
 See `treesit-thing-settings' for more information.")
@@ -3886,7 +3887,7 @@ js-ts-mode

     (setq-local treesit-thing-settings
                 `((javascript
-                   (sexp ,(regexp-opt js--treesit-sexp-nodes))
+                   (sexp ,(format "\\`%s\\'" (regexp-opt js--treesit-sexp-nodes)))
                    (sentence ,(regexp-opt js--treesit-sentence-nodes))
                    (text ,(regexp-opt '("comment"
                                         "template_string"))))))

--------------3zN0kKWv67kudEL5Gi0YLJyw--