Skip to content

Commit 9b8705f

Browse files
committed
More compatibility changes
1 parent d9687d2 commit 9b8705f

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

  • ghcide/src/Development/IDE/Plugin/Completions

ghcide/src/Development/IDE/Plugin/Completions/Context.hs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{-# LANGUAGE DerivingStrategies #-}
33
{-# LANGUAGE NoFieldSelectors #-}
44
{-# LANGUAGE TypeFamilies #-}
5+
{- HLINT ignore "Avoid restricted function" -}
56

67
module Development.IDE.Plugin.Completions.Context
78
( Context (..)
@@ -14,12 +15,13 @@ module Development.IDE.Plugin.Completions.Context
1415
) where
1516

1617
import Control.DeepSeq (NFData (..), rwhnf)
18+
import Control.Monad (join)
1719
import Data.Generics (Data (..), GenericQ,
1820
extQ, mkQ)
1921
import Data.Hashable (Hashable)
2022
import Data.List.Extra (nubOrd)
21-
import Data.Maybe (fromJust, isJust,
22-
mapMaybe)
23+
import Data.Maybe (isJust, mapMaybe,
24+
maybeToList)
2325
import qualified Data.Text as T
2426
import Development.IDE
2527
import Development.IDE.Core.PositionMapping
@@ -93,10 +95,9 @@ groupedChunks n group getPos locate xs = go xs
9395
} : go rest
9496

9597
-- | Build lazy 'ContextChunk' by processing @n@ source items at a time.
96-
singletonChunk :: ContextGroup -> (a -> Maybe Range) -> (a -> Range -> ContextResult) -> a -> ContextChunk
97-
singletonChunk group getPos locate inp = Chunk s e group (locate inp)
98-
where
99-
Range s e = fromJust $ getPos inp
98+
singletonChunk :: ContextGroup -> (a -> Maybe Range) -> (a -> Range -> ContextResult) -> a -> Maybe ContextChunk
99+
singletonChunk group getPos locate inp = flip fmap (getPos inp) $
100+
\(Range s e) -> Chunk s e group (locate inp)
100101

101102
-- | Used during context finding, combines into the tightest interval.
102103
-- As an intuition, the primary interface is through
@@ -134,10 +135,15 @@ getContextMap pm =
134135
ContextMap (isJust hsmodName) $
135136
-- These denote the size of the "jumps" of the cursor when traversing the AST.
136137
-- Reduces the amount of data we have to look at with syb.
137-
singletonChunk HeaderGroup rangeOf getHeaderContext hsmodName
138-
: groupedChunks 10 ImportGroup rangeOf getImportContext hsmodImports
138+
moduleChunk
139+
<> groupedChunks 10 ImportGroup rangeOf getImportContext hsmodImports
139140
<> groupedChunks 2 DeclarationGroup rangeOf getDeclContext hsmodDecls
140141
where
142+
#if MIN_VERSION_ghc(9,9,0)
143+
moduleChunk = maybeToList (singletonChunk HeaderGroup rangeOf getHeaderContext hsmodName)
144+
#else
145+
moduleChunk = maybeToList $ join $ fmap (singletonChunk HeaderGroup rangeOf getHeaderContext) hsmodName
146+
#endif
141147
HsModule {hsmodName, hsmodImports, hsmodDecls} =
142148
unLoc (pm_parsed_source pm)
143149

0 commit comments

Comments
 (0)