From c2b32da3b5c217af0fe3c297c1a38dc321a09bb5 Mon Sep 17 00:00:00 2001 From: Utku Demir Date: Fri, 9 Aug 2019 13:17:19 +1200 Subject: [PATCH] Tweak formatting of warning pragmas --- .../declaration/warning/warning-single-line-out.hs | 6 ++++++ .../declaration/warning/warning-single-line.hs | 8 ++++++++ .../module-header/warning-pragma-multiline-out.hs | 3 ++- data/examples/module-header/warning-pragma-out.hs | 4 +++- src/Ormolu/Printer/Meat/Declaration.hs | 1 + src/Ormolu/Printer/Meat/Declaration/Warning.hs | 1 - src/Ormolu/Printer/Meat/Module.hs | 10 ++++++---- 7 files changed, 26 insertions(+), 7 deletions(-) diff --git a/data/examples/declaration/warning/warning-single-line-out.hs b/data/examples/declaration/warning/warning-single-line-out.hs index 03bf8ab..53a0112 100644 --- a/data/examples/declaration/warning/warning-single-line-out.hs +++ b/data/examples/declaration/warning/warning-single-line-out.hs @@ -3,3 +3,9 @@ {-# WARNING test "This is a warning" #-} test :: IO () test = pure () + +bar = 3 +{-# DEPRECATED bar "Bar is deprecated" #-} + +{-# DEPRECATED baz "Baz is also deprecated" #-} +baz = 5 diff --git a/data/examples/declaration/warning/warning-single-line.hs b/data/examples/declaration/warning/warning-single-line.hs index 77a935e..3a840f7 100644 --- a/data/examples/declaration/warning/warning-single-line.hs +++ b/data/examples/declaration/warning/warning-single-line.hs @@ -3,3 +3,11 @@ {-# WARNING test ["This is a warning" ] #-} test :: IO () test = pure () + +bar = 3 + +{-# Deprecated bar "Bar is deprecated" #-} + +{-# DEPRECATED baz "Baz is also deprecated" #-} +baz = 5 + diff --git a/data/examples/module-header/warning-pragma-multiline-out.hs b/data/examples/module-header/warning-pragma-multiline-out.hs index 263ce9d..727e33b 100644 --- a/data/examples/module-header/warning-pragma-multiline-out.hs +++ b/data/examples/module-header/warning-pragma-multiline-out.hs @@ -1,4 +1,5 @@ -module Test {-# DEPRECATED "This module is unstable" #-} +module Test + {-# DEPRECATED "This module is unstable" #-} ( foo, bar, baz diff --git a/data/examples/module-header/warning-pragma-out.hs b/data/examples/module-header/warning-pragma-out.hs index b1dc66b..b466ab8 100644 --- a/data/examples/module-header/warning-pragma-out.hs +++ b/data/examples/module-header/warning-pragma-out.hs @@ -1 +1,3 @@ -module Test {-# WARNING "This module is very internal" #-} where +module Test + {-# WARNING "This module is very internal" #-} +where diff --git a/src/Ormolu/Printer/Meat/Declaration.hs b/src/Ormolu/Printer/Meat/Declaration.hs index e6dc30b..2c44934 100644 --- a/src/Ormolu/Printer/Meat/Declaration.hs +++ b/src/Ormolu/Printer/Meat/Declaration.hs @@ -103,6 +103,7 @@ separatedDecls -> HsDecl GhcPs -> Bool separatedDecls (TypeSignature n) (FunctionBody n') = n /= n' +separatedDecls x (FunctionBody n) | Just n' <- isPragma x = n /= n' separatedDecls (FunctionBody n) x | Just n' <- isPragma x = n /= n' separatedDecls x y | Just n <- isPragma x, Just n' <- isPragma y = n /= n' separatedDecls x (TypeSignature n') | Just n <- isPragma x = n /= n' diff --git a/src/Ormolu/Printer/Meat/Declaration/Warning.hs b/src/Ormolu/Printer/Meat/Declaration/Warning.hs index ac16ac3..c069d01 100644 --- a/src/Ormolu/Printer/Meat/Declaration/Warning.hs +++ b/src/Ormolu/Printer/Meat/Declaration/Warning.hs @@ -29,7 +29,6 @@ p_moduleWarning :: WarningTxt -> R () p_moduleWarning wtxt = do let (pragmaText, lits) = warningText wtxt switchLayout (getLoc <$> lits) $ do - breakpoint inci $ pragma pragmaText (inci $ p_lits lits) p_topLevelWarning :: [Located RdrName] -> WarningTxt -> R () diff --git a/src/Ormolu/Printer/Meat/Module.hs b/src/Ormolu/Printer/Meat/Module.hs index 6900320..7b68d56 100644 --- a/src/Ormolu/Printer/Meat/Module.hs +++ b/src/Ormolu/Printer/Meat/Module.hs @@ -27,9 +27,9 @@ p_hsModule exts (L moduleSpan HsModule {..}) = do -- NOTE If span of exports in multiline, the whole thing is multiline. -- This is especially important because span of module itself always seems -- to have length zero, so it's not reliable for layout selection. - let spans' = case hsmodExports of - Nothing -> [moduleSpan] - Just (L exportsSpan _) -> moduleSpan : [exportsSpan] + let exportSpans = maybe [] (\(L s _) -> [s]) hsmodExports + deprecSpan = maybe [] (\(L s _) -> [s]) hsmodDeprecMessage + spans' = exportSpans ++ deprecSpan ++ [moduleSpan] switchLayout spans' $ do let hasLangPragmas = not (null exts) hasModuleHeader = isJust hsmodName @@ -43,7 +43,9 @@ p_hsModule exts (L moduleSpan HsModule {..}) = do Nothing -> pure () Just hsmodName' -> line $ do located hsmodName' p_hsmodName - forM_ hsmodDeprecMessage (located' p_moduleWarning) + forM_ hsmodDeprecMessage $ \w -> do + breakpoint + located' p_moduleWarning w case hsmodExports of Nothing -> return () Just hsmodExports' -> do