@@ -69,8 +69,7 @@ import Development.IDE.Types.Diagnostics
6969import Development.IDE.Types.Exports
7070import Development.IDE.Types.Location
7171import Development.IDE.Types.Options
72- import GHC (AddEpAnn (AddEpAnn ),
73- AnnsModule (am_main ),
72+ import GHC (
7473 DeltaPos (.. ),
7574 EpAnn (.. ),
7675 LEpaComment )
@@ -105,17 +104,30 @@ import Text.Regex.TDFA ((=~), (=~~))
105104
106105#if !MIN_VERSION_ghc(9,9,0)
107106import Development.IDE.GHC.Compat.ExactPrint (makeDeltaAst )
108- import GHC (Anchor (anchor_op ),
107+ import GHC (AddEpAnn (AddEpAnn ),
108+ AnnsModule (am_main ),
109+ Anchor (anchor_op ),
109110 AnchorOperation (.. ),
110111 EpaLocation (.. ))
111112#endif
112113
113- #if MIN_VERSION_ghc(9,9,0)
114- import GHC (EpaLocation ,
114+ #if MIN_VERSION_ghc(9,9,0) && !MIN_VERSION_ghc(9,11,0)
115+ import GHC (AddEpAnn (AddEpAnn ),
116+ AnnsModule (am_main ),
117+ EpaLocation ,
115118 EpaLocation' (.. ),
116119 HasLoc (.. ))
117120import GHC.Types.SrcLoc (srcSpanToRealSrcSpan )
118121#endif
122+ #if MIN_VERSION_ghc(9,11,0)
123+ import GHC (EpaLocation ,
124+ AnnsModule (am_where ),
125+ EpaLocation' (.. ),
126+ HasLoc (.. ),
127+ EpToken (.. ))
128+ import GHC.Types.SrcLoc (srcSpanToRealSrcSpan )
129+ #endif
130+
119131
120132-------------------------------------------------------------------------------------------------
121133
@@ -339,7 +351,11 @@ findSigOfBinds range = go
339351 case unLoc <$> findDeclContainingLoc (_start range) lsigs of
340352 Just sig' -> Just sig'
341353 Nothing -> do
354+ #if MIN_VERSION_ghc(9,11,0)
355+ lHsBindLR <- findDeclContainingLoc (_start range) binds
356+ #else
342357 lHsBindLR <- findDeclContainingLoc (_start range) (bagToList binds)
358+ #endif
343359 findSigOfBind range (unLoc lHsBindLR)
344360 go _ = Nothing
345361
@@ -420,7 +436,11 @@ isUnusedImportedId
420436 modName
421437 importSpan
422438 | occ <- mkVarOcc identifier,
439+ #if MIN_VERSION_ghc(9,11,0)
440+ impModsVals <- importedByUser . concat $ imp_mods,
441+ #else
423442 impModsVals <- importedByUser . concat $ moduleEnvElts imp_mods,
443+ #endif
424444 Just rdrEnv <-
425445 listToMaybe
426446 [ imv_all_exports
@@ -659,7 +679,11 @@ suggestDeleteUnusedBinding
659679 name
660680 (L _ Match {m_grhss= GRHSs {grhssLocalBinds}}) = do
661681 let go bag lsigs =
682+ #if MIN_VERSION_ghc(9,11,0)
683+ if null bag
684+ #else
662685 if isEmptyBag bag
686+ #endif
663687 then []
664688 else concatMap (findRelatedSpanForHsBind indexedContent name lsigs) bag
665689 case grhssLocalBinds of
@@ -1700,13 +1724,22 @@ findPositionAfterModuleName ps _hsmodName' = do
17001724#endif
17011725 EpAnn _ annsModule _ -> do
17021726 -- Find the first 'where'
1727+ #if MIN_VERSION_ghc(9,11,0)
1728+ whereLocation <- filterWhere $ am_where annsModule
1729+ #else
17031730 whereLocation <- listToMaybe . mapMaybe filterWhere $ am_main annsModule
1731+ #endif
17041732 epaLocationToLine whereLocation
17051733#if !MIN_VERSION_ghc(9,9,0)
17061734 EpAnnNotUsed -> Nothing
17071735#endif
1736+ #if MIN_VERSION_ghc(9,11,0)
1737+ filterWhere (EpTok loc) = Just loc
1738+ filterWhere _ = Nothing
1739+ #else
17081740 filterWhere (AddEpAnn AnnWhere loc) = Just loc
17091741 filterWhere _ = Nothing
1742+ #endif
17101743
17111744 epaLocationToLine :: EpaLocation -> Maybe Int
17121745#if MIN_VERSION_ghc(9,9,0)
@@ -1719,20 +1752,32 @@ findPositionAfterModuleName ps _hsmodName' = do
17191752 epaLocationToLine (EpaSpan sp)
17201753 = Just . srcLocLine . realSrcSpanEnd $ sp
17211754#endif
1755+ #if MIN_VERSION_ghc(9,11,0)
1756+ epaLocationToLine (EpaDelta _ (SameLine _) priorComments) = Just $ sumCommentsOffset priorComments
1757+ -- 'priorComments' contains the comments right before the current EpaLocation
1758+ -- Summing line offset of priorComments is necessary, as 'line' is the gap between the last comment and
1759+ -- the current AST node
1760+ epaLocationToLine (EpaDelta _ (DifferentLine line _) priorComments) = Just (line + sumCommentsOffset priorComments)
1761+ #else
17221762 epaLocationToLine (EpaDelta (SameLine _) priorComments) = Just $ sumCommentsOffset priorComments
17231763 -- 'priorComments' contains the comments right before the current EpaLocation
17241764 -- Summing line offset of priorComments is necessary, as 'line' is the gap between the last comment and
17251765 -- the current AST node
17261766 epaLocationToLine (EpaDelta (DifferentLine line _) priorComments) = Just (line + sumCommentsOffset priorComments)
1727-
1767+ #endif
17281768 sumCommentsOffset :: [LEpaComment ] -> Int
17291769#if MIN_VERSION_ghc(9,9,0)
17301770 sumCommentsOffset = sum . fmap (\ (L anchor _) -> anchorOpLine anchor)
17311771#else
17321772 sumCommentsOffset = sum . fmap (\ (L anchor _) -> anchorOpLine (anchor_op anchor))
17331773#endif
17341774
1735- #if MIN_VERSION_ghc(9,9,0)
1775+ #if MIN_VERSION_ghc(9,11,0)
1776+ anchorOpLine :: EpaLocation' a -> Int
1777+ anchorOpLine EpaSpan {} = 0
1778+ anchorOpLine (EpaDelta _ (SameLine _) _) = 0
1779+ anchorOpLine (EpaDelta _ (DifferentLine line _) _) = line
1780+ #elif MIN_VERSION_ghc(9,9,0)
17361781 anchorOpLine :: EpaLocation' a -> Int
17371782 anchorOpLine EpaSpan {} = 0
17381783 anchorOpLine (EpaDelta (SameLine _) _) = 0
0 commit comments