diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dd12dc3c2e..71a9e85443 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -213,7 +213,7 @@ jobs: name: Test hls-change-type-signature test suite run: cabal test hls-change-type-signature-plugin-tests || cabal test hls-change-type-signature-plugin-tests - - if: matrix.test && matrix.ghc != '9.12' + - if: matrix.test name: Test hls-gadt-plugin test suit run: cabal test hls-gadt-plugin-tests || cabal test hls-gadt-plugin-tests diff --git a/docs/support/ghc-version-support.md b/docs/support/ghc-version-support.md index 57b6368091..aa29c60c0a 100644 --- a/docs/support/ghc-version-support.md +++ b/docs/support/ghc-version-support.md @@ -17,7 +17,7 @@ Support status (see the support policy below for more details): | GHC version | Last supporting HLS version | Support status | | ------------ | ------------------------------------------------------------------------------------ | -------------- | -| 9.12.2 | [latest](https://github.com/haskell/haskell-language-server/releases/latest) | basic support | +| 9.12.2 | [latest](https://github.com/haskell/haskell-language-server/releases/latest) | full support | | 9.10.1 | [latest](https://github.com/haskell/haskell-language-server/releases/latest) | full support | | 9.8.4 | [latest](https://github.com/haskell/haskell-language-server/releases/latest) | full support | | 9.8.2 | [2.9.0.1](https://github.com/haskell/haskell-language-server/releases/tag/2.9.0.1) | deprecated | diff --git a/docs/support/plugin-support.md b/docs/support/plugin-support.md index 47d494b7b2..7e0d7220e8 100644 --- a/docs/support/plugin-support.md +++ b/docs/support/plugin-support.md @@ -54,7 +54,7 @@ For example, a plugin to provide a formatter which has itself been abandoned has | `hls-explicit-fixity-plugin` | 2 | | | `hls-explicit-record-fields-plugin` | 2 | | | `hls-fourmolu-plugin` | 2 | | -| `hls-gadt-plugin` | 2 | 9.12.2 | +| `hls-gadt-plugin` | 2 | | | `hls-hlint-plugin` | 2 | 9.10.1 | | `hls-module-name-plugin` | 2 | | | `hls-notes-plugin` | 2 | | diff --git a/haskell-language-server.cabal b/haskell-language-server.cabal index 4f378c6e91..3bfbfa4f53 100644 --- a/haskell-language-server.cabal +++ b/haskell-language-server.cabal @@ -1208,13 +1208,13 @@ flag gadt manual: True common gadt - if flag(gadt) && (impl(ghc < 9.11) || flag(ignore-plugins-ghc-bounds)) + if flag(gadt) build-depends: haskell-language-server:hls-gadt-plugin cpp-options: -Dhls_gadt library hls-gadt-plugin import: defaults, pedantic, warnings - if !flag(gadt) || (impl(ghc > 9.11) && !flag(ignore-plugins-ghc-bounds)) + if !flag(gadt) buildable: False exposed-modules: Ide.Plugin.GADT other-modules: Ide.Plugin.GHC @@ -1238,7 +1238,7 @@ library hls-gadt-plugin test-suite hls-gadt-plugin-tests import: defaults, pedantic, test-defaults, warnings - if !flag(gadt) || (impl(ghc > 9.11) && !flag(ignore-plugins-ghc-bounds)) + if !flag(gadt) buildable: False type: exitcode-stdio-1.0 hs-source-dirs: plugins/hls-gadt-plugin/test diff --git a/plugins/hls-gadt-plugin/src/Ide/Plugin/GHC.hs b/plugins/hls-gadt-plugin/src/Ide/Plugin/GHC.hs index a85a449704..7d77d7ae87 100644 --- a/plugins/hls-gadt-plugin/src/Ide/Plugin/GHC.hs +++ b/plugins/hls-gadt-plugin/src/Ide/Plugin/GHC.hs @@ -7,16 +7,20 @@ {-# OPTIONS_GHC -Wno-overlapping-patterns #-} module Ide.Plugin.GHC where +#if !MIN_VERSION_ghc(9,11,0) import Data.Functor ((<&>)) +#endif import Data.List.Extra (stripInfix) import qualified Data.Text as T import Development.IDE import Development.IDE.GHC.Compat import Development.IDE.GHC.Compat.ExactPrint -import GHC.Parser.Annotation (AddEpAnn (..), - DeltaPos (..), +import GHC.Parser.Annotation (DeltaPos (..), EpAnn (..), EpAnnComments (EpaComments)) +#if MIN_VERSION_ghc(9,11,0) +import GHC.Parser.Annotation (EpToken (..)) +#endif import Ide.PluginUtils (subRange) import Language.Haskell.GHC.ExactPrint.Parsers (parseDecl) @@ -44,6 +48,11 @@ import GHC.Parser.Annotation (EpUniToken (..), import Language.Haskell.GHC.ExactPrint.Utils (showAst) #endif +#if MIN_VERSION_ghc(9,11,0) +import GHC.Types.SrcLoc (UnhelpfulSpanReason (..)) +#else +import GHC.Parser.Annotation (AddEpAnn (..)) +#endif type GP = GhcPass Parsed @@ -97,7 +106,9 @@ h98ToGADTConDecl :: h98ToGADTConDecl dataName tyVars ctxt = \case ConDeclH98{..} -> ConDeclGADT -#if MIN_VERSION_ghc(9,9,0) +#if MIN_VERSION_ghc(9,11,0) + (AnnConDeclGADT [] [] NoEpUniTok) +#elif MIN_VERSION_ghc(9,9,0) (NoEpUniTok, con_ext) #else con_ext @@ -209,7 +220,11 @@ prettyGADTDecl df decl = adjustDataDecl DataDecl{..} = DataDecl { tcdDExt = adjustWhere tcdDExt , tcdDataDefn = tcdDataDefn - { dd_cons = + { +#if MIN_VERSION_ghc(9,11,0) + dd_ext = adjustDefnWhere (dd_ext tcdDataDefn), +#endif + dd_cons = fmap adjustCon (dd_cons tcdDataDefn) } , .. @@ -218,7 +233,11 @@ prettyGADTDecl df decl = -- Make every data constructor start with a new line and 2 spaces adjustCon :: LConDecl GP -> LConDecl GP -#if MIN_VERSION_ghc(9,9,0) +#if MIN_VERSION_ghc(9,11,0) + adjustCon (L _ r) = + let delta = EpaDelta (UnhelpfulSpan UnhelpfulNoLocationInfo) (DifferentLine 1 2) [] + in L (EpAnn delta (AnnListItem []) (EpaComments [])) r +#elif MIN_VERSION_ghc(9,9,0) adjustCon (L _ r) = let delta = EpaDelta (DifferentLine 1 3) [] in L (EpAnn delta (AnnListItem []) (EpaComments [])) r @@ -229,6 +248,10 @@ prettyGADTDecl df decl = #endif -- Adjust where annotation to the same line of the type constructor +#if MIN_VERSION_ghc(9,11,0) + -- tcdDext is just a placeholder in ghc-9.12 + adjustWhere = id +#else adjustWhere tcdDExt = tcdDExt <&> #if !MIN_VERSION_ghc(9,9,0) map @@ -238,7 +261,16 @@ prettyGADTDecl df decl = then AddEpAnn AnnWhere d1 else AddEpAnn ann l ) +#endif +#if MIN_VERSION_ghc(9,11,0) + adjustDefnWhere annDataDefn + | andd_where annDataDefn == NoEpTok = annDataDefn + | otherwise = annDataDefn {andd_where = andd_where'} + where + (EpTok (EpaSpan aw)) = andd_where annDataDefn + andd_where' = EpTok (EpaDelta aw (SameLine 1) []) +#endif -- Remove the first extra line if exist removeExtraEmptyLine s = case stripInfix "\n\n" s of Just (x, xs) -> x <> "\n" <> xs @@ -257,6 +289,10 @@ noUsed = EpAnnNotUsed #endif pattern UserTyVar' :: LIdP pass -> HsTyVarBndr flag pass +#if MIN_VERSION_ghc(9,11,0) +pattern UserTyVar' s <- HsTvb _ _ (HsBndrVar _ s) _ +#else pattern UserTyVar' s <- UserTyVar _ _ s +#endif implicitTyVars = wrapXRec @GP mkHsOuterImplicit diff --git a/test/testdata/schema/ghc912/default-config.golden.json b/test/testdata/schema/ghc912/default-config.golden.json index c082c3091b..0dfbd39df2 100644 --- a/test/testdata/schema/ghc912/default-config.golden.json +++ b/test/testdata/schema/ghc912/default-config.golden.json @@ -59,6 +59,9 @@ "path": "fourmolu" } }, + "gadt": { + "globalOn": true + }, "ghcide-code-actions-bindings": { "globalOn": true }, diff --git a/test/testdata/schema/ghc912/vscode-extension-schema.golden.json b/test/testdata/schema/ghc912/vscode-extension-schema.golden.json index 864602002a..77d398438e 100644 --- a/test/testdata/schema/ghc912/vscode-extension-schema.golden.json +++ b/test/testdata/schema/ghc912/vscode-extension-schema.golden.json @@ -131,6 +131,12 @@ "scope": "resource", "type": "string" }, + "haskell.plugin.gadt.globalOn": { + "default": true, + "description": "Enables gadt plugin", + "scope": "resource", + "type": "boolean" + }, "haskell.plugin.ghcide-code-actions-bindings.globalOn": { "default": true, "description": "Enables ghcide-code-actions-bindings plugin",