on master help sign in
Avoid failing when comments get before an operator

This puts out the fire, but I'm not fully content with the solution. I also do not understand why it fails in the original issue but succeeds for e.g.: foo = do 1 + 2

commit094e70a2eb839bd1cd38b523b47b470cc041e188 authormrkkrp <mark.karpov@tweag.io> dateMon 5 Aug 2019, 22:17 (7 years ago) parent8fdc973
3 files changed+24−1
data/examples/declaration/value/other/comments-get-before-op-out.hs+10 data/examples/declaration/value/other/comments-get-before-op.hs+11 src/Ormolu/Printer/Meat/Declaration/Value.hs+3−1
data/examples/declaration/value/other/comments-get-before-op-out.hsnew file+10
@@ -0,0 +1,10 @@
1+main :: IO ()
2+main = do
3+ migrateSchema
4+ [ migration1,
5+ migration1,
6+ migration3
7+ ] -- When adding migrations here, don't forget to update
8+ -- 'schemaVersion' in Galley.Data
9+ `finally`
10+ Log.close
data/examples/declaration/value/other/comments-get-before-op.hsnew file+11
@@ -0,0 +1,11 @@
1+main :: IO ()
2+main = do
3+ migrateSchema
4+ [ migration1
5+ , migration1
6+ , migration3
7+ -- When adding migrations here, don't forget to update
8+ -- 'schemaVersion' in Galley.Data
9+ ]
10+ `finally`
11+ Log.close
src/Ormolu/Printer/Meat/Declaration/Value.hs+3−1
@@ -453,7 +453,9 @@ p_hsExpr = \case
453453 let opWrapper = case unLoc op of
454454 EWildPat NoExt -> backticks
455455 _ -> id
456− located op (opWrapper . p_hsExpr)
456+ -- NOTE Sometimes operator may be displaced from the line by comments,
457+ -- it still should be more indented to remain valid code.
458+ inci $ located op (opWrapper . p_hsExpr)
457459 let placement =
458460 -- NOTE If end of operator and start of second argument are on
459461 -- different lines, always use normal placement.