This repository was archived by the owner on Jun 15, 2023. It is now read-only.
Clean up end-of-file/printing newline logic #142
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Our previous final newline logic was messy. These commits clean them up.
When a printer's final newline logic is messed up, this often causes userland to solve it in the printer callsite, editor plugin, editor itself, etc., as has been the case for the old refmt. It wasn't clear who was adding a newline where. Sometime there are no newline, sometime there's one, sometime two. At which point every step of the way folks do a giant string trim on the output and append a single newline at the end and pass the result forward.
Our printer was on the verge of having this problem. For example, we were semi-normalizing the last newline in
res_doc
, where we appended a newline if the last char isn't already a newline. This is technically a bug, sinceprint (concat [text, hardLine])
andprint (concat [text])
both resulted in a single newline.res_doc
wasn't the right place to be opinionated and magical for newline. The right place would be inres_printer
.So these diffs remove
res_doc
's final newline printing, and add them tores_printer
, and only toprintImplementation
&printInterface
.This has several impacts:
res_doc
, now doesn't print out a final newline. This is important, as the outcome printer's result is sometime displayed inline as part of a bigger error message in the compiler. We don't want oprinter's result to affect that display. This is consistent with OCaml's oprinter behavior.res_diagnostics
and the snapshots.Res_printer.printLeadingComment
. This should be fixed. cc @IwanKaramazow for helphis should be fixed. cc @IwanKaramazow for help.