@@ -69,8 +69,7 @@ import Development.IDE.Types.Diagnostics
69
69
import Development.IDE.Types.Exports
70
70
import Development.IDE.Types.Location
71
71
import Development.IDE.Types.Options
72
- import GHC (AddEpAnn (AddEpAnn ),
73
- AnnsModule (am_main ),
72
+ import GHC (
74
73
DeltaPos (.. ),
75
74
EpAnn (.. ),
76
75
LEpaComment )
@@ -105,17 +104,30 @@ import Text.Regex.TDFA ((=~), (=~~))
105
104
106
105
#if !MIN_VERSION_ghc(9,9,0)
107
106
import 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 ),
109
110
AnchorOperation (.. ),
110
111
EpaLocation (.. ))
111
112
#endif
112
113
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 ,
115
118
EpaLocation' (.. ),
116
119
HasLoc (.. ))
117
120
import GHC.Types.SrcLoc (srcSpanToRealSrcSpan )
118
121
#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
+
119
131
120
132
-------------------------------------------------------------------------------------------------
121
133
@@ -339,7 +351,11 @@ findSigOfBinds range = go
339
351
case unLoc <$> findDeclContainingLoc (_start range) lsigs of
340
352
Just sig' -> Just sig'
341
353
Nothing -> do
354
+ #if MIN_VERSION_ghc(9,11,0)
355
+ lHsBindLR <- findDeclContainingLoc (_start range) binds
356
+ #else
342
357
lHsBindLR <- findDeclContainingLoc (_start range) (bagToList binds)
358
+ #endif
343
359
findSigOfBind range (unLoc lHsBindLR)
344
360
go _ = Nothing
345
361
@@ -420,7 +436,11 @@ isUnusedImportedId
420
436
modName
421
437
importSpan
422
438
| occ <- mkVarOcc identifier,
439
+ #if MIN_VERSION_ghc(9,11,0)
440
+ impModsVals <- importedByUser . concat $ imp_mods,
441
+ #else
423
442
impModsVals <- importedByUser . concat $ moduleEnvElts imp_mods,
443
+ #endif
424
444
Just rdrEnv <-
425
445
listToMaybe
426
446
[ imv_all_exports
@@ -659,7 +679,11 @@ suggestDeleteUnusedBinding
659
679
name
660
680
(L _ Match {m_grhss= GRHSs {grhssLocalBinds}}) = do
661
681
let go bag lsigs =
682
+ #if MIN_VERSION_ghc(9,11,0)
683
+ if null bag
684
+ #else
662
685
if isEmptyBag bag
686
+ #endif
663
687
then []
664
688
else concatMap (findRelatedSpanForHsBind indexedContent name lsigs) bag
665
689
case grhssLocalBinds of
@@ -1700,13 +1724,22 @@ findPositionAfterModuleName ps _hsmodName' = do
1700
1724
#endif
1701
1725
EpAnn _ annsModule _ -> do
1702
1726
-- Find the first 'where'
1727
+ #if MIN_VERSION_ghc(9,11,0)
1728
+ whereLocation <- filterWhere $ am_where annsModule
1729
+ #else
1703
1730
whereLocation <- listToMaybe . mapMaybe filterWhere $ am_main annsModule
1731
+ #endif
1704
1732
epaLocationToLine whereLocation
1705
1733
#if !MIN_VERSION_ghc(9,9,0)
1706
1734
EpAnnNotUsed -> Nothing
1707
1735
#endif
1736
+ #if MIN_VERSION_ghc(9,11,0)
1737
+ filterWhere (EpTok loc) = Just loc
1738
+ filterWhere _ = Nothing
1739
+ #else
1708
1740
filterWhere (AddEpAnn AnnWhere loc) = Just loc
1709
1741
filterWhere _ = Nothing
1742
+ #endif
1710
1743
1711
1744
epaLocationToLine :: EpaLocation -> Maybe Int
1712
1745
#if MIN_VERSION_ghc(9,9,0)
@@ -1719,20 +1752,32 @@ findPositionAfterModuleName ps _hsmodName' = do
1719
1752
epaLocationToLine (EpaSpan sp)
1720
1753
= Just . srcLocLine . realSrcSpanEnd $ sp
1721
1754
#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
1722
1762
epaLocationToLine (EpaDelta (SameLine _) priorComments) = Just $ sumCommentsOffset priorComments
1723
1763
-- 'priorComments' contains the comments right before the current EpaLocation
1724
1764
-- Summing line offset of priorComments is necessary, as 'line' is the gap between the last comment and
1725
1765
-- the current AST node
1726
1766
epaLocationToLine (EpaDelta (DifferentLine line _) priorComments) = Just (line + sumCommentsOffset priorComments)
1727
-
1767
+ #endif
1728
1768
sumCommentsOffset :: [LEpaComment ] -> Int
1729
1769
#if MIN_VERSION_ghc(9,9,0)
1730
1770
sumCommentsOffset = sum . fmap (\ (L anchor _) -> anchorOpLine anchor)
1731
1771
#else
1732
1772
sumCommentsOffset = sum . fmap (\ (L anchor _) -> anchorOpLine (anchor_op anchor))
1733
1773
#endif
1734
1774
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)
1736
1781
anchorOpLine :: EpaLocation' a -> Int
1737
1782
anchorOpLine EpaSpan {} = 0
1738
1783
anchorOpLine (EpaDelta (SameLine _) _) = 0
0 commit comments