on master help sign in
Tweak formatting of warning pragmas
c2b32daUtku Demir
data/examples/declaration/warning/warning-single-line-out.hs+6
@@ -3,3 +3,9 @@
3{-# WARNING test "This is a warning" #-}
3{-# WARNING test "This is a warning" #-}
4test :: IO ()
4test :: IO ()
5test = pure ()
5test = 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 @@
3{-# WARNING test ["This is a warning" ] #-}
3{-# WARNING test ["This is a warning" ] #-}
4test :: IO ()
4test :: IO ()
5test = pure ()
5test = 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
1−module Test {-# DEPRECATED "This module is unstable" #-}
2+ {-# DEPRECATED "This module is unstable" #-}
2 ( foo,
3 ( foo,
3 bar,
4 bar,
4 baz
5 baz
data/examples/module-header/warning-pragma-out.hs+3−1
@@ -1 +1,3 @@
1+module Test
1−module Test {-# WARNING "This module is very internal" #-} where
2+ {-# WARNING "This module is very internal" #-}
3+where
src/Ormolu/Printer/Meat/Declaration.hs+1
@@ -103,6 +103,7 @@ separatedDecls
103 -> HsDecl GhcPs
103 -> HsDecl GhcPs
104 -> Bool
104 -> Bool
105separatedDecls (TypeSignature n) (FunctionBody n') = n /= n'
105separatedDecls (TypeSignature n) (FunctionBody n') = n /= n'
106+separatedDecls x (FunctionBody n) | Just n' <- isPragma x = n /= n'
106separatedDecls (FunctionBody n) x | Just n' <- isPragma x = n /= n'
107separatedDecls (FunctionBody n) x | Just n' <- isPragma x = n /= n'
107separatedDecls x y | Just n <- isPragma x, Just n' <- isPragma y = n /= n'
108separatedDecls x y | Just n <- isPragma x, Just n' <- isPragma y = n /= n'
108separatedDecls x (TypeSignature n') | Just n <- isPragma x = n /= n'
109separatedDecls 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 ()
29p_moduleWarning wtxt = do
29p_moduleWarning wtxt = do
30 let (pragmaText, lits) = warningText wtxt
30 let (pragmaText, lits) = warningText wtxt
31 switchLayout (getLoc <$> lits) $ do
31 switchLayout (getLoc <$> lits) $ do
32− breakpoint
33 inci $ pragma pragmaText (inci $ p_lits lits)
32 inci $ pragma pragmaText (inci $ p_lits lits)
34
33
35p_topLevelWarning :: [Located RdrName] -> WarningTxt -> R ()
34p_topLevelWarning :: [Located RdrName] -> WarningTxt -> R ()
src/Ormolu/Printer/Meat/Module.hs+6−4
@@ -27,9 +27,9 @@ p_hsModule exts (L moduleSpan HsModule {..}) = do
27 -- NOTE If span of exports in multiline, the whole thing is multiline.
27 -- NOTE If span of exports in multiline, the whole thing is multiline.
28 -- This is especially important because span of module itself always seems
28 -- This is especially important because span of module itself always seems
29 -- to have length zero, so it's not reliable for layout selection.
29 -- to have length zero, so it's not reliable for layout selection.
30− let spans' = case hsmodExports of
30+ let exportSpans = maybe [] (\(L s _) -> [s]) hsmodExports
31− Nothing -> [moduleSpan]
31+ deprecSpan = maybe [] (\(L s _) -> [s]) hsmodDeprecMessage
32− Just (L exportsSpan _) -> moduleSpan : [exportsSpan]
32+ spans' = exportSpans ++ deprecSpan ++ [moduleSpan]
33 switchLayout spans' $ do
33 switchLayout spans' $ do
34 let hasLangPragmas = not (null exts)
34 let hasLangPragmas = not (null exts)
35 hasModuleHeader = isJust hsmodName
35 hasModuleHeader = isJust hsmodName
@@ -43,7 +43,9 @@ p_hsModule exts (L moduleSpan HsModule {..}) = do
43 Nothing -> pure ()
43 Nothing -> pure ()
44 Just hsmodName' -> line $ do
44 Just hsmodName' -> line $ do
45 located hsmodName' p_hsmodName
45 located hsmodName' p_hsmodName
46− forM_ hsmodDeprecMessage (located' p_moduleWarning)
46+ forM_ hsmodDeprecMessage $ \w -> do
47+ breakpoint
48+ located' p_moduleWarning w
47 case hsmodExports of
49 case hsmodExports of
48 Nothing -> return ()
50 Nothing -> return ()
49 Just hsmodExports' -> do
51 Just hsmodExports' -> do