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

From: Konstantin Kharlamov <[email-masked]>
Date: Tue, 15 Apr 2025 16:35:02 +0300

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.