Fix mis-formatting of per-argument comments in certain cases
commite21e4ef11949ca38ad6418344b055c3f181a6db8
authormrkkrp <mark.karpov@tweag.io>
dateMon 12 Aug 2019, 20:53 (7 years ago)
parent825171a
data/examples/declaration/instance/contexts-out.hs+2−4
@@ -25,14 +25,12 @@ instance
2525 ( Read a, -- Foo
2626 Read b,
2727 Read
28− ( c,
29− -- Bar
28+ ( c, -- Bar
3029 d
3130 )
3231 )
3332 => Read
34− ( a,
35− -- Baz
33+ ( a, -- Baz
3634 b,
3735 ( c, -- Quux
3836 d
data/examples/declaration/value/function/operators-out.hs+1−2
@@ -1,6 +1,5 @@
11foo = bar
2− ++ {- some comment -}
3− case foo of
2+ ++ case foo of
43 a -> a
54
65main =
data/examples/declaration/value/function/operators.hs−1
@@ -1,5 +1,4 @@
11foo = bar ++
2− {- some comment -}
32 case foo of
43 a -> a
54
data/examples/other/argument-comment-out.hs+10
@@ -2,3 +2,13 @@ foo
22 :: Int -- ^ Documentation
33 -> Bool
44foo _ = True
5+
6+foo
7+ :: Foo a
8+ => Int -- ^ Foo
9+ -> Int
10+
11+foo
12+ :: Foo a
13+ => Int -- ^ Foo
14+ -> Int
data/examples/other/argument-comment.hs+9
@@ -2,3 +2,12 @@ foo
22 :: Int -- ^ Documentation
33 -> Bool
44foo _ = True
5+
6+foo :: Foo a
7+ => Int -- ^ Foo
8+ -> Int
9+
10+foo
11+ :: Foo a
12+ => Int -- ^ Foo
13+ -> Int
src/Ormolu/Printer/Comments.hs+4−2
@@ -208,8 +208,10 @@ commentFollowsElt ref mnSpn meSpn mlastSpn (L l comment) =
208208 Nothing -> True
209209 Just espn ->
210210 let startColumn = srcLocCol . realSrcSpanStart
211− in abs (startColumn espn - startColumn l)
212− >= abs (startColumn ref - startColumn l)
211+ in if startColumn espn > startColumn ref
212+ then True
213+ else abs (startColumn espn - startColumn l)
214+ >= abs (startColumn ref - startColumn l)
213215 continuation =
214216 case mlastSpn of
215217 Nothing -> False