unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.78k stars 270 forks source link

edit + slurp roundtrip fails for long lines with repeated operators #1035

Closed seagreen closed 3 years ago

seagreen commented 4 years ago

The codebase slurps this in fine:

foo : Text
foo =
  "aaaaaaaaaaaaaaaaaaaaaa" ++ "bbbbbbbbbbbbbbbbbbbbbb" ++ "cccccccccccccccccccccc"

But it pretty prints it as:

foo : Text
foo =
  use Text ++
     "aaaaaaaaaaaaaaaaaaaaaa"
  ++ "bbbbbbbbbbbbbbbbbbbbbb"
  ++ "cccccccccccccccccccccc"

And that won't go back in:

  /home/traveller/code/mine/unison-ian/scratch.u:5:3:
  unexpected ++
  expecting [, bang, binding, case, false, handle, if, lambda, let, namespace, quote, termLink, true, tuple, or typeLink
      5 |   ++ "bbbbbbbbbbbbbbbbbbbbbb"

(This is with ucm version: release/M2-base-329-gd3611ffd)

seagreen commented 4 years ago

As a quick fix I could switch long lines with repeated operators to not be split into separate lines.

It looks like the long term fix will be for use Foo to sometimes indent following lines and sometimes not, right now the parser requires this. Or the parser could be changed.

mitchellwrosen commented 4 years ago

Another example, I think it's the same bug though.

part2.hasTwoEqualAdjacent.test : [Result]
part2.hasTwoEqualAdjacent.test =
  use part2 hasTwoEqualAdjacent
  use test ==
     Test.run
  <| v1.tests
       [ hasTwoEqualAdjacent [1, 1, 2, 2, 3, 3] == true,
         hasTwoEqualAdjacent [1, 2, 3, 4, 4, 4] == false,
         hasTwoEqualAdjacent [1, 1, 1, 1, 2, 2] == true,
         hasTwoEqualAdjacent [1, 1, 1, 1] == false,
         hasTwoEqualAdjacent [1, 1, 1, 1, 1] == false ]
mitchellwrosen commented 4 years ago

fyi, here's how ormolu (Haskell formatter) would pretty-print these

"aaaaaaaaaaaaaaaaaaaaaa" ++ "bbbbbbbbbbbbbbbbbbbbbb" ++
  "cccccccccccccccccccccc"
part2.hasTwoEqualAdjacent.test : [Result]
part2.hasTwoEqualAdjacent.test =
  use part2 hasTwoEqualAdjacent
  use test ==
  Test.run <|
    v1.tests
      [ hasTwoEqualAdjacent [1, 1, 2, 2, 3, 3] == true
      , hasTwoEqualAdjacent [1, 2, 3, 4, 4, 4] == false
      , hasTwoEqualAdjacent [1, 1, 1, 1, 2, 2] == true
      , hasTwoEqualAdjacent [1, 1, 1, 1] == false
      , hasTwoEqualAdjacent [1, 1, 1, 1, 1] == false
      ]