tweag / topiary

https://topiary.tweag.io/
MIT License
575 stars 29 forks source link

Poor handling of the `;;` separator #659

Closed Niols closed 9 months ago

Niols commented 11 months ago

Introduction

The ';;' separator can be used in OCaml to explicitly separate two top-level expressions. For instance, the following is a very valid OCaml program:

let bonjour () = "Bonjour"

;;

print_string (bonjour ());
print_string ", "

;;

let topiary _x = "Topiary"

;;

print_string (topiary 27);
print_endline "!"

Describe the bug

As of https://github.com/tweag/topiary/commit/8cc9aa40d99c89b448190bb1693777128fdcd6c0, Topiary has very poor handling of the ;; separator. For instance, given the example file above, Topiary will produce:

let bonjour () = "Bonjour";;print_string (bonjour ());
print_string ", ";;

let topiary _x = "Topiary";;print_string (topiary 27);
print_endline "!"

To Reproduce

$ nix run github:tweag/topiary/8cc9aa4 -- format -l ocaml <<EOF
let bonjour () = "Bonjour"

;;

print_string (bonjour ());
print_string ", "

;;

let topiary _x = "Topiary"

;;

print_string (topiary 27);
print_endline "!"
EOF

Expected behavior

I think this separator should be on its own line, possibly even separated by a line before and a line after. I am not a big user of this style so I am not sure what people would prefer but that sounds like a reasonable first draft to me. Maybe @aspiwack has seen some code with this?

Additional context

I don't think this style is very frequent. However, as of today, Topiary is completely unusable on such files. Hence my choice of priority; feel free to change it of course!