Skip to content

Commit 6b00690

Browse files
committed
Fix backcompat
1 parent 20dd3e0 commit 6b00690

File tree

1 file changed

+28
-12
lines changed
  • plugins/hls-splice-plugin/src/Ide/Plugin

1 file changed

+28
-12
lines changed

plugins/hls-splice-plugin/src/Ide/Plugin/Splice.hs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ import Language.LSP.Server
5757
import Language.LSP.Types
5858
import Language.LSP.Types.Capabilities
5959
import qualified Language.LSP.Types.Lens as J
60+
#if __GLASGOW_HASKELL__ >= 902
6061
import qualified GHC.Types.Error as Error
62+
#endif
6163

6264
descriptor :: PluginId -> PluginDescriptor IdeState
6365
descriptor plId =
@@ -122,13 +124,13 @@ expandTHSplice _eStyle ideState params@ExpandSpliceParams {..} = do
122124
withTypeChecked fp TcModuleResult {..} = do
123125
(ps, _hscEnv, dflags) <- setupHscEnv ideState fp tmrParsed
124126
let Splices {..} = tmrTopLevelSplices
125-
let
127+
let exprSuperSpans =
128+
listToMaybe $ findSubSpansDesc srcSpan exprSplices
126129
_patSuperSpans =
130+
#if __GLASGOW_HASKELL__ == 808
131+
fmap (second dL) $
132+
#endif
127133
listToMaybe $ findSubSpansDesc srcSpan patSplices
128-
129-
exprSuperSpans =
130-
listToMaybe $ findSubSpansDesc srcSpan exprSplices
131-
132134
typeSuperSpans =
133135
listToMaybe $ findSubSpansDesc srcSpan typeSplices
134136
declSuperSpans =
@@ -269,8 +271,7 @@ findSubSpansDesc :: SrcSpan -> [(LHsExpr GhcTc, a)] -> [(SrcSpan, a)]
269271
findSubSpansDesc srcSpan =
270272
sortOn (Down . SubSpan . fst)
271273
. mapMaybe
272-
( \(lcted, e) -> do
273-
let spn = getLocA lcted
274+
( \(getLocA -> spn, e) -> do
274275
guard (spn `isSubspanOf` srcSpan)
275276
pure (spn, e)
276277
)
@@ -353,9 +354,12 @@ manualCalcEdit clientCapabilities reportEditor ran ps hscEnv typechkd srcSpan _e
353354
)
354355
Just <$> either (pure . L _spn) (unRenamedE dflags) eExpr
355356
_ -> pure Nothing
356-
let
357-
warns = Error.getWarningMessages msgs
358-
errs = Error.getErrorMessages msgs
357+
let (warns, errs) =
358+
#if __GLASGOW_HASKELL__ >= 902
359+
(Error.getWarningMessages msgs, Error.getErrorMessages msgs)
360+
#else
361+
msgs
362+
#endif
359363
pure $ (warns,) <$> fromMaybe (Left $ show errs) eresl
360364

361365
unless
@@ -379,10 +383,17 @@ unRenamedE ::
379383
TransformT m (LocatedAn l (ast GhcPs))
380384
unRenamedE dflags expr = do
381385
uniq <- show <$> uniqueSrcSpanT
382-
either (fail . show) pure $
386+
r <- either (fail . show) pure $
383387
parseAST @_ @(ast GhcPs) dflags uniq $
384388
showSDoc dflags $ ppr expr
385389

390+
#if __GLASGOW_HASKELL__ >= 902
391+
pure r
392+
#else
393+
let (_anns, expr') = r
394+
pure expr'
395+
#endif
396+
386397
data SearchResult r =
387398
Continue | Stop | Here r
388399
deriving (Read, Show, Eq, Ord, Data, Typeable)
@@ -432,7 +443,12 @@ codeAction state plId (CodeActionParams _ _ docId ran _) = liftIO $
432443
_ -> Continue
433444
_ -> Stop
434445
)
435-
`extQ` (\loced@(L _ pat :: LPat GhcPs) ->
446+
`extQ` (
447+
#if __GLASGOW_HASKELL__ == 808
448+
\dL @(Pat GhcPs) -> loced@(L _ pat :: Located (Pat GhcPs)) ->
449+
#else
450+
\loced@(L _ pat :: LPat GhcPs) ->
451+
#endif
436452
let thisSpan = getLocA loced
437453
in case thisSpan of
438454
RealSrcSpan spLoc _

0 commit comments

Comments
 (0)