Tweak formatting of warning pragmas

This commit is contained in:
Utku Demir 2019-08-09 13:17:19 +12:00 committed by Mark Karpov
parent 93271b2551
commit c2b32da3b5
7 changed files with 26 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -1,4 +1,5 @@
module Test {-# DEPRECATED "This module is unstable" #-}
module Test
{-# DEPRECATED "This module is unstable" #-}
( foo,
bar,
baz

View File

@ -1 +1,3 @@
module Test {-# WARNING "This module is very internal" #-} where
module Test
{-# WARNING "This module is very internal" #-}
where

View File

@ -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'

View File

@ -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 ()

View File

@ -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