diff --git a/TESTS.md b/TESTS.md index 4f040f6ac..10069c7d1 100644 --- a/TESTS.md +++ b/TESTS.md @@ -80,9 +80,35 @@ import qualified MegaModule as M ((>>>), MonadBaseControl, void, MaybeT(..), joi ```haskell expect import qualified MegaModule as M - (Either, Maybe(Just, Nothing), MaybeT(..), - Monad((>>), (>>=), return), MonadBaseControl, (<<<), (>>>), join, - liftIO, void) + ( Either + , Maybe(Just, Nothing) + , MaybeT(..) + , Monad((>>), (>>=), return) + , MonadBaseControl + , (<<<) + , (>>>) + , join + , liftIO + , void + ) +``` + +Pretty import specification + +```haskell +import A hiding + ( foobarbazqux + , foobarbazqux + , foobarbazqux + , foobarbazqux + , foobarbazqux + , foobarbazqux + , foobarbazqux + ) + +import Name hiding () + +import {-# SOURCE #-} safe qualified Module as M hiding (a, b, c, d, e, f) ``` # Declarations @@ -940,8 +966,7 @@ import B ``` ```haskell expect -import ATooLongList - (alpha, beta, delta, epsilon, eta, gamma, theta, zeta) +import ATooLongList (alpha, beta, delta, epsilon, eta, gamma, theta, zeta) import B ``` diff --git a/src/HIndent/Pretty.hs b/src/HIndent/Pretty.hs index 4ef5eb3e1..6340e6f47 100644 --- a/src/HIndent/Pretty.hs +++ b/src/HIndent/Pretty.hs @@ -1538,14 +1538,43 @@ instance Pretty ModulePragma where prettyInternal = pretty' instance Pretty ImportDecl where - prettyInternal = pretty' + prettyInternal (ImportDecl _ name qualified source safe mpkg mas mspec) = do + write "import" + when source $ write " {-# SOURCE #-}" + when safe $ write " safe" + when qualified $ write " qualified" + case mpkg of + Nothing -> return () + Just pkg -> space >> write pkg + space + pretty name + case mas of + Nothing -> return () + Just asName -> do + space + write "as " + pretty asName + case mspec of + Nothing -> return () + Just spec -> pretty spec instance Pretty ModuleName where prettyInternal (ModuleName _ name) = write name instance Pretty ImportSpecList where - prettyInternal = pretty' + prettyInternal (ImportSpecList _ hiding spec) = do + when hiding $ write " hiding" + let verVar = do + space + parens (commas (map pretty spec)) + let horVar = do + newline + indentedBlock + (do depend (write "( ") (prefixedLined ", " (map pretty spec)) + newline + write ")") + verVar `ifFitsOnOneLineOrElse` horVar instance Pretty ImportSpec where prettyInternal = pretty'