stylish-haskell 0.14.4.0 → 0.14.5.0
raw patch · 14 files changed
+61/−50 lines, 14 filesdep ~aesondep ~ghcdep ~ghc-lib-parserPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: aeson, ghc, ghc-lib-parser, ghc-lib-parser-ex, mtl, optparse-applicative, strict
API changes (from Hackage documentation)
+ Language.Haskell.Stylish.GHC: getConDecls :: HsDataDefn GhcPs -> [LConDecl GhcPs]
- Language.Haskell.Stylish.Module: type Module = Located HsModule
+ Language.Haskell.Stylish.Module: type Module = Located (HsModule GhcPs)
Files
- CHANGELOG +4/−0
- README.markdown +2/−1
- lib/Language/Haskell/Stylish/GHC.hs +7/−1
- lib/Language/Haskell/Stylish/Module.hs +5/−7
- lib/Language/Haskell/Stylish/Ordering.hs +1/−2
- lib/Language/Haskell/Stylish/Parse.hs +2/−1
- lib/Language/Haskell/Stylish/Printer.hs +0/−2
- lib/Language/Haskell/Stylish/Step/Data.hs +6/−5
- lib/Language/Haskell/Stylish/Step/Imports.hs +9/−7
- lib/Language/Haskell/Stylish/Step/ModuleHeader.hs +3/−4
- lib/Language/Haskell/Stylish/Step/SimpleAlign.hs +6/−8
- lib/Language/Haskell/Stylish/Step/Squash.hs +2/−2
- lib/Language/Haskell/Stylish/Step/UnicodeSyntax.hs +2/−2
- stylish-haskell.cabal +12/−8
CHANGELOG view
@@ -1,5 +1,9 @@ # CHANGELOG +- 0.14.5.0 (2023-06-23)+ * #459 Support GHC 9.6 (By Michael Peyton Jones)+ * #445 Default `ghc-lib` flag to True (by amesgen)+ - 0.14.4.0 (2023-01-09) * #421 Support GHC 9.4 (by Lei Zhu) * #439 Fix NoXyz extension issues for .cabal files (by Lev Dvorkin)
README.markdown view
@@ -2,7 +2,8 @@ <img src="./assets/Logo/SVG/RoundedLogo.svg" width="100px"> -++ ## Introduction
lib/Language/Haskell/Stylish/GHC.hs view
@@ -16,6 +16,7 @@ , showOutputable -- * Deconstruction+ , getConDecls , epAnnComments , deepAnnComments ) where@@ -68,7 +69,12 @@ dropBeforeAndAfter loc = dropBeforeLocated (Just loc) . dropAfterLocated (Just loc) baseDynFlags :: GHC.DynFlags-baseDynFlags = defaultDynFlags GHCEx.fakeSettings GHCEx.fakeLlvmConfig+baseDynFlags = defaultDynFlags GHCEx.fakeSettings ++getConDecls :: GHC.HsDataDefn GHC.GhcPs -> [GHC.LConDecl GHC.GhcPs]+getConDecls d@GHC.HsDataDefn {} = case GHC.dd_cons d of+ GHC.NewTypeCon con -> [con]+ GHC.DataTypeCons _ cons -> cons showOutputable :: GHC.Outputable a => a -> String showOutputable = GHC.showPpr baseDynFlags
lib/Language/Haskell/Stylish/Module.hs view
@@ -42,7 +42,6 @@ import GHC.Types.SrcLoc (GenLocated (..), RealSrcSpan (..), unLoc) import qualified GHC.Types.SrcLoc as GHC-import qualified GHC.Unit.Module.Name as GHC --------------------------------------------------------------------------------@@ -56,7 +55,7 @@ -------------------------------------------------------------------------------- -- | Concrete module type-type Module = GHC.Located GHC.HsModule+type Module = GHC.Located (GHC.HsModule GHC.GhcPs) importModuleName :: ImportDecl GhcPs -> String importModuleName = GHC.moduleNameString . GHC.unLoc . GHC.ideclName@@ -68,9 +67,8 @@ , (==) `on` ideclPkgQual , (==) `on` ideclSource , hasMergableQualified `on` ideclQualified- , (==) `on` ideclImplicit , (==) `on` fmap unLoc . ideclAs- , (==) `on` fmap fst . ideclHiding -- same 'hiding' flags+ , (==) `on` fmap fst . ideclImportList -- same 'hiding' flags ] where hasMergableQualified QualifiedPre QualifiedPost = True@@ -120,10 +118,10 @@ :: GHC.LImportDecl GHC.GhcPs -> GHC.LImportDecl GHC.GhcPs -> GHC.LImportDecl GHC.GhcPs mergeModuleImport (L p0 i0) (L _p1 i1) =- L p0 $ i0 { ideclHiding = newImportNames }+ L p0 $ i0 { ideclImportList = newImportNames } where newImportNames =- case (ideclHiding i0, ideclHiding i1) of+ case (ideclImportList i0, ideclImportList i1) of (Just (b, L p imps0), Just (_, L _ imps1)) -> Just (b, L p (imps0 `merge` imps1)) (Nothing, Nothing) -> Nothing (Just x, Nothing) -> Just x@@ -137,7 +135,7 @@ moduleLanguagePragmas :: Module -> [(RealSrcSpan, NonEmpty String)] moduleLanguagePragmas =- mapMaybe prag . epAnnComments . GHC.hsmodAnn . GHC.unLoc+ mapMaybe prag . epAnnComments . GHC.hsmodAnn . GHC.hsmodExt . GHC.unLoc where prag :: GHC.LEpaComment -> Maybe (GHC.RealSrcSpan, NonEmpty String) prag comment = case GHC.ac_tok (GHC.unLoc comment) of
lib/Language/Haskell/Stylish/Ordering.hs view
@@ -17,7 +17,6 @@ import Data.Ord (comparing) import GHC.Hs import qualified GHC.Hs as GHC-import GHC.Types.Name.Reader (RdrName) import GHC.Types.SrcLoc (unLoc) import GHC.Utils.Outputable (Outputable) import qualified GHC.Utils.Outputable as GHC@@ -55,7 +54,7 @@ ---------------------------------------------------------------------------------compareWrappedName :: IEWrappedName RdrName -> IEWrappedName RdrName -> Ordering+compareWrappedName :: IEWrappedName GhcPs -> IEWrappedName GhcPs -> Ordering compareWrappedName = comparing nameKey
lib/Language/Haskell/Stylish/Parse.hs view
@@ -20,6 +20,7 @@ import qualified GHC.LanguageExtensions.Type as LangExt import qualified GHC.Parser.Header as GHC import qualified GHC.Parser.Lexer as GHC+import qualified GHC.Types.Error as GHC import qualified GHC.Types.SrcLoc as GHC import qualified GHC.Utils.Error as GHC import qualified Language.Haskell.GhclibParserEx.GHC.Driver.Session as GHCEx@@ -114,7 +115,7 @@ -- Actual parse. case GHCEx.parseModule input dynFlags1 of GHC.POk _ m -> Right m- GHC.PFailed ps -> Left . withFileName . GHC.showSDoc dynFlags1 . GHC.pprMessages . snd $+ GHC.PFailed ps -> Left . withFileName . GHC.showSDoc dynFlags1 . GHC.pprMessages GHC.NoDiagnosticOpts . snd $ GHC.getPsMessages ps where withFileName x = maybe "" (<> ": ") fp <> x
lib/Language/Haskell/Stylish/Printer.hs view
@@ -50,11 +50,9 @@ -------------------------------------------------------------------------------- import qualified GHC.Hs as GHC import GHC.Hs.Extension (GhcPs)-import qualified GHC.Types.Basic as GHC import GHC.Types.Name.Reader (RdrName (..)) import GHC.Types.SrcLoc (GenLocated (..)) import qualified GHC.Types.SrcLoc as GHC-import qualified GHC.Unit.Module.Name as GHC import GHC.Utils.Outputable (Outputable) --------------------------------------------------------------------------------
lib/Language/Haskell/Stylish/Step/Data.hs view
@@ -18,6 +18,7 @@ -------------------------------------------------------------------------------- import Control.Monad (forM_, unless, when)+import Data.Foldable (toList) import Data.List (sortBy) import Data.Maybe (listToMaybe, maybeToList) import qualified GHC.Hs as GHC@@ -139,7 +140,7 @@ let defn = dataDefn decl constructorComments = commentGroups (GHC.srcSpanToRealSrcSpan . GHC.getLocA)- (GHC.dd_cons defn)+ (getConDecls defn) (dataComments decl) onelineEnum =@@ -296,7 +297,7 @@ putUnbrokenEnum :: Config -> DataDecl -> P () putUnbrokenEnum cfg decl = sep (space >> putText "|" >> space)- (fmap (putConstructor cfg 0) . GHC.dd_cons . dataDefn $ decl)+ (fmap (putConstructor cfg 0) . getConDecls . dataDefn $ decl) putName :: DataDecl -> P () putName decl@MkDataDecl{..} =@@ -329,7 +330,7 @@ GHC.ConDeclGADT {..} -> do -- Put argument to constructor first: case con_g_args of- GHC.PrefixConGADT _ -> sep (comma >> space) $ fmap putRdrName con_names+ GHC.PrefixConGADT _ -> sep (comma >> space) $ fmap putRdrName $ toList con_names GHC.RecConGADT _ _ -> error . mconcat $ [ "Language.Haskell.Stylish.Step.Data.putConstructor: " , "encountered a GADT with record constructors, not supported yet"@@ -469,7 +470,7 @@ putForAll :: GHC.OutputableBndrFlag s 'GHC.Parsed => Bool -> [GHC.LHsTyVarBndr s GHC.GhcPs] -> P ()-putForAll forall ex_tvs = when forall do+putForAll frall ex_tvs = when frall do putText "forall" space sep space $ putOutputable . GHC.unLoc <$> ex_tvs@@ -530,7 +531,7 @@ _ -> False isNewtype :: DataDecl -> Bool-isNewtype = (== GHC.NewType) . GHC.dd_ND . dataDefn+isNewtype = (== GHC.NewType) . GHC.dataDefnConsNewOrData . GHC.dd_cons . dataDefn isInfix :: DataDecl -> Bool isInfix = (== GHC.Infix) . dataFixity
lib/Language/Haskell/Stylish/Step/Imports.hs view
@@ -44,8 +44,8 @@ import qualified GHC.Types.PkgQual as GHC import qualified GHC.Types.SourceText as GHC import qualified GHC.Types.SrcLoc as GHC-import qualified GHC.Unit.Module.Name as GHC-import qualified GHC.Unit.Types as GHC+--import qualified GHC.Unit.Module.Name as GHC+--import qualified GHC.Unit.Types as GHC import qualified Text.Regex.TDFA as Regex import Text.Regex.TDFA (Regex) import Text.Regex.TDFA.ReadRegex (parseRegex)@@ -367,7 +367,7 @@ -- Only print spaces if something follows. let somethingFollows = isJust (GHC.ideclAs decl) || isHiding decl ||- not (null $ GHC.ideclHiding decl)+ not (null $ GHC.ideclImportList decl) when (padNames && somethingFollows) $ putText $ replicate (isLongestImport stats - importModuleNameLength decl) ' '@@ -396,7 +396,7 @@ pure () - case snd <$> GHC.ideclHiding decl of+ case snd <$> GHC.ideclImportList decl of Nothing -> pure () Just limports | null (GHC.unLoc limports) -> case emptyListAlign of RightAfter -> modifyCurrentLine trimRight >> space >> putText "()"@@ -536,9 +536,9 @@ ---------------------------------------------------------------------------------printIeWrappedName :: GHC.LIEWrappedName GHC.RdrName -> P ()+printIeWrappedName :: GHC.LIEWrappedName GHC.GhcPs -> P () printIeWrappedName lie = case GHC.unLoc lie of- GHC.IEName n -> putRdrName n+ GHC.IEName _ n -> putRdrName n GHC.IEPattern _ n -> putText "pattern" >> space >> putRdrName n GHC.IEType _ n -> putText "type" >> space >> putRdrName n @@ -603,7 +603,9 @@ isQualified = (/=) GHC.NotQualified . GHC.ideclQualified isHiding :: GHC.ImportDecl GHC.GhcPs -> Bool-isHiding = maybe False fst . GHC.ideclHiding+isHiding d = case GHC.ideclImportList d of+ Just (GHC.EverythingBut, _) -> True+ _ -> False isSource :: GHC.ImportDecl GHC.GhcPs -> Bool isSource = (==) GHC.IsBoot . GHC.ideclSource
lib/Language/Haskell/Stylish/Step/ModuleHeader.hs view
@@ -18,7 +18,6 @@ listToMaybe) import qualified GHC.Hs as GHC import qualified GHC.Types.SrcLoc as GHC-import qualified GHC.Unit.Module.Name as GHC --------------------------------------------------------------------------------@@ -80,8 +79,8 @@ GHC.srcSpanEndLine <$> GHC.srcSpanToRealSrcSpan loc) keywordLine kw = listToMaybe $ do- GHC.EpAnn {..} <- pure $ GHC.hsmodAnn modul- GHC.AddEpAnn kw' (GHC.EpaSpan s) <- GHC.am_main anns+ GHC.EpAnn {..} <- pure $ GHC.hsmodAnn $ GHC.hsmodExt modul+ GHC.AddEpAnn kw' (GHC.EpaSpan s _) <- GHC.am_main anns guard $ kw == kw' pure $ GHC.srcSpanEndLine s @@ -89,7 +88,7 @@ whereLine = keywordLine GHC.AnnWhere commentOnLine l = listToMaybe $ do- comment <- epAnnComments $ GHC.hsmodAnn modul+ comment <- epAnnComments $ GHC.hsmodAnn $ GHC.hsmodExt modul guard $ GHC.srcSpanStartLine (GHC.anchor $ GHC.getLoc comment) == l pure comment
lib/Language/Haskell/Stylish/Step/SimpleAlign.hs view
@@ -22,6 +22,7 @@ -------------------------------------------------------------------------------- import Language.Haskell.Stylish.Align import qualified Language.Haskell.Stylish.Editor as Editor+import Language.Haskell.Stylish.GHC import Language.Haskell.Stylish.Module import Language.Haskell.Stylish.Step import Language.Haskell.Stylish.Util@@ -63,21 +64,17 @@ ---------------------------------------------------------------------------------records :: GHC.Located Hs.HsModule -> [Record]+records :: Module -> [Record] records modu = do let decls = map GHC.unLoc (Hs.hsmodDecls (GHC.unLoc modu)) tyClDecls = [ tyClDecl | Hs.TyClD _ tyClDecl <- decls ] dataDecls = [ d | d@(Hs.DataDecl _ _ _ _ _) <- tyClDecls ] dataDefns = map Hs.tcdDataDefn dataDecls- d@Hs.ConDeclH98 {} <- concatMap getConDecls dataDefns+ d@Hs.ConDeclH98 {} <- GHC.unLoc <$> concatMap getConDecls dataDefns case Hs.con_args d of Hs.RecCon rec -> [GHC.unLoc rec] _ -> []- where- getConDecls :: Hs.HsDataDefn Hs.GhcPs -> [Hs.ConDecl Hs.GhcPs]- getConDecls d@Hs.HsDataDefn {} = map GHC.unLoc $ Hs.dd_cons d - -------------------------------------------------------------------------------- recordToAlignable :: Config -> Record -> [[Alignable GHC.RealSrcSpan]] recordToAlignable conf = groupAlign (cRecords conf) . fromMaybe [] . traverse fieldDeclToAlignable@@ -103,8 +100,9 @@ :: Config -> Hs.MatchGroup Hs.GhcPs (Hs.LHsExpr Hs.GhcPs) -> [[Alignable GHC.RealSrcSpan]]-matchGroupToAlignable conf (Hs.MG _ alts _) = cases' ++ patterns'+matchGroupToAlignable conf mg = cases' ++ patterns' where+ alts = Hs.mg_alts mg (cases, patterns) = partitionEithers . fromMaybe [] $ traverse matchToAlignable (GHC.unLoc alts) cases' = groupAlign (cCases conf) cases patterns' = groupAlign (cTopLevelPatterns conf) patterns@@ -184,7 +182,7 @@ step :: Maybe Int -> Config -> Step step maxColumns config = makeStep "Cases" $ \ls module' -> let changes- :: (GHC.Located Hs.HsModule -> [a])+ :: (Module -> [a]) -> (a -> [[Alignable GHC.RealSrcSpan]]) -> Editor.Edits changes search toAlign = mconcat $ do
lib/Language/Haskell/Stylish/Step/Squash.hs view
@@ -47,7 +47,7 @@ -------------------------------------------------------------------------------- fieldDeclSeparator :: GHC.EpAnn [GHC.AddEpAnn]-> Maybe GHC.RealSrcSpan fieldDeclSeparator GHC.EpAnn {..} = listToMaybe $ do- GHC.AddEpAnn GHC.AnnDcolon (GHC.EpaSpan s) <- anns+ GHC.AddEpAnn GHC.AnnDcolon (GHC.EpaSpan s _) <- anns pure s fieldDeclSeparator _ = Nothing @@ -76,7 +76,7 @@ -------------------------------------------------------------------------------- matchSeparator :: GHC.EpAnn GHC.GrhsAnn -> Maybe GHC.RealSrcSpan matchSeparator GHC.EpAnn {..}- | GHC.AddEpAnn _ (GHC.EpaSpan s) <- GHC.ga_sep anns = Just s+ | GHC.AddEpAnn _ (GHC.EpaSpan s _) <- GHC.ga_sep anns = Just s matchSeparator _ = Nothing
lib/Language/Haskell/Stylish/Step/UnicodeSyntax.hs view
@@ -24,7 +24,7 @@ Editor.replaceRealSrcSpan (GHC.epaLocationRealSrcSpan epaLoc) "→" hsTyReplacements (GHC.HsQualTy _ ctx _) | Just arrow <- GHC.ac_darrow . GHC.anns . GHC.ann $ GHC.getLoc ctx- , (GHC.NormalSyntax, GHC.EpaSpan loc) <- arrow =+ , (GHC.NormalSyntax, GHC.EpaSpan loc _) <- arrow = Editor.replaceRealSrcSpan loc "⇒" hsTyReplacements _ = mempty @@ -32,7 +32,7 @@ hsSigReplacements :: GHC.Sig GHC.GhcPs -> Editor.Edits hsSigReplacements (GHC.TypeSig ann _ _) | GHC.AddEpAnn GHC.AnnDcolon epaLoc <- GHC.asDcolon $ GHC.anns ann- , GHC.EpaSpan loc <- epaLoc =+ , GHC.EpaSpan loc _ <- epaLoc = Editor.replaceRealSrcSpan loc "∷" hsSigReplacements _ = mempty
stylish-haskell.cabal view
@@ -1,6 +1,6 @@ Cabal-version: 2.4 Name: stylish-haskell-Version: 0.14.4.0+Version: 0.14.5.0 Synopsis: Haskell code prettifier Homepage: https://github.com/haskell/stylish-haskell License: BSD-3-Clause@@ -24,7 +24,7 @@ data/stylish-haskell.yaml Flag ghc-lib- Default: False+ Default: True Manual: True Description: Force dependency on ghc-lib-parser even if GHC API in the ghc package is supported@@ -42,7 +42,7 @@ directory >= 1.2.3 && < 1.4, filepath >= 1.1 && < 1.5, file-embed >= 0.0.10 && < 0.1,- mtl >= 2.0 && < 2.3,+ mtl >= 2.0 && < 2.4, regex-tdfa >= 1.3 && < 1.4, syb >= 0.3 && < 0.8, text >= 1.2 && < 2.1,@@ -53,17 +53,21 @@ Build-depends: semigroups >= 0.18 && < 0.20 + -- Use GHC if the ghc-lib flag is not set+ -- and we have a new enough GHC. Note that + -- this will only work if the user's + -- compiler is of the matching major version! if impl(ghc >= 9.4.1) && (!flag(ghc-lib)) Build-depends:- ghc >= 9.4 && < 9.5,+ ghc >= 9.6 && < 9.7, ghc-boot, ghc-boot-th else Build-depends:- ghc-lib-parser >= 9.4 && < 9.5+ ghc-lib-parser >= 9.6 && < 9.7 Build-depends:- ghc-lib-parser-ex >= 9.4 && < 9.5+ ghc-lib-parser-ex >= 9.6 && < 9.7 Library Import: depends@@ -109,8 +113,8 @@ Build-depends: stylish-haskell,- strict >= 0.3 && < 0.5,- optparse-applicative >= 0.12 && < 0.18+ strict >= 0.3 && < 0.6,+ optparse-applicative >= 0.12 && < 0.19 Test-suite stylish-haskell-tests Import: depends