From 09ec59eaf93bbce4e4bca823fd6ea0d70adae89b Mon Sep 17 00:00:00 2001 From: Lennart Spitzner Date: Wed, 19 Apr 2023 11:52:45 +0000 Subject: [PATCH] Fix comment-after-context --- data/15-regressions.blt | 7 +++++++ .../Haskell/Brittany/Internal/ToBriDoc/Type.hs | 16 +++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/data/15-regressions.blt b/data/15-regressions.blt index 792f320..e8c5ece 100644 --- a/data/15-regressions.blt +++ b/data/15-regressions.blt @@ -929,3 +929,10 @@ alignColsLines layoutBriDocM bridocs = do -- colInfos `forM_` \colInfo -> do -- contains nonempty Seqs. colAggregation xs = maximum [ x | x <- xs, x <= minimum xs + alignMax' ] where alignMax' = max 0 alignMax + +#test type-signature comment-after-context +tzejubuVxairoy + :: (VwzuyApikd.VwzuyApikd zub, ZxtbaKospaKwqnuw Defg.Xeqpgko.Xeqpgko m) + -- foo bar + => CUR.Ozuzcak zub + -> m () diff --git a/source/library/Language/Haskell/Brittany/Internal/ToBriDoc/Type.hs b/source/library/Language/Haskell/Brittany/Internal/ToBriDoc/Type.hs index 83d14da..a3024c0 100644 --- a/source/library/Language/Haskell/Brittany/Internal/ToBriDoc/Type.hs +++ b/source/library/Language/Haskell/Brittany/Internal/ToBriDoc/Type.hs @@ -37,12 +37,18 @@ splitArrowType ltype@(L _ typ) = case typ of splitHsForallTypeFromBinders (getBinders hsf) typ1 HsQualTy NoExtField ctxMay typ1 -> do (innerHead, innerBody) <- splitArrowType typ1 + (wrapCtx, cntxtDocs) <- case ctxMay of + Nothing -> pure (id, []) + Just (L (SrcSpanAnn epAnn _) ctxs) -> do + let wrap = case epAnn of + EpAnn _ (AnnContext (Just (_, loc)) _ _) _ -> + docFlushCommsPost False (Just $ epaLocationRealSrcSpanStart loc) + . docHandleComms epAnn + _ -> docHandleComms epAnn + x <- ctxs `forM` (shareDoc . layoutType) + pure (wrap, x) pure - $ ( do - cntxtDocs <- case ctxMay of - Nothing -> pure [] - Just (L _ ctxs) -> ctxs `forM` (shareDoc . layoutType) - case cntxtDocs of + $ ( wrapCtx $ case cntxtDocs of [] -> docLit $ Text.pack "()" [x] -> x docs -> docAlt