emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comments to the new tree sitter implementation


From: Theodor Thornhill
Subject: Re: Comments to the new tree sitter implementation
Date: Sun, 24 Apr 2022 07:06:00 +0200

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> 1. New parent-beginning-of-line preset
>>
>> For typescript-mode more often that not you want to find some close
>> parent, then go to beginning of line to calculate the offset.  A
>> suggested implementation of this is:
>
> FWIW, I think this is a "quick hack" which gives fairly good results at
> little effort but doesn't help in the long run because you'll have to
> refine it sooner or later: it's never actually right, it's only ever
> right by accident.
>

Yes, absolutely.  Will indentation rules ever be perfect?  I'm thinking
a good approach is to provide something simple enough to not be too
controversial, and make sure a formatter takes care of the rest.  I
guess if we should cover all variants of the problems you outline I'd
have to provide a rule for all cases, don't I?  Or is there another way
you see?

>> ```typescript
>> function foo() {
>>   bar(() => ({
>>     baz
>>   }))
>> }
>> ```
>
> What if there's another argument to `bar` after the
> `() => ({ baz })` function, or if the user just prefers
>
>     function foo() {
>       bar(() => ({
>             baz
>           }))
>     }

In the first case you described my example function is surely wrong.  In
the second case I'm thinking either we provide some
'tree-sitter-simle-indent-override' defcustom that people can put their
own indentation rules into should they have some particular indentation
need

For typescript I'm now for the time being using the base 'prettier'
formatter just as a guidance tool for how to indent, as well as observe
how vscode behaves when typing.  Because the way Emacs handles
indentation is very different from how other editors do it (Emacs is
more of a formatter than the usual tab + shift-tab indenting method of
other editors), we have to make sure that both ways of indenting is
pleasant.  By this I mean that typing out a file from scratch should
indent as we type like how vscode or vim does it, while "C-x h TAB"
should work like a formatter.

With using prettiers default rules it would return

```typescript
function foo() {
  bar(
    () => ({
      baz,
    }),
    foo
  );
}
```

for the case where there's an extra arg where you specified.  This was
my reasoning for why this preset was ok enough.  It may not be for the
general case, though.  And fwiw, vscode indents it like this while
typing:

```typescript
function foo() {
   bar(() => ({
     baz
   }),
   foo
   )
}
```

This looks more like "I'm not even gonna try, just return 0 indent."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]