Use the line splitting solution from the original source for splits outside of the...
commit98d61f0ae9dabcdda7e5e311721d46766a87b1e5
authorJake Bailey <jakebailey@fb.com>
Fri, 22 Sep 2017 02:55:12 +0000 (21 19:55 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Fri, 22 Sep 2017 03:07:22 +0000 (21 20:07 -0700)
tree3c18b35452d180506f364d194af45a38f2b3d476
parentec2a3d738a118a6b98945139ab549b1f4fff669d
Use the line splitting solution from the original source for splits outside of the formatting range

Summary:
Currently, range formatting simply prints a substring of the full formatted source. This causes problems when the original source represents a line-breaking solution different from the one hackfmt would produce. For example, consider as-you-type formatting on this source:

```
Vec\map($foo, $x ==> {
  bar($x);
  baz($x);
});
```

If you try to format at the semicolon after the call to `bar`, you'll get incorrect indentation:

```
Vec\map($foo, $x ==> {
    bar($x);
  baz($x);
});
```

The reason is that hackfmt actually wants to format the whole code block like this:

```
Vec\map(
  $foo,
  $x ==> {
    bar($x);
    baz($x);
  },
);
```

But the result of hackfmt is only the changed range, which includes this extra indent.

This diff binds all splits outside of the formatting range to the solution in the original source, constraining hackfmt to change line breaks only within the formatting range. This fixes the indentation problem in this example.

Reviewed By: arxanas

Differential Revision: D5853970

fbshipit-source-id: 575ecd9b5286f4294ecc8e6328ad5bef6321f5ee
hphp/hack/src/hackfmt/chunk_group.ml
hphp/hack/src/hackfmt/line_splitter.ml
hphp/hack/src/hackfmt/solve_state.ml
hphp/hack/test/hackfmt/tests/at_char_inside_lambda.flags [new file with mode: 0644]
hphp/hack/test/hackfmt/tests/at_char_inside_lambda.php [new file with mode: 0644]
hphp/hack/test/hackfmt/tests/at_char_inside_lambda.php.exp [new file with mode: 0644]
hphp/hack/test/hackfmt/tests/at_char_last_arg_removes_trailing_comma.flags
hphp/hack/test/hackfmt/tests/at_char_last_arg_removes_trailing_comma.php
hphp/hack/test/hackfmt/tests/at_char_last_arg_removes_trailing_comma.php.exp