on master help sign in
Correctly place comments inside enclosing expressions at the end of the module
commit8662581ad5ac26d66642dcdcbc8bf3490960b7af authorUtku Demir <me@utdemir.com> dateWed 28 Aug 2019, 14:21 (7 years ago) parent374aca5
2 files changed+12−7
data/examples/declaration/rewrite-rule/prelude4-out.hs+1−1 src/Ormolu/Printer/Comments.hs+11−6
data/examples/declaration/rewrite-rule/prelude4-out.hs+1−1
@@ -2,6 +2,6 @@
22"unpack" [~1] forall a. unpackCString # a = build (unpackFoldrCString # a)
33"unpack-list" [1] forall a. unpackFoldrCString # a (:) [] = unpackCString # a
44"unpack-append" forall a n. unpackFoldrCString # a (:) n = unpackAppendCString # a n
5− #-}
65-- There's a built-in rule (in PrelRules.lhs) for
76-- unpackFoldr "foo" c (unpackFoldr "baz" c n) = unpackFoldr "foobaz" c n
7+ #-}
src/Ormolu/Printer/Comments.hs+11−6
@@ -242,13 +242,18 @@ commentFollowsElt ref mnSpn meSpn mlastSpn (L l comment) =
242242 Just spn -> srcSpanEndLine spn + 1 == srcSpanStartLine l
243243
244244 lastInEnclosing =
245− case (,) <$> meSpn <*> mnSpn of
245+ case meSpn of
246+ -- When there is no enclosing element, return false
246247 Nothing -> False
247− Just (espn, nspn) ->
248− -- Make sure that the comment is inside the parent
249− realSrcSpanEnd l <= realSrcSpanEnd espn
250− -- Check if the next element is outside of the parent
251− && realSrcSpanEnd espn < realSrcSpanStart nspn
248+ -- When there is an enclosing element,
249+ Just espn ->
250+ let -- Make sure that the comment is inside the enclosing element
251+ insideParent = realSrcSpanEnd l <= realSrcSpanEnd espn
252+ -- And check if the next element is outside of the parent
253+ nextOutsideParent = case mnSpn of
254+ Nothing -> True
255+ Just nspn -> realSrcSpanEnd espn < realSrcSpanStart nspn
256+ in insideParent && nextOutsideParent
252257
253258-- | Output a 'Comment'. This is a low-level printing function.
254259