Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Implement new indentation logic based on tree-sitter #594

Open
@chfritz

Description

@chfritz

Enhancement

Description

As discussed in various places, including atom/atom#10384 (comment), there is an opportunity to implement a new indentation logic that heavily exploits the output from the new tree-sitter parser. This makes it possible to address a number of issues users have been seeing with indentation, including in other languages, e.g., atom/atom#6655.

Status

I've started developing this in my sane-indentation package, and version 0.9.3 already use it. It works very well so far and without having gone through the above linked list of issues in detail, it seems to fix a good number of them already. I'm showing an example of its current indentation below.

Proposed Approach

I plan to complete the work for this new logic in the package for JavaScript. Once that is done, i.e., it fixes all known indentation issues, so long as they are not mutually exclusive (for instance, because they were just a matter of opinion), then I propose we discuss porting that code into this package (language-javascript). If and when that is completed, i.e., we all agree that this is the right approach, then it should be relatively simple to port this to other languages as well.

Example

foo({
    sd,
    sdf
  },
  4
);

foo( 2, {
    sd,
    sdf
  },
  4
);

foo( 2,
  {
    sd,
    sdf
  });

foo(2,
  4);

var x = [
  3,
  4
];

if (true) {
  foo();
  bar();
} else {
  foo();
  bar();
}

if (true)
  foo();
else
  bar();

const jsx = (
  <div
    title='start'
    >
    good
    <a>
      link
    </a>
    <i>
      sdfg
    </i>
    <div>
      sdf
    </div>
  </div>
);

const two = (
  <div>
    <b>
      test
    </b>
    <b>
      test
    </b>
  </div>
);

const x = {
  g: {
    a: 1,
    b: 2
  },
  h: {
    c: 3
  }
}

/* multi-line expressions */
req
  .shouldBeOne();
too.
  more.
  shouldBeOneToo;

const a =
  long_expression;

b =
  long;

b =
  3 + 5;

/**
  Comments
*/

while (mycondition) {
  sdfsdfg();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions