From https://github.com/haskell/haskell-language-server/pull/4568
From: GuillaumedeVolpiano <xavier@wheredoibegin.fr>
Date: Sun, 6 Apr 2025 11:46:13 +0200
Subject: [PATCH] enable gadt for ghc-9.12

--- 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
--- 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
