mirror of
https://github.com/google/ormolu.git
synced 2025-01-05 22:16:03 +03:00
[#52] Implement WARNING/DEPRECATED in module header
This commit is contained in:
parent
f8b920767c
commit
7307b6debd
@ -0,0 +1,11 @@
|
||||
module Test
|
||||
{-# DEPRECATED
|
||||
[ "This module is deprecated."
|
||||
, "Please use OtherModule instead."
|
||||
]
|
||||
#-}
|
||||
( foo
|
||||
, bar
|
||||
, baz
|
||||
)
|
||||
where
|
@ -0,0 +1,8 @@
|
||||
module Test {-# DEPRECATED ["This module is deprecated.",
|
||||
"Please use OtherModule instead."
|
||||
]#-}
|
||||
( foo
|
||||
, bar
|
||||
, baz
|
||||
)
|
||||
where
|
@ -0,0 +1,8 @@
|
||||
module Test {-# DEPRECATED "This module is unstable" #-}
|
||||
( foo
|
||||
, bar
|
||||
, baz
|
||||
)
|
||||
where
|
||||
|
||||
import Blah
|
4
data/examples/module-header/warning-pragma-multiline.hs
Normal file
4
data/examples/module-header/warning-pragma-multiline.hs
Normal file
@ -0,0 +1,4 @@
|
||||
module Test {-# DEPRECATED "This module is unstable" #-}
|
||||
(foo, bar, baz) where
|
||||
|
||||
import Blah
|
1
data/examples/module-header/warning-pragma-out.hs
Normal file
1
data/examples/module-header/warning-pragma-out.hs
Normal file
@ -0,0 +1 @@
|
||||
module Test {-# WARNING "This module is very internal" #-} where
|
@ -0,0 +1 @@
|
||||
module Test {-# WARNING "There's only one line here." #-} where
|
@ -0,0 +1 @@
|
||||
module Test {-# WArnING ["There's only one line here."] #-} where
|
2
data/examples/module-header/warning-pragma.hs
Normal file
2
data/examples/module-header/warning-pragma.hs
Normal file
@ -0,0 +1,2 @@
|
||||
module Test {-# WARNING "This module is very internal"
|
||||
#-} where
|
@ -38,6 +38,7 @@ module Ormolu.Printer.Combinators
|
||||
, parens
|
||||
, parensHash
|
||||
, pragmaBraces
|
||||
, pragma
|
||||
-- ** Literals
|
||||
, comma
|
||||
, space
|
||||
@ -270,6 +271,19 @@ pragmaBraces m = sitcc $ do
|
||||
vlayout space (newline >> txt " ")
|
||||
txt "#-}"
|
||||
|
||||
-- | This surrounds the body in a pragma, which includes the 'pragmaBraces' and
|
||||
--- the keyword for the pragma. It also takes a 'SrcSpan', which should be the
|
||||
--- combined span of the body. This means multiline layouts are only triggered
|
||||
--- when the body spans multiple lines, not just when the braces or pragma
|
||||
--- keyword do.
|
||||
|
||||
pragma :: SrcSpan -> Text -> R () -> R ()
|
||||
pragma srcSpan pragmaText body = switchLayout srcSpan . pragmaBraces $ do
|
||||
txt pragmaText
|
||||
breakpoint
|
||||
inci body
|
||||
|
||||
|
||||
-- | Surround given entity by optional space before and a newline after, iff
|
||||
-- current layout is multiline.
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE PatternSynonyms #-}
|
||||
{-# LANGUAGE RecordWildCards #-}
|
||||
@ -9,8 +10,10 @@ module Ormolu.Printer.Meat.Module
|
||||
)
|
||||
where
|
||||
|
||||
import BasicTypes hiding (InlinePragma)
|
||||
import Control.Monad
|
||||
import Data.Maybe (isJust)
|
||||
import Data.Text (Text)
|
||||
import GHC
|
||||
import Ormolu.Imports
|
||||
import Ormolu.Printer.Combinators
|
||||
@ -35,6 +38,7 @@ p_hsModule loc@(L moduleSpan hsModule) = do
|
||||
Nothing -> pure ()
|
||||
Just hsmodName' -> line $ do
|
||||
located hsmodName' p_hsmodName
|
||||
maybe (pure ()) (located' p_warningTxt) hsmodDeprecMessage
|
||||
case hsmodExports of
|
||||
Nothing -> return ()
|
||||
Just hsmodExports' -> do
|
||||
@ -59,6 +63,26 @@ p_hsModule loc@(L moduleSpan hsModule) = do
|
||||
when (trailingComments && isJust hsmodName) newline
|
||||
spitRemainingComments
|
||||
|
||||
-- | Layout the WARNING/DEPRECATED pragmas in the module head
|
||||
|
||||
p_warningTxt :: WarningTxt -> R ()
|
||||
p_warningTxt = \case
|
||||
WarningTxt _ lits -> p_pragma "WARNING" lits
|
||||
DeprecatedTxt _ lits -> p_pragma "DEPRECATED" lits
|
||||
where
|
||||
p_pragma :: Text -> [Located StringLiteral] -> R ()
|
||||
p_pragma pragmaText lits = switchLayout (litsSpan lits) $ do
|
||||
breakpoint
|
||||
inci $ pragma (litsSpan lits) pragmaText (p_lits lits)
|
||||
|
||||
litsSpan :: [Located StringLiteral] -> SrcSpan
|
||||
litsSpan lits = combineSrcSpans (getLoc $ head lits) (getLoc $ last lits)
|
||||
|
||||
p_lits :: [Located StringLiteral] -> R ()
|
||||
p_lits = \case
|
||||
[l] -> atom l
|
||||
ls -> brackets . velt $ withSep comma atom ls
|
||||
|
||||
-- | Determine if these declarations should be separated by a blank line.
|
||||
|
||||
separatedDecls
|
||||
|
Loading…
Reference in New Issue
Block a user