@@ -50,7 +50,9 @@ import Development.IDE.Core.Service
5050import Development.IDE.Core.Shake hiding (Log )
5151import Development.IDE.GHC.Compat hiding
5252 (ImplicitPrelude )
53+ #if !MIN_VERSION_ghc(9,11,0)
5354import Development.IDE.GHC.Compat.Util
55+ #endif
5456import Development.IDE.GHC.Error
5557import Development.IDE.GHC.ExactPrint
5658import qualified Development.IDE.GHC.ExactPrint as E
@@ -71,8 +73,7 @@ import Development.IDE.Types.Diagnostics
7173import Development.IDE.Types.Exports
7274import Development.IDE.Types.Location
7375import Development.IDE.Types.Options
74- import GHC (AddEpAnn (AddEpAnn ),
75- AnnsModule (am_main ),
76+ import GHC (
7677 DeltaPos (.. ),
7778 EpAnn (.. ),
7879 LEpaComment )
@@ -107,17 +108,30 @@ import Text.Regex.TDFA ((=~), (=~~))
107108
108109#if !MIN_VERSION_ghc(9,9,0)
109110import Development.IDE.GHC.Compat.ExactPrint (makeDeltaAst )
110- import GHC (Anchor (anchor_op ),
111+ import GHC (AddEpAnn (AddEpAnn ),
112+ AnnsModule (am_main ),
113+ Anchor (anchor_op ),
111114 AnchorOperation (.. ),
112115 EpaLocation (.. ))
113116#endif
114117
115- #if MIN_VERSION_ghc(9,9,0)
116- import GHC (EpaLocation ,
118+ #if MIN_VERSION_ghc(9,9,0) && !MIN_VERSION_ghc(9,11,0)
119+ import GHC (AddEpAnn (AddEpAnn ),
120+ AnnsModule (am_main ),
121+ EpaLocation ,
117122 EpaLocation' (.. ),
118123 HasLoc (.. ))
119124import GHC.Types.SrcLoc (srcSpanToRealSrcSpan )
120125#endif
126+ #if MIN_VERSION_ghc(9,11,0)
127+ import GHC (EpaLocation ,
128+ AnnsModule (am_where ),
129+ EpaLocation' (.. ),
130+ HasLoc (.. ),
131+ EpToken (.. ))
132+ import GHC.Types.SrcLoc (srcSpanToRealSrcSpan )
133+ #endif
134+
121135
122136-------------------------------------------------------------------------------------------------
123137
@@ -341,7 +355,11 @@ findSigOfBinds range = go
341355 case unLoc <$> findDeclContainingLoc (_start range) lsigs of
342356 Just sig' -> Just sig'
343357 Nothing -> do
358+ #if MIN_VERSION_ghc(9,11,0)
359+ lHsBindLR <- findDeclContainingLoc (_start range) binds
360+ #else
344361 lHsBindLR <- findDeclContainingLoc (_start range) (bagToList binds)
362+ #endif
345363 findSigOfBind range (unLoc lHsBindLR)
346364 go _ = Nothing
347365
@@ -422,7 +440,11 @@ isUnusedImportedId
422440 modName
423441 importSpan
424442 | occ <- mkVarOcc identifier,
443+ #if MIN_VERSION_ghc(9,11,0)
444+ impModsVals <- importedByUser . concat $ M. elems imp_mods,
445+ #else
425446 impModsVals <- importedByUser . concat $ moduleEnvElts imp_mods,
447+ #endif
426448 Just rdrEnv <-
427449 listToMaybe
428450 [ imv_all_exports
@@ -661,7 +683,11 @@ suggestDeleteUnusedBinding
661683 name
662684 (L _ Match {m_grhss= GRHSs {grhssLocalBinds}}) = do
663685 let go bag lsigs =
686+ #if MIN_VERSION_ghc(9,11,0)
687+ if null bag
688+ #else
664689 if isEmptyBag bag
690+ #endif
665691 then []
666692 else concatMap (findRelatedSpanForHsBind indexedContent name lsigs) bag
667693 case grhssLocalBinds of
@@ -1723,13 +1749,22 @@ findPositionAfterModuleName ps _hsmodName' = do
17231749#endif
17241750 EpAnn _ annsModule _ -> do
17251751 -- Find the first 'where'
1752+ #if MIN_VERSION_ghc(9,11,0)
1753+ whereLocation <- filterWhere $ am_where annsModule
1754+ #else
17261755 whereLocation <- listToMaybe . mapMaybe filterWhere $ am_main annsModule
1756+ #endif
17271757 epaLocationToLine whereLocation
17281758#if !MIN_VERSION_ghc(9,9,0)
17291759 EpAnnNotUsed -> Nothing
17301760#endif
1761+ #if MIN_VERSION_ghc(9,11,0)
1762+ filterWhere (EpTok loc) = Just loc
1763+ filterWhere _ = Nothing
1764+ #else
17311765 filterWhere (AddEpAnn AnnWhere loc) = Just loc
17321766 filterWhere _ = Nothing
1767+ #endif
17331768
17341769 epaLocationToLine :: EpaLocation -> Maybe Int
17351770#if MIN_VERSION_ghc(9,9,0)
@@ -1742,20 +1777,32 @@ findPositionAfterModuleName ps _hsmodName' = do
17421777 epaLocationToLine (EpaSpan sp)
17431778 = Just . srcLocLine . realSrcSpanEnd $ sp
17441779#endif
1780+ #if MIN_VERSION_ghc(9,11,0)
1781+ epaLocationToLine (EpaDelta _ (SameLine _) priorComments) = Just $ sumCommentsOffset priorComments
1782+ -- 'priorComments' contains the comments right before the current EpaLocation
1783+ -- Summing line offset of priorComments is necessary, as 'line' is the gap between the last comment and
1784+ -- the current AST node
1785+ epaLocationToLine (EpaDelta _ (DifferentLine line _) priorComments) = Just (line + sumCommentsOffset priorComments)
1786+ #else
17451787 epaLocationToLine (EpaDelta (SameLine _) priorComments) = Just $ sumCommentsOffset priorComments
17461788 -- 'priorComments' contains the comments right before the current EpaLocation
17471789 -- Summing line offset of priorComments is necessary, as 'line' is the gap between the last comment and
17481790 -- the current AST node
17491791 epaLocationToLine (EpaDelta (DifferentLine line _) priorComments) = Just (line + sumCommentsOffset priorComments)
1750-
1792+ #endif
17511793 sumCommentsOffset :: [LEpaComment ] -> Int
17521794#if MIN_VERSION_ghc(9,9,0)
17531795 sumCommentsOffset = sum . fmap (\ (L anchor _) -> anchorOpLine anchor)
17541796#else
17551797 sumCommentsOffset = sum . fmap (\ (L anchor _) -> anchorOpLine (anchor_op anchor))
17561798#endif
17571799
1758- #if MIN_VERSION_ghc(9,9,0)
1800+ #if MIN_VERSION_ghc(9,11,0)
1801+ anchorOpLine :: EpaLocation' a -> Int
1802+ anchorOpLine EpaSpan {} = 0
1803+ anchorOpLine (EpaDelta _ (SameLine _) _) = 0
1804+ anchorOpLine (EpaDelta _ (DifferentLine line _) _) = line
1805+ #elif MIN_VERSION_ghc(9,9,0)
17591806 anchorOpLine :: EpaLocation' a -> Int
17601807 anchorOpLine EpaSpan {} = 0
17611808 anchorOpLine (EpaDelta (SameLine _) _) = 0
@@ -1936,14 +1983,11 @@ extractQualifiedModuleName x
19361983-- ‘Data.Functor’ nor ‘Data.Text’ exports ‘putStrLn’.
19371984extractDoesNotExportModuleName :: T. Text -> Maybe T. Text
19381985extractDoesNotExportModuleName x
1939- | Just [m] <-
1940- #if MIN_VERSION_ghc(9,4,0)
1941- matchRegexUnifySpaces x " the module ‘([^’]*)’ does not export"
1942- <|> matchRegexUnifySpaces x " nor ‘([^’]*)’ export"
1943- #else
1944- matchRegexUnifySpaces x " Module ‘([^’]*)’ does not export"
1945- <|> matchRegexUnifySpaces x " nor ‘([^’]*)’ exports"
1946- #endif
1986+ | Just [m] <- case ghcVersion of
1987+ GHC912 -> matchRegexUnifySpaces x " The module ‘([^’]*)’ does not export"
1988+ <|> matchRegexUnifySpaces x " nor ‘([^’]*)’ export"
1989+ _ -> matchRegexUnifySpaces x " the module ‘([^’]*)’ does not export"
1990+ <|> matchRegexUnifySpaces x " nor ‘([^’]*)’ export"
19471991 = Just m
19481992 | otherwise
19491993 = Nothing
0 commit comments