Subject: bug#77803: tsx-ts-mode: wrong indentation for variables declarations

From: Konstantin Kharlamov <[email-masked]>
Date: Tue, 15 Apr 2025 17:33:21 +0300

On Tue, 2025-04-15 at 16:35 +0300, Konstantin Kharlamov wrote:
> On Tue, 2025-04-15 at 12:02 +0300, Eli Zaretskii wrote:
> > > From: Konstantin Kharlamov <[email-masked]>
> > > Date: Mon, 14 Apr 2025 18:41:42 +0300
> > > 
> > > Given this TypeScript snippet:
> > > 
> > >     const a = 1,
> > >           b = 2;
> > >     var c = 3,
> > >         d = 4;
> > > 
> > > …both b and d are expected to be indented to `typescript-ts-mode-
> > > indent-offset`
> > > (2 by default). This both makes logical sense and is the behavior
> > > in another
> > > editor VSCode.
> > > 
> > > Instead it gets indented to the length of `const` and `var` +
> > > space.
> > > 
> > > I'd note a separate problem: if you have this code:
> > > 
> > > 
> > >     const a = 1,
> > >       b = 2,
> > >           c = 3;
> > > 
> > > …and you try to indent `c`, instead of getting indented to the
> > > previous line it
> > > keeps being at "const + space" length.
> > 
> > Thanks.
> > 
> > Theo and Yuan, any suggestions or comments?
> 
> I dug into it a big — I think, the solution should be adding this
> line
> 
>      ((parent-is "variable_declarator") parent-bol typescript-ts-
> mode-indent-offset)
> 
> to the list inside `typescript-ts-mode--indent-rules`.
> 
> However, when I evaluate the defun and try re-indenting, nothing
> changes, it still gets indented to `const `.
> 
> I see that evaluating `(treesit-node-parent (treesit-node-at
> (point)))`
> results in "#<treesit-node variable_declarator in 623-688>", so
> presumably the fix should work. I'd appreciate a hint on how to see
> what rule gets actually triggered during indentation, that results in
> the change not doing anything.

Okay, I figured it all out, going to send patch, but another thing I
stumbled upon: are tests not working? I mean, the `test/README` says I
could run "make <filename>  -or-  make <filename>.log".

But:

╰─λ make typescript-ts-mode-tests
make: *** No rule to make target 'typescript-ts-mode-tests'.  Stop.
╰─λ make typescript-ts-mode-tests.el                                  
make: *** No rule to make target 'typescript-ts-mode-tests.el'.  Stop.
╰─λ make test/lisp/progmodes/typescript-ts-mode-tests.el
make: 'test/lisp/progmodes/typescript-ts-mode-tests.el' is up to date.