From fb4ae77e9374454d8d3f69fbeb6fc51d00425951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hr=C4=8Dek?= Date: Wed, 29 May 2024 16:13:57 +0200 Subject: [PATCH 1/9] Allow building with GHC 9.10 --- .github/workflows/cabal.yml | 35 +++++++++++++++++++++++++++++++++++ stylish-haskell.cabal | 16 +++++++++------- 2 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/cabal.yml diff --git a/.github/workflows/cabal.yml b/.github/workflows/cabal.yml new file mode 100644 index 00000000..87e477ac --- /dev/null +++ b/.github/workflows/cabal.yml @@ -0,0 +1,35 @@ +name: Cabal + +on: ['pull_request', 'push'] + +jobs: + build: + name: Build on ${{ matrix.os }} GHC ${{ matrix.ghc }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macOS-latest] + ghc: ["9.4", "9.6", "9.8", "9.10"] + fail-fast: false + + steps: + - uses: actions/checkout@v2 + + - uses: haskell/actions/setup@v2 + name: Setup Haskell Cabal + with: + ghc-version: ${{ matrix.ghc }} + + - uses: actions/cache@v2 + name: Cache ~/.cabal + with: + path: ~/.cabal + key: "${{ runner.os }}-${{ matrix.ghc }}-v9-${{ hashFiles('stylish-haskell.cabal') }}" + + - name: Build + run: cabal build + id: build + + - name: Test + run: cabal test + diff --git a/stylish-haskell.cabal b/stylish-haskell.cabal index 0edd396b..1806c5a3 100644 --- a/stylish-haskell.cabal +++ b/stylish-haskell.cabal @@ -19,10 +19,12 @@ Description: Extra-source-files: - CHANGELOG, README.markdown, data/stylish-haskell.yaml +Extra-doc-files: + CHANGELOG + Flag ghc-lib Default: True Manual: True @@ -38,9 +40,9 @@ Common depends base >= 4.8 && < 5, bytestring >= 0.9 && < 0.13, Cabal >= 3.14 && < 4.0, - containers >= 0.3 && < 0.7, + containers >= 0.3 && < 0.8, directory >= 1.2.3 && < 1.4, - filepath >= 1.1 && < 1.5, + filepath >= 1.1 && < 1.6, file-embed >= 0.0.10 && < 0.1, mtl >= 2.0 && < 2.4, regex-tdfa >= 1.3 && < 1.4, @@ -54,8 +56,8 @@ Common 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 + -- 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 !flag(ghc-lib) && impl(ghc >= 9.8) && impl(ghc < 9.9) Build-depends: @@ -64,10 +66,10 @@ Common depends ghc-boot-th else Build-depends: - ghc-lib-parser >= 9.8 && < 9.9 + ghc-lib-parser >= 9.8 && < 9.11 Build-depends: - ghc-lib-parser-ex >= 9.8 && < 9.9 + ghc-lib-parser-ex >= 9.8 && < 9.11 Library Import: depends From d72282e0ffbeb6f3bcdbd0257ce965a8f888e268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hr=C4=8Dek?= Date: Wed, 29 May 2024 19:52:54 +0200 Subject: [PATCH 2/9] Update to ghc 9.10 api --- lib/Language/Haskell/Stylish/GHC.hs | 3 +- lib/Language/Haskell/Stylish/Ordering.hs | 12 +++---- lib/Language/Haskell/Stylish/Printer.hs | 13 ++------ lib/Language/Haskell/Stylish/Step/Data.hs | 13 +++++--- lib/Language/Haskell/Stylish/Step/Imports.hs | 31 ++++++++++--------- .../Haskell/Stylish/Step/ModuleHeader.hs | 4 +-- .../Haskell/Stylish/Step/SimpleAlign.hs | 6 ++-- lib/Language/Haskell/Stylish/Step/Squash.hs | 9 +++--- .../Haskell/Stylish/Step/UnicodeSyntax.hs | 11 ++++--- stylish-haskell.cabal | 8 ++--- 10 files changed, 53 insertions(+), 57 deletions(-) diff --git a/lib/Language/Haskell/Stylish/GHC.hs b/lib/Language/Haskell/Stylish/GHC.hs index 3a5b3ed6..021c7aa3 100644 --- a/lib/Language/Haskell/Stylish/GHC.hs +++ b/lib/Language/Haskell/Stylish/GHC.hs @@ -69,7 +69,7 @@ dropBeforeAndAfter :: Located a -> [RealLocated b] -> [RealLocated b] dropBeforeAndAfter loc = dropBeforeLocated (Just loc) . dropAfterLocated (Just loc) baseDynFlags :: GHC.DynFlags -baseDynFlags = defaultDynFlags GHCEx.fakeSettings +baseDynFlags = defaultDynFlags GHCEx.fakeSettings getConDecls :: GHC.HsDataDefn GHC.GhcPs -> [GHC.LConDecl GHC.GhcPs] getConDecls d@GHC.HsDataDefn {} = case GHC.dd_cons d of @@ -80,7 +80,6 @@ showOutputable :: GHC.Outputable a => a -> String showOutputable = GHC.showPpr baseDynFlags epAnnComments :: GHC.EpAnn a -> [GHC.LEpaComment] -epAnnComments GHC.EpAnnNotUsed = [] epAnnComments GHC.EpAnn {..} = priorAndFollowing comments deepAnnComments :: (Data a, Typeable a) => a -> [GHC.LEpaComment] diff --git a/lib/Language/Haskell/Stylish/Ordering.hs b/lib/Language/Haskell/Stylish/Ordering.hs index a215ac21..d8455dae 100644 --- a/lib/Language/Haskell/Stylish/Ordering.hs +++ b/lib/Language/Haskell/Stylish/Ordering.hs @@ -45,12 +45,12 @@ compareLIE = comparing $ ieKey . unLoc -- constructors first, followed by functions, and then operators. ieKey :: IE GhcPs -> (Int, String) ieKey = \case - IEVar _ n -> nameKey n - IEThingAbs _ n -> nameKey n - IEThingAll _ n -> nameKey n - IEThingWith _ n _ _ -> nameKey n - IEModuleContents _ n -> nameKey n - _ -> (2, "") + IEVar _ n _ -> nameKey n + IEThingAbs _ n _ -> nameKey n + IEThingAll _ n _ -> nameKey n + IEThingWith _ n _ _ _ -> nameKey n + IEModuleContents _ n -> nameKey n + _ -> (2, "") -------------------------------------------------------------------------------- diff --git a/lib/Language/Haskell/Stylish/Printer.hs b/lib/Language/Haskell/Stylish/Printer.hs index 08c30c98..b6c769ca 100644 --- a/lib/Language/Haskell/Stylish/Printer.hs +++ b/lib/Language/Haskell/Stylish/Printer.hs @@ -61,7 +61,6 @@ import Control.Monad.Reader (MonadReader, ReaderT (..), asks, local) import Control.Monad.State (MonadState, State, get, gets, modify, put, runState) -import Data.List (foldl') -------------------------------------------------------------------------------- import Language.Haskell.Stylish.GHC (showOutputable) @@ -138,7 +137,6 @@ putComment epaComment = case GHC.ac_tok epaComment of GHC.EpaLineComment s -> putText s GHC.EpaDocOptions s -> putText s GHC.EpaBlockComment s -> putText s - GHC.EpaEofComment -> pure () putMaybeLineComment :: Maybe GHC.EpaComment -> P () putMaybeLineComment = \case @@ -149,8 +147,7 @@ putMaybeLineComment = \case putRdrName :: GenLocated GHC.SrcSpanAnnN RdrName -> P () putRdrName rdrName = case GHC.unLoc rdrName of Unqual name -> do - let (pre, post) = nameAnnAdornments $ - GHC.epAnnAnnsL $ GHC.ann $ GHC.getLoc rdrName + let (pre, post) = nameAnnAdornment $ GHC.anns $ GHC.getLoc rdrName putText pre putText (showOutputable name) putText post @@ -161,12 +158,6 @@ putRdrName rdrName = case GHC.unLoc rdrName of Exact name -> putText (showOutputable name) -nameAnnAdornments :: [GHC.NameAnn] -> (String, String) -nameAnnAdornments = foldl' - (\(accl, accr) nameAnn -> - let (l, r) = nameAnnAdornment nameAnn in (accl ++ l, r ++ accr)) - (mempty, mempty) - nameAnnAdornment :: GHC.NameAnn -> (String, String) nameAnnAdornment = \case GHC.NameAnn {..} -> fromAdornment nann_adornment @@ -239,7 +230,7 @@ putType ltp = case GHC.unLoc ltp of putOutputable ltp GHC.HsQualTy {} -> putOutputable ltp - GHC.HsAppKindTy _ _ _ _ -> + GHC.HsAppKindTy _ _ _ -> putOutputable ltp GHC.HsListTy _ _ -> putOutputable ltp diff --git a/lib/Language/Haskell/Stylish/Step/Data.hs b/lib/Language/Haskell/Stylish/Step/Data.hs index 0a99b0aa..f05fda29 100644 --- a/lib/Language/Haskell/Stylish/Step/Data.hs +++ b/lib/Language/Haskell/Stylish/Step/Data.hs @@ -93,6 +93,11 @@ step cfg = makeStep "Data" \ls m -> Editor.apply (changes m) ls changes :: Module -> Editor.Edits changes = foldMap (formatDataDecl cfg) . dataDecls + getComments :: GHC.AddEpAnn -> [GHC.LEpaComment] + getComments (GHC.AddEpAnn _ epaLoc) = case epaLoc of + GHC.EpaDelta _ comments -> comments + GHC.EpaSpan _ -> [] + dataDecls :: Module -> [DataDecl] dataDecls m = do ldecl <- GHC.hsmodDecls $ GHC.unLoc m @@ -100,7 +105,7 @@ step cfg = makeStep "Data" \ls m -> Editor.apply (changes m) ls loc <- maybeToList $ GHC.srcSpanToRealSrcSpan $ GHC.getLocA ldecl case tycld of GHC.DataDecl {..} -> pure $ MkDataDecl - { dataComments = epAnnComments tcdDExt + { dataComments = foldMap getComments tcdDExt , dataLoc = loc , dataDeclName = tcdLName , dataTypeVars = tcdTyVars @@ -330,7 +335,7 @@ putConstructor cfg consIndent lcons = case GHC.unLoc lcons of GHC.ConDeclGADT {..} -> do -- Put argument to constructor first: case con_g_args of - GHC.PrefixConGADT _ -> sep (comma >> space) $ fmap putRdrName $ toList 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" @@ -350,7 +355,7 @@ putConstructor cfg consIndent lcons = case GHC.unLoc lcons of GHC.HsOuterExplicit {..} -> hso_bndrs) forM_ con_mb_cxt $ putContext cfg case con_g_args of - GHC.PrefixConGADT scaledTys -> forM_ scaledTys $ \scaledTy -> do + GHC.PrefixConGADT _ scaledTys -> forM_ scaledTys $ \scaledTy -> do putType $ GHC.hsScaledThing scaledTy space >> putText "->" >> space GHC.RecConGADT _ _ -> error . mconcat $ @@ -384,7 +389,7 @@ putConstructor cfg consIndent lcons = case GHC.unLoc lcons of let commented = commentGroups (GHC.srcSpanToRealSrcSpan . GHC.getLocA) (GHC.unLoc largs) - (epAnnComments . GHC.ann $ GHC.getLoc largs) + (epAnnComments $ GHC.getLoc largs) forM_ (flagEnds commented) $ \(CommentGroup {..}, firstCommentGroup, _) -> do diff --git a/lib/Language/Haskell/Stylish/Step/Imports.hs b/lib/Language/Haskell/Stylish/Step/Imports.hs index fc69b2f7..53ef9241 100644 --- a/lib/Language/Haskell/Stylish/Step/Imports.hs +++ b/lib/Language/Haskell/Stylish/Step/Imports.hs @@ -58,6 +58,7 @@ import Language.Haskell.Stylish.Ordering import Language.Haskell.Stylish.Printer import Language.Haskell.Stylish.Step import Language.Haskell.Stylish.Util +import Control.Applicative ((<|>)) -------------------------------------------------------------------------------- data Options = Options @@ -507,11 +508,11 @@ printQualified Options{..} padNames stats ldecl = do -------------------------------------------------------------------------------- printImport :: Bool -> GHC.IE GHC.GhcPs -> P () -printImport _ (GHC.IEVar _ name) = do +printImport _ (GHC.IEVar _ name _) = do printIeWrappedName name -printImport _ (GHC.IEThingAbs _ name) = do +printImport _ (GHC.IEThingAbs _ name _) = do printIeWrappedName name -printImport separateLists (GHC.IEThingAll _ name) = do +printImport separateLists (GHC.IEThingAll _ name _) = do printIeWrappedName name when separateLists space putText "(..)" @@ -519,7 +520,7 @@ printImport _ (GHC.IEModuleContents _ modu) = do putText "module" space putText . GHC.moduleNameString $ GHC.unLoc modu -printImport separateLists (GHC.IEThingWith _ name wildcard imps) = do +printImport separateLists (GHC.IEThingWith _ name wildcard imps _) = do printIeWrappedName name when separateLists space let ellipsis = case wildcard of @@ -637,24 +638,24 @@ prepareImportList = prepareInner :: GHC.IE GHC.GhcPs -> GHC.IE GHC.GhcPs prepareInner = \case -- Simplify `A ()` to `A`. - GHC.IEThingWith x n GHC.NoIEWildcard [] -> GHC.IEThingAbs x n - GHC.IEThingWith x n w ns -> - GHC.IEThingWith x n w (sortBy (compareWrappedName `on` GHC.unLoc) ns) + GHC.IEThingWith x n GHC.NoIEWildcard [] md -> GHC.IEThingAbs x n md + GHC.IEThingWith x n w ns md -> + GHC.IEThingWith x n w (sortBy (compareWrappedName `on` GHC.unLoc) ns) md ie -> ie -- Merge two import items, assuming they have the same name. ieMerge :: GHC.IE GHC.GhcPs -> GHC.IE GHC.GhcPs -> Maybe (GHC.IE GHC.GhcPs) - ieMerge l@(GHC.IEVar _ _) _ = Just l - ieMerge _ r@(GHC.IEVar _ _) = Just r - ieMerge (GHC.IEThingAbs _ _) r = Just r - ieMerge l (GHC.IEThingAbs _ _) = Just l - ieMerge l@(GHC.IEThingAll _ _) _ = Just l - ieMerge _ r@(GHC.IEThingAll _ _) = Just r - ieMerge (GHC.IEThingWith x0 n0 w0 ns0) (GHC.IEThingWith _ _ w1 ns1) + ieMerge l@(GHC.IEVar _ _ _) _ = Just l + ieMerge _ r@(GHC.IEVar _ _ _) = Just r + ieMerge (GHC.IEThingAbs _ _ _) r = Just r + ieMerge l (GHC.IEThingAbs _ _ _) = Just l + ieMerge l@(GHC.IEThingAll _ _ _) _ = Just l + ieMerge _ r@(GHC.IEThingAll _ _ _) = Just r + ieMerge (GHC.IEThingWith x0 n0 w0 ns0 me0) (GHC.IEThingWith _ _ w1 ns1 me1) | w0 /= w1 = Nothing | otherwise = Just $ -- TODO: sort the `ns0 ++ ns1`? - GHC.IEThingWith x0 n0 w0 (nubOn GHC.lieWrappedName $ ns0 ++ ns1) + GHC.IEThingWith x0 n0 w0 (nubOn GHC.lieWrappedName $ ns0 ++ ns1) (me0 <|> me1) ieMerge _ _ = Nothing diff --git a/lib/Language/Haskell/Stylish/Step/ModuleHeader.hs b/lib/Language/Haskell/Stylish/Step/ModuleHeader.hs index 474a08fc..ff32761f 100644 --- a/lib/Language/Haskell/Stylish/Step/ModuleHeader.hs +++ b/lib/Language/Haskell/Stylish/Step/ModuleHeader.hs @@ -83,7 +83,7 @@ printModuleHeader maxCols conf ls lmodul = keywordLine kw = listToMaybe $ do GHC.EpAnn {..} <- pure $ GHC.hsmodAnn $ GHC.hsmodExt modul - GHC.AddEpAnn kw' (GHC.EpaSpan s _) <- GHC.am_main anns + GHC.AddEpAnn kw' (GHC.EpaSpan (GHC.RealSrcSpan s _)) <- GHC.am_main anns guard $ kw == kw' pure $ GHC.srcSpanEndLine s @@ -104,7 +104,7 @@ printModuleHeader maxCols conf ls lmodul = Just lexports -> Just $ doSort $ commentGroups (GHC.srcSpanToRealSrcSpan . GHC.getLocA) (GHC.unLoc lexports) - (epAnnComments . GHC.ann $ GHC.getLoc lexports) + (epAnnComments $ GHC.getLoc lexports) printedModuleHeader = runPrinter_ (PrinterConfig maxCols) diff --git a/lib/Language/Haskell/Stylish/Step/SimpleAlign.hs b/lib/Language/Haskell/Stylish/Step/SimpleAlign.hs index d1c8d4eb..a0448b2c 100644 --- a/lib/Language/Haskell/Stylish/Step/SimpleAlign.hs +++ b/lib/Language/Haskell/Stylish/Step/SimpleAlign.hs @@ -12,7 +12,7 @@ module Language.Haskell.Stylish.Step.SimpleAlign -------------------------------------------------------------------------------- import Data.Either (partitionEithers) import Data.Foldable (toList) -import Data.List (foldl', foldl1', sortOn) +import Data.List (foldl1', sortOn) import Data.Maybe (fromMaybe) import qualified GHC.Hs as Hs import qualified GHC.Parser.Annotation as GHC @@ -160,9 +160,9 @@ multiWayIfToAlignable _conf _ = [] -------------------------------------------------------------------------------- grhsToAlignable - :: GHC.GenLocated (GHC.SrcSpanAnn' a) (Hs.GRHS Hs.GhcPs (Hs.LHsExpr Hs.GhcPs)) + :: GHC.GenLocated (GHC.EpAnnCO) (Hs.GRHS Hs.GhcPs (Hs.LHsExpr Hs.GhcPs)) -> Maybe (Alignable GHC.RealSrcSpan) -grhsToAlignable (GHC.L (GHC.SrcSpanAnn _ grhsloc) (Hs.GRHS _ guards@(_ : _) body)) = do +grhsToAlignable (GHC.L (GHC.EpAnn (GHC.EpaSpan grhsloc) _ _ ) (Hs.GRHS _ guards@(_ : _) body)) = do let guardsLocs = map GHC.getLocA guards bodyLoc = GHC.getLocA $ body left = foldl1' GHC.combineSrcSpans guardsLocs diff --git a/lib/Language/Haskell/Stylish/Step/Squash.hs b/lib/Language/Haskell/Stylish/Step/Squash.hs index c90b5f34..bcc04d06 100644 --- a/lib/Language/Haskell/Stylish/Step/Squash.hs +++ b/lib/Language/Haskell/Stylish/Step/Squash.hs @@ -45,11 +45,10 @@ squashFieldDecl _ = mempty -------------------------------------------------------------------------------- -fieldDeclSeparator :: GHC.EpAnn [GHC.AddEpAnn]-> Maybe GHC.RealSrcSpan -fieldDeclSeparator GHC.EpAnn {..} = listToMaybe $ do - GHC.AddEpAnn GHC.AnnDcolon (GHC.EpaSpan s _) <- anns +fieldDeclSeparator :: [GHC.AddEpAnn]-> Maybe GHC.RealSrcSpan +fieldDeclSeparator anns = listToMaybe $ do + GHC.AddEpAnn GHC.AnnDcolon (GHC.EpaSpan (GHC.RealSrcSpan s _)) <- anns pure s -fieldDeclSeparator _ = Nothing -------------------------------------------------------------------------------- @@ -76,7 +75,7 @@ squashMatch lmatch = case GHC.m_grhss match of -------------------------------------------------------------------------------- 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 (GHC.RealSrcSpan s _)) <- GHC.ga_sep anns = Just s matchSeparator _ = Nothing diff --git a/lib/Language/Haskell/Stylish/Step/UnicodeSyntax.hs b/lib/Language/Haskell/Stylish/Step/UnicodeSyntax.hs index 1e815497..e28c869b 100644 --- a/lib/Language/Haskell/Stylish/Step/UnicodeSyntax.hs +++ b/lib/Language/Haskell/Stylish/Step/UnicodeSyntax.hs @@ -20,19 +20,20 @@ import Language.Haskell.Stylish.Util (everything) -------------------------------------------------------------------------------- hsTyReplacements :: GHC.HsType GHC.GhcPs -> Editor.Edits hsTyReplacements (GHC.HsFunTy _ arr _ _) - | GHC.HsUnrestrictedArrow (GHC.L (GHC.TokenLoc epaLoc) GHC.HsNormalTok) <- arr= + | GHC.HsUnrestrictedArrow (GHC.EpUniTok epaLoc GHC.NormalSyntax) <- arr = 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 = + | Just arrow <- GHC.ac_darrow . GHC.anns $ GHC.getLoc ctx + , (GHC.NormalSyntax, GHC.EpaSpan (GHC.RealSrcSpan loc _)) <- arrow = Editor.replaceRealSrcSpan loc "⇒" hsTyReplacements _ = mempty + -------------------------------------------------------------------------------- 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.AddEpAnn GHC.AnnDcolon epaLoc <- GHC.asDcolon ann + , GHC.EpaSpan (GHC.RealSrcSpan loc _) <- epaLoc = Editor.replaceRealSrcSpan loc "∷" hsSigReplacements _ = mempty diff --git a/stylish-haskell.cabal b/stylish-haskell.cabal index 1806c5a3..8ebd4bca 100644 --- a/stylish-haskell.cabal +++ b/stylish-haskell.cabal @@ -59,17 +59,17 @@ Common depends -- 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 !flag(ghc-lib) && impl(ghc >= 9.8) && impl(ghc < 9.9) + if !flag(ghc-lib) && impl(ghc >= 9.8) && impl(ghc < 9.11) Build-depends: - ghc >= 9.8 && < 9.9, + ghc >= 9.10 && < 9.11, ghc-boot, ghc-boot-th else Build-depends: - ghc-lib-parser >= 9.8 && < 9.11 + ghc-lib-parser >= 9.10 && < 9.11 Build-depends: - ghc-lib-parser-ex >= 9.8 && < 9.11 + ghc-lib-parser-ex >= 9.10 && < 9.11 Library Import: depends From f07ca9134f117384605f244d018840e09e929ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hr=C4=8Dek?= Date: Sun, 16 Feb 2025 15:10:12 +0100 Subject: [PATCH 3/9] Format import --- lib/Language/Haskell/Stylish/Step/Imports.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Language/Haskell/Stylish/Step/Imports.hs b/lib/Language/Haskell/Stylish/Step/Imports.hs index 53ef9241..f63b2e1c 100644 --- a/lib/Language/Haskell/Stylish/Step/Imports.hs +++ b/lib/Language/Haskell/Stylish/Step/Imports.hs @@ -23,6 +23,7 @@ module Language.Haskell.Stylish.Step.Imports ) where -------------------------------------------------------------------------------- +import Control.Applicative ((<|>)) import Control.Monad (forM_, void, when) import qualified Data.Aeson as A import Data.Foldable (toList) @@ -58,7 +59,6 @@ import Language.Haskell.Stylish.Ordering import Language.Haskell.Stylish.Printer import Language.Haskell.Stylish.Step import Language.Haskell.Stylish.Util -import Control.Applicative ((<|>)) -------------------------------------------------------------------------------- data Options = Options From 1f2bdf753749fb173ec1ca27fe5c7443777ac320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hr=C4=8Dek?= Date: Sun, 16 Feb 2025 15:12:58 +0100 Subject: [PATCH 4/9] Fix botched rebase --- .github/workflows/cabal.yml | 35 ----------------------------------- .github/workflows/ci.yml | 2 +- 2 files changed, 1 insertion(+), 36 deletions(-) delete mode 100644 .github/workflows/cabal.yml diff --git a/.github/workflows/cabal.yml b/.github/workflows/cabal.yml deleted file mode 100644 index 87e477ac..00000000 --- a/.github/workflows/cabal.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Cabal - -on: ['pull_request', 'push'] - -jobs: - build: - name: Build on ${{ matrix.os }} GHC ${{ matrix.ghc }} - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macOS-latest] - ghc: ["9.4", "9.6", "9.8", "9.10"] - fail-fast: false - - steps: - - uses: actions/checkout@v2 - - - uses: haskell/actions/setup@v2 - name: Setup Haskell Cabal - with: - ghc-version: ${{ matrix.ghc }} - - - uses: actions/cache@v2 - name: Cache ~/.cabal - with: - path: ~/.cabal - key: "${{ runner.os }}-${{ matrix.ghc }}-v9-${{ hashFiles('stylish-haskell.cabal') }}" - - - name: Build - run: cabal build - id: build - - - name: Test - run: cabal test - diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 11f1421b..e2cbb263 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest] - ghc: ["9.4", "9.6", "9.8"] + ghc: ["9.4", "9.6", "9.8", "9.10"] steps: - uses: actions/checkout@v4 From 932ea2a407e7cfe73f57fab5477c95bc75e057f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hr=C4=8Dek?= Date: Sun, 16 Feb 2025 15:34:42 +0100 Subject: [PATCH 5/9] Add ghc version to job name, fix compilaton with ghc 9.6, remove 9.4 --- .github/workflows/ci.yml | 4 ++-- lib/Language/Haskell/Stylish/Step/SimpleAlign.hs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2cbb263..edd983ba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,12 +4,12 @@ on: ['pull_request', 'push'] jobs: build: - name: Build on ${{ matrix.os }} + name: Build on ${{ matrix.os }} with GHC ${{ matrix.ghc }} runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-latest, macOS-latest] - ghc: ["9.4", "9.6", "9.8", "9.10"] + ghc: ["9.6", "9.8", "9.10"] steps: - uses: actions/checkout@v4 diff --git a/lib/Language/Haskell/Stylish/Step/SimpleAlign.hs b/lib/Language/Haskell/Stylish/Step/SimpleAlign.hs index a0448b2c..492a292d 100644 --- a/lib/Language/Haskell/Stylish/Step/SimpleAlign.hs +++ b/lib/Language/Haskell/Stylish/Step/SimpleAlign.hs @@ -12,7 +12,7 @@ module Language.Haskell.Stylish.Step.SimpleAlign -------------------------------------------------------------------------------- import Data.Either (partitionEithers) import Data.Foldable (toList) -import Data.List (foldl1', sortOn) +import Data.List (foldl', foldl1', sortOn) import Data.Maybe (fromMaybe) import qualified GHC.Hs as Hs import qualified GHC.Parser.Annotation as GHC From b2f7c6bdb1ae9d814540bb1c36ae071b3bf2727f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hr=C4=8Dek?= Date: Tue, 8 Apr 2025 13:01:08 +0200 Subject: [PATCH 6/9] Fix remaining tests --- lib/Language/Haskell/Stylish/Step/Data.hs | 23 +++++++++++++++-------- stylish-haskell.cabal | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/Language/Haskell/Stylish/Step/Data.hs b/lib/Language/Haskell/Stylish/Step/Data.hs index f05fda29..d43f25ee 100644 --- a/lib/Language/Haskell/Stylish/Step/Data.hs +++ b/lib/Language/Haskell/Stylish/Step/Data.hs @@ -93,20 +93,27 @@ step cfg = makeStep "Data" \ls m -> Editor.apply (changes m) ls changes :: Module -> Editor.Edits changes = foldMap (formatDataDecl cfg) . dataDecls - getComments :: GHC.AddEpAnn -> [GHC.LEpaComment] - getComments (GHC.AddEpAnn _ epaLoc) = case epaLoc of - GHC.EpaDelta _ comments -> comments - GHC.EpaSpan _ -> [] + getComments :: GHC.RealSrcSpan -> GHC.SrcSpanAnnA -> [GHC.LEpaComment] + getComments declSpan declAnnos= + filter isAfterStart $ epAnnComments declAnnos + where + -- workaround to make sure we don't reprint a haddock + -- comment before a data declaration after a data + -- declaration + isAfterStart :: GHC.LEpaComment -> Bool + isAfterStart (GHC.L (GHC.EpaSpan (GHC.RealSrcSpan commentSpan _)) _) = + GHC.srcSpanStartLine commentSpan >= GHC.srcSpanStartLine declSpan + isAfterStart _ = False dataDecls :: Module -> [DataDecl] dataDecls m = do ldecl <- GHC.hsmodDecls $ GHC.unLoc m - GHC.TyClD _ tycld <- pure $ GHC.unLoc ldecl - loc <- maybeToList $ GHC.srcSpanToRealSrcSpan $ GHC.getLocA ldecl + (GHC.L declAnnos (GHC.TyClD _ tycld)) <- pure ldecl + declSpan <- maybeToList $ GHC.srcSpanToRealSrcSpan $ GHC.getLocA ldecl case tycld of GHC.DataDecl {..} -> pure $ MkDataDecl - { dataComments = foldMap getComments tcdDExt - , dataLoc = loc + { dataComments = getComments declSpan declAnnos + , dataLoc = declSpan , dataDeclName = tcdLName , dataTypeVars = tcdTyVars , dataDefn = tcdDataDefn diff --git a/stylish-haskell.cabal b/stylish-haskell.cabal index 8ebd4bca..eb54596b 100644 --- a/stylish-haskell.cabal +++ b/stylish-haskell.cabal @@ -40,7 +40,7 @@ Common depends base >= 4.8 && < 5, bytestring >= 0.9 && < 0.13, Cabal >= 3.14 && < 4.0, - containers >= 0.3 && < 0.8, + containers >= 0.3 && < 0.9, directory >= 1.2.3 && < 1.4, filepath >= 1.1 && < 1.6, file-embed >= 0.0.10 && < 0.1, From 9b1cd409139fda91ebf67a5c09031dd02104c70f Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sat, 12 Apr 2025 12:19:49 +0200 Subject: [PATCH 7/9] Bump to run CI From a50de8a95309539186be7073dac5640029911038 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sat, 12 Apr 2025 15:09:49 +0200 Subject: [PATCH 8/9] Bust caches --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index edd983ba..b4308d7b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,9 +22,9 @@ jobs: - uses: actions/cache@v3 with: path: ${{ steps.setup.outputs.cabal-store }} - key: ${{ runner.os }}-${{ matrix.ghc }}-v1-${{ hashFiles('*.cabal') }} + key: ${{ runner.os }}-${{ matrix.ghc }}-v2-${{ hashFiles('*.cabal') }} restore-keys: | - ${{ runner.os }}-${{ matrix.ghc }}-v1- + ${{ runner.os }}-${{ matrix.ghc }}-v2- - run: make build - run: make test From e23accd30c518a9ae85e06cb7a48c02545c192fd Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sun, 13 Apr 2025 11:50:24 +0200 Subject: [PATCH 9/9] Try different GHC 9.6 version --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4308d7b..75851b0d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest] - ghc: ["9.6", "9.8", "9.10"] + ghc: ["9.6.6", "9.8", "9.10"] steps: - uses: actions/checkout@v4 @@ -29,11 +29,11 @@ jobs: - run: make build - run: make test - - if: startsWith(github.ref, 'refs/tags') && matrix.ghc == '9.6' + - if: startsWith(github.ref, 'refs/tags') && startsWith(matrix.ghc, '9.8') run: make artifact - uses: actions/upload-artifact@v4 - if: startsWith(github.ref, 'refs/tags') && matrix.ghc == '9.6' + if: startsWith(github.ref, 'refs/tags') && startsWith(matrix.ghc, '9.8') with: path: artifacts/* name: artifacts-${{ runner.os }}