GNU bug report logs - #68054
[PATCH] Add tree-sitter indent rule for lexical decls in js/typescript

Previous Next

Package: emacs;

Reported by: Noah Peart <noah.v.peart <at> gmail.com>

Date: Wed, 27 Dec 2023 06:22:01 UTC

Severity: wishlist

Tags: patch

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 68054 in the body.
You can then email your comments to 68054 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Wed, 27 Dec 2023 06:22:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Noah Peart <noah.v.peart <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 27 Dec 2023 06:22:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Noah Peart <noah.v.peart <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Add tree-sitter indent rule for lexical decls in js/typescript
Date: Wed, 27 Dec 2023 01:21:05 -0500
[Message part 1 (text/plain, inline)]
Tags: patch

* Bug: `js-ts-mode` and `typescript-ts-mode` are missing indentation
rules for lexical declarations that span multiple lines.

Recipe to reproduce:

Using the following function to configure js-ts-mode and indent the
buffer:

    (defun try-indent ()
      (interactive)
      (js-ts-mode)
      (setq-local indent-tabs-mode nil)
      (setq-local js-indent-level 4)
      (indent-region (point-min) (point-max)))

Add the following example to a buffer and call `try-indent`.

    let foo = 1,
    bar = 2; // no indent rule matches this line

No indentation is applied to the second line.

This patch adds a simple indentation rules for `js-ts-mode` and
`typescript-ts-mode` to handle the multi-line lexical declarations.


In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.33, cairo version 1.16.0) of 2023-12-26 built on nverno-XPS-8940
Repository revision: d376462c7183752bf44b9bd20bf5020fe7eaf75a
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101004
System Description: Ubuntu 22.04.3 LTS

Configured using:
 'configure --prefix=/usr/local --with-modules --with-tree-sitter
--with-threads --with-x-toolkit=gtk3 --with-xwidgets --with-gnutls
--with-json --with-mailutils --with-jpeg --with-png --with-rsvg
--with-tiff --with-xml2 --with-xpm --with-imagemagick CC=gcc-12
CXX=gcc-12'
[Message part 2 (text/html, inline)]
[js-ts-indent-decls.patch (text/x-patch, attachment)]

Severity set to 'wishlist' from 'normal' Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 27 Dec 2023 21:39:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Sat, 30 Dec 2023 04:25:01 GMT) Full text and rfc822 format available.

Message #10 received at 68054 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Noah Peart <noah.v.peart <at> gmail.com>
Cc: 68054 <at> debbugs.gnu.org
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Fri, 29 Dec 2023 20:24:13 -0800

> On Dec 26, 2023, at 10:21 PM, Noah Peart <noah.v.peart <at> gmail.com> wrote:
> 
> Tags: patch
> 
> * Bug: `js-ts-mode` and `typescript-ts-mode` are missing indentation
> rules for lexical declarations that span multiple lines.
> 
> Recipe to reproduce:
> 
> Using the following function to configure js-ts-mode and indent the
> buffer:
> 
>     (defun try-indent ()
>       (interactive)
>       (js-ts-mode)
>       (setq-local indent-tabs-mode nil)
>       (setq-local js-indent-level 4)
>       (indent-region (point-min) (point-max)))
> 
> Add the following example to a buffer and call `try-indent`.
> 
>     let foo = 1,
>     bar = 2; // no indent rule matches this line
> 
> No indentation is applied to the second line.
> 
> This patch adds a simple indentation rules for `js-ts-mode` and
> `typescript-ts-mode` to handle the multi-line lexical declarations.

Thanks, and sorry for not seeing this. I’ll take a look tonight.

Yuan



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Sat, 30 Dec 2023 20:32:01 GMT) Full text and rfc822 format available.

Message #13 received at 68054 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Noah Peart <noah.v.peart <at> gmail.com>
Cc: 68054 <at> debbugs.gnu.org
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Sat, 30 Dec 2023 12:31:20 -0800

> On Dec 29, 2023, at 8:24 PM, Yuan Fu <casouri <at> gmail.com> wrote:
> 
> 
> 
>> On Dec 26, 2023, at 10:21 PM, Noah Peart <noah.v.peart <at> gmail.com> wrote:
>> 
>> Tags: patch
>> 
>> * Bug: `js-ts-mode` and `typescript-ts-mode` are missing indentation
>> rules for lexical declarations that span multiple lines.
>> 
>> Recipe to reproduce:
>> 
>> Using the following function to configure js-ts-mode and indent the
>> buffer:
>> 
>>    (defun try-indent ()
>>      (interactive)
>>      (js-ts-mode)
>>      (setq-local indent-tabs-mode nil)
>>      (setq-local js-indent-level 4)
>>      (indent-region (point-min) (point-max)))
>> 
>> Add the following example to a buffer and call `try-indent`.
>> 
>>    let foo = 1,
>>    bar = 2; // no indent rule matches this line
>> 
>> No indentation is applied to the second line.
>> 
>> This patch adds a simple indentation rules for `js-ts-mode` and
>> `typescript-ts-mode` to handle the multi-line lexical declarations.

It seems that js-mode indents bar to align with foo, rather than indenting one level. I feel that we should do the same, WDYT?

Yuan



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Sun, 31 Dec 2023 00:32:02 GMT) Full text and rfc822 format available.

Message #16 received at 68054 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dmitry <at> gutov.dev>
To: Yuan Fu <casouri <at> gmail.com>, Noah Peart <noah.v.peart <at> gmail.com>
Cc: 68054 <at> debbugs.gnu.org
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Sun, 31 Dec 2023 02:31:46 +0200
On 30/12/2023 22:31, Yuan Fu wrote:
> 
>> On Dec 29, 2023, at 8:24 PM, Yuan Fu<casouri <at> gmail.com>  wrote:
>>
>>
>>
>>> On Dec 26, 2023, at 10:21 PM, Noah Peart<noah.v.peart <at> gmail.com>  wrote:
>>>
>>> Tags: patch
>>>
>>> * Bug: `js-ts-mode` and `typescript-ts-mode` are missing indentation
>>> rules for lexical declarations that span multiple lines.
>>>
>>> Recipe to reproduce:
>>>
>>> Using the following function to configure js-ts-mode and indent the
>>> buffer:
>>>
>>>     (defun try-indent ()
>>>       (interactive)
>>>       (js-ts-mode)
>>>       (setq-local indent-tabs-mode nil)
>>>       (setq-local js-indent-level 4)
>>>       (indent-region (point-min) (point-max)))
>>>
>>> Add the following example to a buffer and call `try-indent`.
>>>
>>>     let foo = 1,
>>>     bar = 2; // no indent rule matches this line
>>>
>>> No indentation is applied to the second line.
>>>
>>> This patch adds a simple indentation rules for `js-ts-mode` and
>>> `typescript-ts-mode` to handle the multi-line lexical declarations.
> It seems that js-mode indents bar to align with foo, rather than indenting one level. I feel that we should do the same, WDYT?

Yes, please. This also makes a difference when the variables are 
declared with 'const' instead of 'let'.

We should also support 'var' declarations: the parent node type to match 
against is "variable_declaration".




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Sun, 31 Dec 2023 05:36:01 GMT) Full text and rfc822 format available.

Message #19 received at 68054 <at> debbugs.gnu.org (full text, mbox):

From: Noah Peart <noah.v.peart <at> gmail.com>
To: Dmitry Gutov <dmitry <at> gutov.dev>
Cc: Yuan Fu <casouri <at> gmail.com>, 68054 <at> debbugs.gnu.org
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Sun, 31 Dec 2023 00:35:39 -0500
[Message part 1 (text/plain, inline)]
Yea, I agree that would be better - would you align on start the variable
names, or '=' like
`c-lineup-assignments`?

On Sat, Dec 30, 2023 at 7:31 PM Dmitry Gutov <dmitry <at> gutov.dev> wrote:

> On 30/12/2023 22:31, Yuan Fu wrote:
> >
> >> On Dec 29, 2023, at 8:24 PM, Yuan Fu<casouri <at> gmail.com>  wrote:
> >>
> >>
> >>
> >>> On Dec 26, 2023, at 10:21 PM, Noah Peart<noah.v.peart <at> gmail.com>
> wrote:
> >>>
> >>> Tags: patch
> >>>
> >>> * Bug: `js-ts-mode` and `typescript-ts-mode` are missing indentation
> >>> rules for lexical declarations that span multiple lines.
> >>>
> >>> Recipe to reproduce:
> >>>
> >>> Using the following function to configure js-ts-mode and indent the
> >>> buffer:
> >>>
> >>>     (defun try-indent ()
> >>>       (interactive)
> >>>       (js-ts-mode)
> >>>       (setq-local indent-tabs-mode nil)
> >>>       (setq-local js-indent-level 4)
> >>>       (indent-region (point-min) (point-max)))
> >>>
> >>> Add the following example to a buffer and call `try-indent`.
> >>>
> >>>     let foo = 1,
> >>>     bar = 2; // no indent rule matches this line
> >>>
> >>> No indentation is applied to the second line.
> >>>
> >>> This patch adds a simple indentation rules for `js-ts-mode` and
> >>> `typescript-ts-mode` to handle the multi-line lexical declarations.
> > It seems that js-mode indents bar to align with foo, rather than
> indenting one level. I feel that we should do the same, WDYT?
>
> Yes, please. This also makes a difference when the variables are
> declared with 'const' instead of 'let'.
>
> We should also support 'var' declarations: the parent node type to match
> against is "variable_declaration".
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Sun, 31 Dec 2023 13:42:02 GMT) Full text and rfc822 format available.

Message #22 received at 68054 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dmitry <at> gutov.dev>
To: Noah Peart <noah.v.peart <at> gmail.com>
Cc: Yuan Fu <casouri <at> gmail.com>, 68054 <at> debbugs.gnu.org
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Sun, 31 Dec 2023 15:41:44 +0200
On 31/12/2023 07:35, Noah Peart wrote:
> Yea, I agree that would be better - would you align on start the 
> variable names, or '=' like
> `c-lineup-assignments`?

Like js-mode would be good.

I'm not familiar with c-lineup-assignments, but we could add different 
variations later.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Mon, 01 Jan 2024 04:57:01 GMT) Full text and rfc822 format available.

Message #25 received at 68054 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Dmitry Gutov <dmitry <at> gutov.dev>
Cc: Noah Peart <noah.v.peart <at> gmail.com>, 68054 <at> debbugs.gnu.org
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Sun, 31 Dec 2023 20:56:04 -0800

> On Dec 31, 2023, at 5:41 AM, Dmitry Gutov <dmitry <at> gutov.dev> wrote:
> 
> On 31/12/2023 07:35, Noah Peart wrote:
>> Yea, I agree that would be better - would you align on start the variable names, or '=' like
>> `c-lineup-assignments`?
> 
> Like js-mode would be good.
> 
> I'm not familiar with c-lineup-assignments, but we could add different variations later.

Also, if you are feeling adventurous, I noticed that the second variable in a lexical_declaration isn’t fontified in variable-name-face. It’d be nice to fix that as well.

Yuan



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Wed, 17 Apr 2024 20:22:02 GMT) Full text and rfc822 format available.

Message #28 received at 68054 <at> debbugs.gnu.org (full text, mbox):

From: Noah Peart <noah.v.peart <at> gmail.com>
To: Yuan Fu <casouri <at> gmail.com>
Cc: Dmitry Gutov <dmitry <at> gutov.dev>, 68054 <at> debbugs.gnu.org
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Wed, 17 Apr 2024 13:21:10 -0700
[Message part 1 (text/plain, inline)]
Sorry, I forgot about this. I've just added a rule to align the
variable_declarators
in let, var, and const declarations, but I need some feedback about the
indentation
for values in the variable_declarators following dangling '='.

For example, which of the following would be preferable?

1) indent the dangling values with respect to start of the declaration

    const a =
        (x: string): string => {
            return x + x;
        },
          bbb =
        {
            "x": 0
        },
          cccc =
        1,
          ddddd = 0;

2) indent them with respect to the start of the variable_declarator

    const a =
              (x: string): string => {
                  return x + x;
              },
          bbb =
              {
                  "x": 0
              },
          cccc =
              1,
          ddddd = 0;

3) align with the variable declarators (this is the same as js-mode)

    const a =
          (x: string): string => {
              return x + x;
          },
          bbb =
          {
              "x": 0
          },
          cccc =
          1,
          ddddd = 0;

I've attached a patch with with the rules for the 3 options here.

On Sun, Dec 31, 2023 at 8:56 PM Yuan Fu <casouri <at> gmail.com> wrote:

>
>
> > On Dec 31, 2023, at 5:41 AM, Dmitry Gutov <dmitry <at> gutov.dev> wrote:
> >
> > On 31/12/2023 07:35, Noah Peart wrote:
> >> Yea, I agree that would be better - would you align on start the
> variable names, or '=' like
> >> `c-lineup-assignments`?
> >
> > Like js-mode would be good.
> >
> > I'm not familiar with c-lineup-assignments, but we could add different
> variations later.
>
> Also, if you are feeling adventurous, I noticed that the second variable
> in a lexical_declaration isn’t fontified in variable-name-face. It’d be
> nice to fix that as well.
>
> Yuan
[Message part 2 (text/html, inline)]
[typescript-ts-decl-indent.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Tue, 23 Apr 2024 05:08:02 GMT) Full text and rfc822 format available.

Message #31 received at 68054 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Noah Peart <noah.v.peart <at> gmail.com>
Cc: Dmitry Gutov <dmitry <at> gutov.dev>, 68054 <at> debbugs.gnu.org
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Mon, 22 Apr 2024 22:07:20 -0700

> On Apr 17, 2024, at 1:21 PM, Noah Peart <noah.v.peart <at> gmail.com> wrote:
> 
> Sorry, I forgot about this. I've just added a rule to align the variable_declarators
> in let, var, and const declarations, but I need some feedback about the indentation
> for values in the variable_declarators following dangling '='.

Thanks!

> 
> For example, which of the following would be preferable?
> 
> 1) indent the dangling values with respect to start of the declaration
> 
>     const a =
>         (x: string): string => {
>             return x + x;
>         },
>           bbb =
>         {
>             "x": 0
>         },
>           cccc =
>         1,
>           ddddd = 0;
>   
> 2) indent them with respect to the start of the variable_declarator
> 
>     const a =
>               (x: string): string => {
>                   return x + x;
>               },
>           bbb =
>               {
>                   "x": 0
>               },
>           cccc =
>               1,
>           ddddd = 0;
> 
> 3) align with the variable declarators (this is the same as js-mode)
> 
>     const a =
>           (x: string): string => {
>               return x + x;
>           },
>           bbb =
>           {
>               "x": 0
>           },
>           cccc =
>           1,
>           ddddd = 0;
> 
> I've attached a patch with with the rules for the 3 options here.

I don’t really know what’s the convention, if there is one. Maybe Dmitry has better idea. Personally I like option 1.

Yuan



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Wed, 24 Apr 2024 00:16:05 GMT) Full text and rfc822 format available.

Message #34 received at 68054 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dmitry <at> gutov.dev>
To: Yuan Fu <casouri <at> gmail.com>, Noah Peart <noah.v.peart <at> gmail.com>
Cc: 68054 <at> debbugs.gnu.org
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Wed, 24 Apr 2024 03:15:08 +0300
On 23/04/2024 08:07, Yuan Fu wrote:
>> 1) indent the dangling values with respect to start of the declaration
>>
>>      const a =
>>          (x: string): string => {
>>              return x + x;
>>          },
>>            bbb =
>>          {
>>              "x": 0
>>          },
>>            cccc =
>>          1,
>>            ddddd = 0;
>>    
>> 2) indent them with respect to the start of the variable_declarator
>>
>>      const a =
>>                (x: string): string => {
>>                    return x + x;
>>                },
>>            bbb =
>>                {
>>                    "x": 0
>>                },
>>            cccc =
>>                1,
>>            ddddd = 0;
>>
>> 3) align with the variable declarators (this is the same as js-mode)
>>
>>      const a =
>>            (x: string): string => {
>>                return x + x;
>>            },
>>            bbb =
>>            {
>>                "x": 0
>>            },
>>            cccc =
>>            1,
>>            ddddd = 0;
>>
>> I've attached a patch with with the rules for the 3 options here.
> I don’t really know what’s the convention, if there is one. Maybe Dmitry has better idea. Personally I like option 1.

What js-mode does (looks like 3) shouldn't be too bad, but I wouldn't 
mind an extra indentation level for such cases, too (example 2).

This seems like a rare enough case, so it probably doesn't matter too 
much, so I'd suggest picking one style and implementing it, and then 
adjusting based on user feedback later.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Wed, 24 Apr 2024 02:38:10 GMT) Full text and rfc822 format available.

Message #37 received at 68054 <at> debbugs.gnu.org (full text, mbox):

From: Noah Peart <noah.v.peart <at> gmail.com>
To: Dmitry Gutov <dmitry <at> gutov.dev>
Cc: Yuan Fu <casouri <at> gmail.com>, 68054 <at> debbugs.gnu.org
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Tue, 23 Apr 2024 19:36:45 -0700
[Message part 1 (text/plain, inline)]
> What js-mode does (looks like 3) shouldn't be too bad, but I wouldn't
mind an extra indentation level for such cases, too (example 2).

The problem I found with option 2/3 was cases like the following (which
also seem like the most common) where I expect the start of
the function be indented according to `typescript-ts-mode-indent-offset`,
not with the declaration keyword "const" as in `js-mode` (and option 3).

    const someFuncWithReallyLongName =
      async (x: number, y: number, z: number): Promise<void> => {
        // ...
      };

> This seems like a rare enough case, so it probably doesn't matter too
much, so I'd suggest picking one style and implementing it, and then
adjusting based on user feedback later.

I've attached a patch implementing option 1 for now (with a test), but
I'm happy to change the style whenever.

Thanks!

On Tue, Apr 23, 2024 at 5:15 PM Dmitry Gutov <dmitry <at> gutov.dev> wrote:

> On 23/04/2024 08:07, Yuan Fu wrote:
> >> 1) indent the dangling values with respect to start of the declaration
> >>
> >>      const a =
> >>          (x: string): string => {
> >>              return x + x;
> >>          },
> >>            bbb =
> >>          {
> >>              "x": 0
> >>          },
> >>            cccc =
> >>          1,
> >>            ddddd = 0;
> >>
> >> 2) indent them with respect to the start of the variable_declarator
> >>
> >>      const a =
> >>                (x: string): string => {
> >>                    return x + x;
> >>                },
> >>            bbb =
> >>                {
> >>                    "x": 0
> >>                },
> >>            cccc =
> >>                1,
> >>            ddddd = 0;
> >>
> >> 3) align with the variable declarators (this is the same as js-mode)
> >>
> >>      const a =
> >>            (x: string): string => {
> >>                return x + x;
> >>            },
> >>            bbb =
> >>            {
> >>                "x": 0
> >>            },
> >>            cccc =
> >>            1,
> >>            ddddd = 0;
> >>
> >> I've attached a patch with with the rules for the 3 options here.
> > I don’t really know what’s the convention, if there is one. Maybe Dmitry
> has better idea. Personally I like option 1.
>
> What js-mode does (looks like 3) shouldn't be too bad, but I wouldn't
> mind an extra indentation level for such cases, too (example 2).
>
> This seems like a rare enough case, so it probably doesn't matter too
> much, so I'd suggest picking one style and implementing it, and then
> adjusting based on user feedback later.
>
[Message part 2 (text/html, inline)]
[0001-Add-typescript-ts-mode-indentation-for-multi-assignm.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Wed, 24 Apr 2024 23:16:08 GMT) Full text and rfc822 format available.

Message #40 received at 68054 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dmitry <at> gutov.dev>
To: Noah Peart <noah.v.peart <at> gmail.com>
Cc: Yuan Fu <casouri <at> gmail.com>, 68054 <at> debbugs.gnu.org
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Thu, 25 Apr 2024 02:15:16 +0300
On 24/04/2024 05:36, Noah Peart wrote:
>  > What js-mode does (looks like 3) shouldn't be too bad, but I wouldn't
> mind an extra indentation level for such cases, too (example 2).
> 
> The problem I found with option 2/3 was cases like the following (which
> also seem like the most common) where I expect the start of
> the function be indented according to `typescript-ts-mode-indent-offset`,
> not with the declaration keyword "const" as in `js-mode` (and option 3).
> 
>      const someFuncWithReallyLongName =
>        async (x: number, y: number, z: number): Promise<void> => {
>          // ...
>        };

I don't know, in my understanding the line break after the "=" (or its 
absence) is usually a good enough look to choose between indentation 
offsets for a given statement. I.e. with the break after = it would be 
indented deeply, and without it (keeping "async" on the first line) the 
body would have the same base indentation as the "const" statement.

Though of course some users like it differently anyway.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Thu, 25 Apr 2024 22:50:08 GMT) Full text and rfc822 format available.

Message #43 received at 68054 <at> debbugs.gnu.org (full text, mbox):

From: Noah Peart <noah.v.peart <at> gmail.com>
To: Dmitry Gutov <dmitry <at> gutov.dev>
Cc: Yuan Fu <casouri <at> gmail.com>, 68054 <at> debbugs.gnu.org
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Thu, 25 Apr 2024 15:48:37 -0700
[Message part 1 (text/plain, inline)]
Ok, I can make a patch for option 3 (the same as js-mode) instead. It's
implementation is the simplest also.  Would that work?

Thanks

On Wed, Apr 24, 2024 at 4:15 PM Dmitry Gutov <dmitry <at> gutov.dev> wrote:

> On 24/04/2024 05:36, Noah Peart wrote:
> >  > What js-mode does (looks like 3) shouldn't be too bad, but I wouldn't
> > mind an extra indentation level for such cases, too (example 2).
> >
> > The problem I found with option 2/3 was cases like the following (which
> > also seem like the most common) where I expect the start of
> > the function be indented according to `typescript-ts-mode-indent-offset`,
> > not with the declaration keyword "const" as in `js-mode` (and option 3).
> >
> >      const someFuncWithReallyLongName =
> >        async (x: number, y: number, z: number): Promise<void> => {
> >          // ...
> >        };
>
> I don't know, in my understanding the line break after the "=" (or its
> absence) is usually a good enough look to choose between indentation
> offsets for a given statement. I.e. with the break after = it would be
> indented deeply, and without it (keeping "async" on the first line) the
> body would have the same base indentation as the "const" statement.
>
> Though of course some users like it differently anyway.
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Fri, 26 Apr 2024 01:07:06 GMT) Full text and rfc822 format available.

Message #46 received at 68054 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dmitry <at> gutov.dev>
To: Noah Peart <noah.v.peart <at> gmail.com>
Cc: Yuan Fu <casouri <at> gmail.com>, 68054 <at> debbugs.gnu.org
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Fri, 26 Apr 2024 04:06:05 +0300
On 26/04/2024 01:48, Noah Peart wrote:
> Ok, I can make a patch for option 3 (the same as js-mode) instead. It's
> implementation is the simplest also.  Would that work?

I'd be okay with it, yes, thank you. If only because it's good to have 
similar defaults in both modes, and evolve them together until one is 
deprecated.

FTR, the option more in line with my previous explanation would be 
option 3, I think. Rhere's no real need to implement it right now, I 
guess, but for illustration:

const a =
        (x: string): string => {
          return x + x;
        },
      bbb =
        {
          "x": 0
        },
      cccc =
        1,
      ddddd = 0;

const bbb =
      {
        "x": 0
      }, a = (x: string): string => {
        return x + x;
      },
      bbb = {
        "x": 0
      },
      cccc = 1,
      ddddd = 0;

js-mode also has by necessity the below exceptions: when the first 
variable's value starts on the same line, and it's multiline (usually 
that means that the same line ends with a {), then its indentation level 
goes back to the statement, not to the "const" keyword:

const a = (x: string): string => {
  return x + x;
}

var bbb = {
  "x": 0
}

This is basically to support the non-multivar declarations better. 
js-ts-mode now has the exact same indentation; these cases might come up 
when you change how the first two cases indent, however.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Thu, 02 May 2024 13:27:01 GMT) Full text and rfc822 format available.

Message #49 received at 68054 <at> debbugs.gnu.org (full text, mbox):

From: Noah Peart <noah.v.peart <at> gmail.com>
To: Dmitry Gutov <dmitry <at> gutov.dev>
Cc: Yuan Fu <casouri <at> gmail.com>, 68054 <at> debbugs.gnu.org
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Thu, 2 May 2024 06:26:00 -0700
[Message part 1 (text/plain, inline)]
Ok, here is an updated patch for option 3.  The indentation looks like the
examples
you've provided - it's the same indentation as in js-mode for these cases.


On Thu, Apr 25, 2024 at 6:06 PM Dmitry Gutov <dmitry <at> gutov.dev> wrote:

> On 26/04/2024 01:48, Noah Peart wrote:
> > Ok, I can make a patch for option 3 (the same as js-mode) instead. It's
> > implementation is the simplest also.  Would that work?
>
> I'd be okay with it, yes, thank you. If only because it's good to have
> similar defaults in both modes, and evolve them together until one is
> deprecated.
>
> FTR, the option more in line with my previous explanation would be
> option 3, I think. Rhere's no real need to implement it right now, I
> guess, but for illustration:
>
> const a =
>          (x: string): string => {
>            return x + x;
>          },
>        bbb =
>          {
>            "x": 0
>          },
>        cccc =
>          1,
>        ddddd = 0;
>
> const bbb =
>        {
>          "x": 0
>        }, a = (x: string): string => {
>          return x + x;
>        },
>        bbb = {
>          "x": 0
>        },
>        cccc = 1,
>        ddddd = 0;
>
> js-mode also has by necessity the below exceptions: when the first
> variable's value starts on the same line, and it's multiline (usually
> that means that the same line ends with a {), then its indentation level
> goes back to the statement, not to the "const" keyword:
>
> const a = (x: string): string => {
>    return x + x;
> }
>
> var bbb = {
>    "x": 0
> }
>
> This is basically to support the non-multivar declarations better.
> js-ts-mode now has the exact same indentation; these cases might come up
> when you change how the first two cases indent, however.
>
[Message part 2 (text/html, inline)]
[0001-Add-typescript-ts-mode-indentation-for-multi-assignm.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Thu, 02 May 2024 13:40:02 GMT) Full text and rfc822 format available.

Message #52 received at 68054 <at> debbugs.gnu.org (full text, mbox):

From: Noah Peart <noah.v.peart <at> gmail.com>
To: Dmitry Gutov <dmitry <at> gutov.dev>
Cc: Yuan Fu <casouri <at> gmail.com>, 68054 <at> debbugs.gnu.org
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Thu, 2 May 2024 06:38:57 -0700
[Message part 1 (text/plain, inline)]
> js-ts-mode now has the exact same indentation

I'm not sure what you meant by this - did you mean js-ts-mode has
the same indentation for non-multivar declarations as the examples
shown above? js-ts-mode is still missing indentation rules for multiple
decl statements.
The patch would work for js-ts-mode as well, but I didn't want to copy the
code between the files.

So much of the grammar is shared between js-ts-mode and
typescript-ts-mode, it might be worth combining - neovim uses an ecma
grammar
from which they both inherit.

On Thu, May 2, 2024 at 6:26 AM Noah Peart <noah.v.peart <at> gmail.com> wrote:

> Ok, here is an updated patch for option 3.  The indentation looks like the
> examples
> you've provided - it's the same indentation as in js-mode for these cases.
>
>
> On Thu, Apr 25, 2024 at 6:06 PM Dmitry Gutov <dmitry <at> gutov.dev> wrote:
>
>> On 26/04/2024 01:48, Noah Peart wrote:
>> > Ok, I can make a patch for option 3 (the same as js-mode) instead. It's
>> > implementation is the simplest also.  Would that work?
>>
>> I'd be okay with it, yes, thank you. If only because it's good to have
>> similar defaults in both modes, and evolve them together until one is
>> deprecated.
>>
>> FTR, the option more in line with my previous explanation would be
>> option 3, I think. Rhere's no real need to implement it right now, I
>> guess, but for illustration:
>>
>> const a =
>>          (x: string): string => {
>>            return x + x;
>>          },
>>        bbb =
>>          {
>>            "x": 0
>>          },
>>        cccc =
>>          1,
>>        ddddd = 0;
>>
>> const bbb =
>>        {
>>          "x": 0
>>        }, a = (x: string): string => {
>>          return x + x;
>>        },
>>        bbb = {
>>          "x": 0
>>        },
>>        cccc = 1,
>>        ddddd = 0;
>>
>> js-mode also has by necessity the below exceptions: when the first
>> variable's value starts on the same line, and it's multiline (usually
>> that means that the same line ends with a {), then its indentation level
>> goes back to the statement, not to the "const" keyword:
>>
>> const a = (x: string): string => {
>>    return x + x;
>> }
>>
>> var bbb = {
>>    "x": 0
>> }
>>
>> This is basically to support the non-multivar declarations better.
>> js-ts-mode now has the exact same indentation; these cases might come up
>> when you change how the first two cases indent, however.
>>
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Sat, 18 May 2024 08:31:02 GMT) Full text and rfc822 format available.

Message #55 received at 68054 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Noah Peart <noah.v.peart <at> gmail.com>
Cc: dmitry <at> gutov.dev, casouri <at> gmail.com, 68054 <at> debbugs.gnu.org
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Sat, 18 May 2024 11:29:57 +0300
> Cc: Yuan Fu <casouri <at> gmail.com>, 68054 <at> debbugs.gnu.org
> From: Noah Peart <noah.v.peart <at> gmail.com>
> Date: Thu, 2 May 2024 06:38:57 -0700
> 
> > js-ts-mode now has the exact same indentation
> 
> I'm not sure what you meant by this - did you mean js-ts-mode has
> the same indentation for non-multivar declarations as the examples
> shown above? js-ts-mode is still missing indentation rules for multiple decl statements.
> The patch would work for js-ts-mode as well, but I didn't want to copy the
> code between the files. 
> 
> So much of the grammar is shared between js-ts-mode and
> typescript-ts-mode, it might be worth combining - neovim uses an ecma grammar
> from which they both inherit.

Not sure what is the conclusion here.  Are there any objections to
installing Noah's last patch?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Sun, 09 Jun 2024 02:50:02 GMT) Full text and rfc822 format available.

Message #58 received at 68054 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dmitry <at> gutov.dev>
To: Noah Peart <noah.v.peart <at> gmail.com>
Cc: Yuan Fu <casouri <at> gmail.com>, 68054 <at> debbugs.gnu.org
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Sun, 9 Jun 2024 05:48:57 +0300
On 02/05/2024 16:26, Noah Peart wrote:
> Ok, here is an updated patch for option 3.  The indentation looks like 
> the examples
> you've provided - it's the same indentation as in js-mode for these cases.

Thanks! Pushed to master.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Sun, 09 Jun 2024 02:54:02 GMT) Full text and rfc822 format available.

Message #61 received at 68054 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dmitry <at> gutov.dev>
To: Noah Peart <noah.v.peart <at> gmail.com>
Cc: Yuan Fu <casouri <at> gmail.com>, 68054 <at> debbugs.gnu.org
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Sun, 9 Jun 2024 05:52:47 +0300
On 02/05/2024 16:38, Noah Peart wrote:
>  > js-ts-mode now has the exact same indentation
> 
> I'm not sure what you meant by this - did you mean js-ts-mode has
> the same indentation for non-multivar declarations as the examples
> shown above? js-ts-mode is still missing indentation rules for multiple 
> decl statements.
> The patch would work for js-ts-mode as well, but I didn't want to copy the
> code between the files.

Yes, I meant that it would be a good idea to keep the modes consistent, 
and to keep those examples indent like they do now.

> So much of the grammar is shared between js-ts-mode and
> typescript-ts-mode, it might be worth combining - neovim uses an ecma 
> grammar
> from which they both inherit.

When you say "uses the ecma grammar", what do you mean exactly? It just 
uses the parent grammar, not either of those two?

As for copying the code, it might be fine - the indentation rules are 
difficult to share, and copying the definition of 
typescript-ts-mode--anchor-decl is probably better than loading the 
whole other package file just for its sake. If more functions could be 
reused, however...




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68054; Package emacs. (Sun, 09 Jun 2024 06:26:01 GMT) Full text and rfc822 format available.

Message #64 received at 68054 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Dmitry Gutov <dmitry <at> gutov.dev>
Cc: noah.v.peart <at> gmail.com, casouri <at> gmail.com, 68054 <at> debbugs.gnu.org
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Sun, 09 Jun 2024 09:15:43 +0300
> Cc: Yuan Fu <casouri <at> gmail.com>, 68054 <at> debbugs.gnu.org
> Date: Sun, 9 Jun 2024 05:48:57 +0300
> From: Dmitry Gutov <dmitry <at> gutov.dev>
> 
> On 02/05/2024 16:26, Noah Peart wrote:
> > Ok, here is an updated patch for option 3.  The indentation looks like 
> > the examples
> > you've provided - it's the same indentation as in js-mode for these cases.
> 
> Thanks! Pushed to master.

Please also close the bug if appropriate.




Reply sent to Stefan Kangas <stefankangas <at> gmail.com>:
You have taken responsibility. (Thu, 13 Feb 2025 07:06:01 GMT) Full text and rfc822 format available.

Notification sent to Noah Peart <noah.v.peart <at> gmail.com>:
bug acknowledged by developer. (Thu, 13 Feb 2025 07:06:02 GMT) Full text and rfc822 format available.

Message #69 received at 68054-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Dmitry Gutov <dmitry <at> gutov.dev>, casouri <at> gmail.com,
 68054-done <at> debbugs.gnu.org, noah.v.peart <at> gmail.com
Subject: Re: bug#68054: [PATCH] Add tree-sitter indent rule for lexical decls
 in js/typescript
Date: Wed, 12 Feb 2025 23:05:34 -0800
Eli Zaretskii <eliz <at> gnu.org> writes:

>> Cc: Yuan Fu <casouri <at> gmail.com>, 68054 <at> debbugs.gnu.org
>> Date: Sun, 9 Jun 2024 05:48:57 +0300
>> From: Dmitry Gutov <dmitry <at> gutov.dev>
>>
>> On 02/05/2024 16:26, Noah Peart wrote:
>> > Ok, here is an updated patch for option 3.  The indentation looks like
>> > the examples
>> > you've provided - it's the same indentation as in js-mode for these cases.
>>
>> Thanks! Pushed to master.
>
> Please also close the bug if appropriate.

Now done.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 13 Mar 2025 11:24:22 GMT) Full text and rfc822 format available.

This bug report was last modified today.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.