@@ -50,7 +50,9 @@ import Development.IDE.Core.Service
50
50
import Development.IDE.Core.Shake hiding (Log )
51
51
import Development.IDE.GHC.Compat hiding
52
52
(ImplicitPrelude )
53
+ #if !MIN_VERSION_ghc(9,11,0)
53
54
import Development.IDE.GHC.Compat.Util
55
+ #endif
54
56
import Development.IDE.GHC.Error
55
57
import Development.IDE.GHC.ExactPrint
56
58
import qualified Development.IDE.GHC.ExactPrint as E
@@ -71,8 +73,7 @@ import Development.IDE.Types.Diagnostics
71
73
import Development.IDE.Types.Exports
72
74
import Development.IDE.Types.Location
73
75
import Development.IDE.Types.Options
74
- import GHC (AddEpAnn (AddEpAnn ),
75
- AnnsModule (am_main ),
76
+ import GHC (
76
77
DeltaPos (.. ),
77
78
EpAnn (.. ),
78
79
LEpaComment )
@@ -107,17 +108,30 @@ import Text.Regex.TDFA ((=~), (=~~))
107
108
108
109
#if !MIN_VERSION_ghc(9,9,0)
109
110
import 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 ),
111
114
AnchorOperation (.. ),
112
115
EpaLocation (.. ))
113
116
#endif
114
117
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 ,
117
122
EpaLocation' (.. ),
118
123
HasLoc (.. ))
119
124
import GHC.Types.SrcLoc (srcSpanToRealSrcSpan )
120
125
#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
+
121
135
122
136
-------------------------------------------------------------------------------------------------
123
137
@@ -341,7 +355,11 @@ findSigOfBinds range = go
341
355
case unLoc <$> findDeclContainingLoc (_start range) lsigs of
342
356
Just sig' -> Just sig'
343
357
Nothing -> do
358
+ #if MIN_VERSION_ghc(9,11,0)
359
+ lHsBindLR <- findDeclContainingLoc (_start range) binds
360
+ #else
344
361
lHsBindLR <- findDeclContainingLoc (_start range) (bagToList binds)
362
+ #endif
345
363
findSigOfBind range (unLoc lHsBindLR)
346
364
go _ = Nothing
347
365
@@ -422,7 +440,11 @@ isUnusedImportedId
422
440
modName
423
441
importSpan
424
442
| occ <- mkVarOcc identifier,
443
+ #if MIN_VERSION_ghc(9,11,0)
444
+ impModsVals <- importedByUser . concat $ M. elems imp_mods,
445
+ #else
425
446
impModsVals <- importedByUser . concat $ moduleEnvElts imp_mods,
447
+ #endif
426
448
Just rdrEnv <-
427
449
listToMaybe
428
450
[ imv_all_exports
@@ -661,7 +683,11 @@ suggestDeleteUnusedBinding
661
683
name
662
684
(L _ Match {m_grhss= GRHSs {grhssLocalBinds}}) = do
663
685
let go bag lsigs =
686
+ #if MIN_VERSION_ghc(9,11,0)
687
+ if null bag
688
+ #else
664
689
if isEmptyBag bag
690
+ #endif
665
691
then []
666
692
else concatMap (findRelatedSpanForHsBind indexedContent name lsigs) bag
667
693
case grhssLocalBinds of
@@ -1723,13 +1749,22 @@ findPositionAfterModuleName ps _hsmodName' = do
1723
1749
#endif
1724
1750
EpAnn _ annsModule _ -> do
1725
1751
-- Find the first 'where'
1752
+ #if MIN_VERSION_ghc(9,11,0)
1753
+ whereLocation <- filterWhere $ am_where annsModule
1754
+ #else
1726
1755
whereLocation <- listToMaybe . mapMaybe filterWhere $ am_main annsModule
1756
+ #endif
1727
1757
epaLocationToLine whereLocation
1728
1758
#if !MIN_VERSION_ghc(9,9,0)
1729
1759
EpAnnNotUsed -> Nothing
1730
1760
#endif
1761
+ #if MIN_VERSION_ghc(9,11,0)
1762
+ filterWhere (EpTok loc) = Just loc
1763
+ filterWhere _ = Nothing
1764
+ #else
1731
1765
filterWhere (AddEpAnn AnnWhere loc) = Just loc
1732
1766
filterWhere _ = Nothing
1767
+ #endif
1733
1768
1734
1769
epaLocationToLine :: EpaLocation -> Maybe Int
1735
1770
#if MIN_VERSION_ghc(9,9,0)
@@ -1742,20 +1777,32 @@ findPositionAfterModuleName ps _hsmodName' = do
1742
1777
epaLocationToLine (EpaSpan sp)
1743
1778
= Just . srcLocLine . realSrcSpanEnd $ sp
1744
1779
#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
1745
1787
epaLocationToLine (EpaDelta (SameLine _) priorComments) = Just $ sumCommentsOffset priorComments
1746
1788
-- 'priorComments' contains the comments right before the current EpaLocation
1747
1789
-- Summing line offset of priorComments is necessary, as 'line' is the gap between the last comment and
1748
1790
-- the current AST node
1749
1791
epaLocationToLine (EpaDelta (DifferentLine line _) priorComments) = Just (line + sumCommentsOffset priorComments)
1750
-
1792
+ #endif
1751
1793
sumCommentsOffset :: [LEpaComment ] -> Int
1752
1794
#if MIN_VERSION_ghc(9,9,0)
1753
1795
sumCommentsOffset = sum . fmap (\ (L anchor _) -> anchorOpLine anchor)
1754
1796
#else
1755
1797
sumCommentsOffset = sum . fmap (\ (L anchor _) -> anchorOpLine (anchor_op anchor))
1756
1798
#endif
1757
1799
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)
1759
1806
anchorOpLine :: EpaLocation' a -> Int
1760
1807
anchorOpLine EpaSpan {} = 0
1761
1808
anchorOpLine (EpaDelta (SameLine _) _) = 0
@@ -1936,14 +1983,11 @@ extractQualifiedModuleName x
1936
1983
-- ‘Data.Functor’ nor ‘Data.Text’ exports ‘putStrLn’.
1937
1984
extractDoesNotExportModuleName :: T. Text -> Maybe T. Text
1938
1985
extractDoesNotExportModuleName 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"
1947
1991
= Just m
1948
1992
| otherwise
1949
1993
= Nothing
0 commit comments