Skip to content

Enable hls-plugin-gadt for ghc-9.12 #4568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/support/ghc-version-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
2 changes: 1 addition & 1 deletion docs/support/plugin-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |
Expand Down
6 changes: 3 additions & 3 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
46 changes: 41 additions & 5 deletions plugins/hls-gadt-plugin/src/Ide/Plugin/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
, ..
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
3 changes: 3 additions & 0 deletions test/testdata/schema/ghc912/default-config.golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
"path": "fourmolu"
}
},
"gadt": {
"globalOn": true
},
"ghcide-code-actions-bindings": {
"globalOn": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading