on master help sign in
Tweak formatting of warning pragmas
commitc2b32da3b5c217af0fe3c297c1a38dc321a09bb5 authorUtku Demir <me@utdemir.com> dateFri 9 Aug 2019, 13:17 (7 years ago) parent93271b2
7 files changed+26−7
data/examples/declaration/warning/warning-single-line-out.hs+6 data/examples/declaration/warning/warning-single-line.hs+8 data/examples/module-header/warning-pragma-multiline-out.hs+2−1 data/examples/module-header/warning-pragma-out.hs+3−1 src/Ormolu/Printer/Meat/Declaration.hs+1 src/Ormolu/Printer/Meat/Declaration/Warning.hs−1 src/Ormolu/Printer/Meat/Module.hs+6−4
data/examples/declaration/warning/warning-single-line-out.hs+6
@@ -3,3 +3,9 @@
33{-# WARNING test "This is a warning" #-}
44test :: IO ()
55test = pure ()
6+
7+bar = 3
8+{-# DEPRECATED bar "Bar is deprecated" #-}
9+
10+{-# DEPRECATED baz "Baz is also deprecated" #-}
11+baz = 5
data/examples/declaration/warning/warning-single-line.hs+8
@@ -3,3 +3,11 @@
33{-# WARNING test ["This is a warning" ] #-}
44test :: IO ()
55test = pure ()
6+
7+bar = 3
8+
9+{-# Deprecated bar "Bar is deprecated" #-}
10+
11+{-# DEPRECATED baz "Baz is also deprecated" #-}
12+baz = 5
13+
data/examples/module-header/warning-pragma-multiline-out.hs+2−1
@@ -1,4 +1,5 @@
1−module Test {-# DEPRECATED "This module is unstable" #-}
1+module Test
2+ {-# DEPRECATED "This module is unstable" #-}
23 ( foo,
34 bar,
45 baz
data/examples/module-header/warning-pragma-out.hs+3−1
@@ -1 +1,3 @@
1−module Test {-# WARNING "This module is very internal" #-} where
1+module Test
2+ {-# WARNING "This module is very internal" #-}
3+where
src/Ormolu/Printer/Meat/Declaration.hs+1
@@ -103,6 +103,7 @@ separatedDecls
103103 -> HsDecl GhcPs
104104 -> Bool
105105separatedDecls (TypeSignature n) (FunctionBody n') = n /= n'
106+separatedDecls x (FunctionBody n) | Just n' <- isPragma x = n /= n'
106107separatedDecls (FunctionBody n) x | Just n' <- isPragma x = n /= n'
107108separatedDecls x y | Just n <- isPragma x, Just n' <- isPragma y = n /= n'
108109separatedDecls x (TypeSignature n') | Just n <- isPragma x = n /= n'
src/Ormolu/Printer/Meat/Declaration/Warning.hs−1
@@ -29,7 +29,6 @@ p_moduleWarning :: WarningTxt -> R ()
2929p_moduleWarning wtxt = do
3030 let (pragmaText, lits) = warningText wtxt
3131 switchLayout (getLoc <$> lits) $ do
32− breakpoint
3332 inci $ pragma pragmaText (inci $ p_lits lits)
3433
3534p_topLevelWarning :: [Located RdrName] -> WarningTxt -> R ()
src/Ormolu/Printer/Meat/Module.hs+6−4
@@ -27,9 +27,9 @@ p_hsModule exts (L moduleSpan HsModule {..}) = do
2727 -- NOTE If span of exports in multiline, the whole thing is multiline.
2828 -- This is especially important because span of module itself always seems
2929 -- to have length zero, so it's not reliable for layout selection.
30− let spans' = case hsmodExports of
31− Nothing -> [moduleSpan]
32− Just (L exportsSpan _) -> moduleSpan : [exportsSpan]
30+ let exportSpans = maybe [] (\(L s _) -> [s]) hsmodExports
31+ deprecSpan = maybe [] (\(L s _) -> [s]) hsmodDeprecMessage
32+ spans' = exportSpans ++ deprecSpan ++ [moduleSpan]
3333 switchLayout spans' $ do
3434 let hasLangPragmas = not (null exts)
3535 hasModuleHeader = isJust hsmodName
@@ -43,7 +43,9 @@ p_hsModule exts (L moduleSpan HsModule {..}) = do
4343 Nothing -> pure ()
4444 Just hsmodName' -> line $ do
4545 located hsmodName' p_hsmodName
46− forM_ hsmodDeprecMessage (located' p_moduleWarning)
46+ forM_ hsmodDeprecMessage $ \w -> do
47+ breakpoint
48+ located' p_moduleWarning w
4749 case hsmodExports of
4850 Nothing -> return ()
4951 Just hsmodExports' -> do