on master help sign in
Fix Haddock placement for function arguments
803f76amrkkrp
data/examples/other/argument-comment-out.hsnew file+4
@@ -0,0 +1,4 @@
1+foo
2+ :: Int -- ^ Documentation
3+ -> Bool
4+foo _ = True
data/examples/other/argument-comment.hsnew file+4
@@ -0,0 +1,4 @@
1+foo
2+ :: Int -- ^ Documentation
3+ -> Bool
4+foo _ = True
src/Ormolu/Printer/Comments.hs+2−2
@@ -78,7 +78,7 @@ spitFollowingComment
78 -> R (Maybe RealSrcSpan) -- ^ Location of this comment
78 -> R (Maybe RealSrcSpan) -- ^ Location of this comment
79spitFollowingComment (L ref a) mlastSpn = do
79spitFollowingComment (L ref a) mlastSpn = do
80 mnSpn <- nextEltSpan
80 mnSpn <- nextEltSpan
81− meSpn <- getEnclosingSpan
81+ meSpn <- getEnclosingSpan ref
82 i <- getIndent
82 i <- getIndent
83 withPoppedComment (commentFollowsElt ref mnSpn meSpn mlastSpn) $ \l comment ->
83 withPoppedComment (commentFollowsElt ref mnSpn meSpn mlastSpn) $ \l comment ->
84 if theSameLine l ref && not (isModule a)
84 if theSameLine l ref && not (isModule a)
@@ -201,7 +201,7 @@ commentFollowsElt ref mnSpn meSpn mlastSpn (L l comment) =
201 Just espn ->
201 Just espn ->
202 let startColumn = srcLocCol . realSrcSpanStart
202 let startColumn = srcLocCol . realSrcSpanStart
203 in abs (startColumn espn - startColumn l)
203 in abs (startColumn espn - startColumn l)
204− > abs (startColumn ref - startColumn l)
204+ >= abs (startColumn ref - startColumn l)
205 continuation = isJust mlastSpn
205 continuation = isJust mlastSpn
206
206
207-- | Output a 'Comment'. This is a low-level printing function.
207-- | Output a 'Comment'. This is a low-level printing function.
src/Ormolu/Printer/Internal.hs+7−6
@@ -72,7 +72,7 @@ data RC = RC
72 -- ^ Whether to relax aligning rules for comments
72 -- ^ Whether to relax aligning rules for comments
73 , rcDebug :: Bool
73 , rcDebug :: Bool
74 -- ^ Whether to print debugging info as we go
74 -- ^ Whether to print debugging info as we go
75− , rcEnclosingSpan :: Maybe RealSrcSpan
75+ , rcEnclosingSpans :: [RealSrcSpan]
76 -- ^ Span of enclosing element of AST
76 -- ^ Span of enclosing element of AST
77 , rcAnns :: Anns
77 , rcAnns :: Anns
78 -- ^ Collection of annotations
78 -- ^ Collection of annotations
@@ -117,7 +117,7 @@ runR debug (R m) sstream cstream anns =
117 , rcLayout = MultiLine
117 , rcLayout = MultiLine
118 , rcRelaxedComments = False
118 , rcRelaxedComments = False
119 , rcDebug = debug
119 , rcDebug = debug
120− , rcEnclosingSpan = Nothing
120+ , rcEnclosingSpans = []
121 , rcAnns = anns
121 , rcAnns = anns
122 }
122 }
123 sc = SC
123 sc = SC
@@ -316,17 +316,18 @@ setIndent i m' = do
316 R (local modRC m)
316 R (local modRC m)
317 traceR "set_indent_after" Nothing
317 traceR "set_indent_after" Nothing
318
318
319−-- | Get 'RealSrcSpan' of enclosing span, if any.
319+-- | Get 'RealSrcSpan' of enclosing span for given referencne span.
320
320
321−getEnclosingSpan :: R (Maybe RealSrcSpan)
321+getEnclosingSpan :: RealSrcSpan -> R (Maybe RealSrcSpan)
322−getEnclosingSpan = R (asks rcEnclosingSpan)
322+getEnclosingSpan r =
323+ listToMaybe . dropWhile (== r) <$> R (asks rcEnclosingSpans)
323
324
324-- | Set 'RealSrcSpan' of enclosing span for the given computation.
325-- | Set 'RealSrcSpan' of enclosing span for the given computation.
325
326
326withEnclosingSpan :: RealSrcSpan -> R () -> R ()
327withEnclosingSpan :: RealSrcSpan -> R () -> R ()
327withEnclosingSpan spn (R m) = do
328withEnclosingSpan spn (R m) = do
328 let modRC rc = rc
329 let modRC rc = rc
329− { rcEnclosingSpan = Just spn
330+ { rcEnclosingSpans = spn : rcEnclosingSpans rc
330 }
331 }
331 R (local modRC m)
332 R (local modRC m)
332
333
src/Ormolu/Printer/Meat/Type.hs+5−6
@@ -38,14 +38,13 @@ p_hsType = \case
38 located f p_hsType
38 located f p_hsType
39 breakpoint
39 breakpoint
40 inci (located x p_hsType)
40 inci (located x p_hsType)
41− HsFunTy NoExt f x@(L _ x') -> do
41+ HsFunTy NoExt x y@(L _ y') -> do
42− located f p_hsType
42+ located x p_hsType
43 breakpoint
43 breakpoint
44 txt "-> "
44 txt "-> "
45− let located_ = case x' of
45+ case y' of
46− HsFunTy{} -> locatedVia Nothing
46+ HsFunTy{} -> p_hsType y'
47− _ -> located
47+ _ -> located y p_hsType
48− located_ x p_hsType
49 HsListTy NoExt t -> located t (brackets . p_hsType)
48 HsListTy NoExt t -> located t (brackets . p_hsType)
50 HsTupleTy NoExt tsort xs ->
49 HsTupleTy NoExt tsort xs ->
51 let parens' =
50 let parens' =