Add format_node
commit16ba8556541e79b21de9d3ef4592cdba033b9ca2
authorJake Bailey <jakebailey@fb.com>
Tue, 21 Nov 2017 21:23:45 +0000 (21 13:23 -0800)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Tue, 21 Nov 2017 21:39:02 +0000 (21 13:39 -0800)
tree437da39ff6846014b1b4eae90b11d5bec5d1e139
parentd3e1302174cc5d980e7ad531c2641b93b242707a
Add format_node

Summary:
Currently, consumers who would like to format an EditableSyntax node already in hand must obtain a SyntaxTree in order to invoke format_tree or format_range. This means they invoke SyntaxTree.make, re-parsing the entire node, even though they already have a parse tree in hand!

This diff adds an API to format a single node, with an argument for adding indentation. Because toplevel text was previously never indented, this revealed an inconsistency in Chunk_builder, where the first chunk in a chunk group was not explicitly associated with an Always rule (this was masked by the fact that chunk groups were usually implicitly considered to have a break before them by Solve_state and Line_splitter). This diff also fixes that (without this fix, leading indentation would not be included on the first line of the formatted result, since the first chunk was considered not to have a break preceding it by the function which adds indentation).

Reviewed By: arxanas

Differential Revision: D6385825

fbshipit-source-id: edfdf3bfc9d86be2329b6aa0ad995b9fb72dacd7
hphp/hack/src/hackfmt/chunk_builder.ml
hphp/hack/src/hackfmt/libhackfmt.ml
hphp/hack/test/hackfmt/hackfmt_node_unit_test.ml [new file with mode: 0644]