typescript-vim icon indicating copy to clipboard operation
typescript-vim copied to clipboard

Wrong indent with interfaces

Open jpevarnek opened this issue 7 years ago • 12 comments

Plugin corrects

interface foo {
  a: number;
  b: number;
}

to

interface foo {
  a: number;
     b: number;
}

jpevarnek avatar Feb 02 '18 15:02 jpevarnek

This is also occurring with enums:

enum Foo {
  Bar = 'one',
  Bazinga = 'two'
}

Indenting with vim turns enum into:

enum Foo {
  Bar = 'one',
    Bazinga = 'two'
}

I am not sure where to start, looking at the indent file 😨 there is nothing specific for interfaces and enums.

mboughaba avatar Mar 13 '18 20:03 mboughaba

Same issue, it's disturbing.

chemzqm avatar Jun 17 '18 06:06 chemzqm

I found the indent file from https://github.com/HerringtonDarkholme/yats.vim works well.

chemzqm avatar Jun 17 '18 06:06 chemzqm

Is this project just unmaintained? Maybe time to start a fork.

thejohnfreeman avatar Sep 25 '18 01:09 thejohnfreeman

Not unmaintained but low on my priorities right now - I'm happy to take in PRs but I don't have time to fix this indent issue.

Note, the indent file is almost entirely a copy of the indent file in https://github.com/pangloss/vim-javascript. This issue might be fixed by updating to their latest version.

leafgarland avatar Sep 25 '18 11:09 leafgarland

There are three ways to terminate member declarations in Typescript interfaces and object type aliases: semicolons, commas, and newlines.

interface foo {
  a: number;
  b: number;
}

interface foo {
  a: number,
  b: number,
}

interface foo {
  a: number
  b: number
}

The latest version of this plugin correctly indents all but comma-terminated member declarations within interface declarations (not within object type aliases). Such style might be uncommon, but it is legal. I was using it, but I'm not sure where I picked up the habit; perhaps from switching a type alias to an interface declaration. I'm going to change my personal style, but if this plugin wants to be 100% complete, it will need to handle that case.

thejohnfreeman avatar Oct 02 '18 02:10 thejohnfreeman

since I don't see this getting fixed I have disabled indent from this plugin and used https://github.com/jason0x43/vim-js-indent which seems to actually work.

moofish32 avatar Feb 15 '19 08:02 moofish32

Although I still have this plugin installed (I guess for syntax highlighting), I've switched to using Prettier to format my TypeScript. It's a huge relief.

thejohnfreeman avatar Feb 15 '19 19:02 thejohnfreeman

@thejohnfreeman The indent support for ts (from whichever plugin) is still useful while you are typing in code?

leafgarland avatar Feb 20 '19 04:02 leafgarland

@leafgarland Yes, the TypeScript indentation is still mildly useful. I believe it comes from this plugin (it is the only TypeScript-specific plugin I have, and I disabled vim-polyglot for TypeScript). However, JSX in TypeScript is not indented correctly, and so I rely on Prettier to fix it up for me.

thejohnfreeman avatar Feb 20 '19 16:02 thejohnfreeman

https://github.com/neoclide/coc-tsserver could provide on type format, which not only indent the lines, but also add/remove space according to your configuration when typing.

chemzqm avatar Feb 20 '19 16:02 chemzqm

Same. Forced to use Prettier to clear this up.

geoyws avatar Jun 28 '19 08:06 geoyws