Skip to content

Commit 4a1575b

Browse files
committed
hls-splice-plugin 9.6 compat
1 parent 8055f0c commit 4a1575b

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

haskell-language-server.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ common pragmas
287287
cpp-options: -Dhls_pragmas
288288

289289
common splice
290-
if flag(splice) && impl(ghc < 9.5)
290+
if flag(splice)
291291
build-depends: hls-splice-plugin ^>=1.0.0.1
292292
cpp-options: -Dhls_splice
293293

plugins/hls-splice-plugin/hls-splice-plugin.cabal

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ source-repository head
2727
location: https://github.com/haskell/haskell-language-server.git
2828

2929
library
30-
if impl(ghc >= 9.5)
31-
buildable: False
3230
exposed-modules:
3331
Ide.Plugin.Splice
3432
Ide.Plugin.Splice.Types
@@ -62,8 +60,6 @@ library
6260
TypeOperators
6361

6462
test-suite tests
65-
if impl(ghc >= 9.5)
66-
buildable: False
6763
type: exitcode-stdio-1.0
6864
default-language: Haskell2010
6965
hs-source-dirs: test

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

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,24 +295,56 @@ data SpliceClass where
295295
OneToOneAST :: HasSplice AnnListItem ast => Proxy# ast -> SpliceClass
296296
IsHsDecl :: SpliceClass
297297

298+
#if MIN_VERSION_ghc(9,5,0)
299+
data HsSpliceCompat pass
300+
= UntypedSplice (HsUntypedSplice pass)
301+
| TypedSplice (LHsExpr pass)
302+
#endif
303+
304+
298305
class (Outputable (ast GhcRn), ASTElement l (ast GhcPs)) => HasSplice l ast where
299306
type SpliceOf ast :: Kinds.Type -> Kinds.Type
300-
type SpliceOf ast = HsSplice
301307
matchSplice :: Proxy# ast -> ast GhcPs -> Maybe (SpliceOf ast GhcPs)
302308
expandSplice :: Proxy# ast -> SpliceOf ast GhcPs -> RnM (Either (ast GhcPs) (ast GhcRn), FreeVars)
303309

304310
instance HasSplice AnnListItem HsExpr where
311+
#if MIN_VERSION_ghc(9,5,0)
312+
type SpliceOf HsExpr = HsSpliceCompat
313+
matchSplice _ (HsUntypedSplice _ spl) = Just (UntypedSplice spl)
314+
matchSplice _ (HsTypedSplice _ spl) = Just (TypedSplice spl)
315+
#else
316+
type SpliceOf HsExpr = HsSplice
305317
matchSplice _ (HsSpliceE _ spl) = Just spl
318+
#endif
306319
matchSplice _ _ = Nothing
320+
#if MIN_VERSION_ghc(9,5,0)
321+
expandSplice _ (UntypedSplice e) = fmap (first Right) $ rnUntypedSpliceExpr e
322+
expandSplice _ (TypedSplice e) = fmap (first Right) $ rnTypedSplice e
323+
#else
307324
expandSplice _ = fmap (first Right) . rnSpliceExpr
325+
#endif
308326

309327
instance HasSplice AnnListItem Pat where
328+
#if MIN_VERSION_ghc(9,5,0)
329+
type SpliceOf Pat = HsUntypedSplice
330+
#else
331+
type SpliceOf Pat = HsSplice
332+
#endif
310333
matchSplice _ (SplicePat _ spl) = Just spl
311334
matchSplice _ _ = Nothing
312-
expandSplice _ = rnSplicePat
335+
expandSplice _ =
336+
#if MIN_VERSION_ghc(9,5,0)
337+
fmap (first (Left . unLoc . utsplice_result . snd )) .
338+
#endif
339+
rnSplicePat
313340

314341

315342
instance HasSplice AnnListItem HsType where
343+
#if MIN_VERSION_ghc(9,5,0)
344+
type SpliceOf HsType = HsUntypedSplice
345+
#else
346+
type SpliceOf HsType = HsSplice
347+
#endif
316348
matchSplice _ (HsSpliceTy _ spl) = Just spl
317349
matchSplice _ _ = Nothing
318350
expandSplice _ = fmap (first Right) . rnSpliceType
@@ -401,10 +433,15 @@ manualCalcEdit clientCapabilities reportEditor ran ps hscEnv typechkd srcSpan _e
401433
showBag :: Error.Diagnostic a => Bag (Error.MsgEnvelope a) -> String
402434
showBag = show . fmap (fmap toDiagnosticMessage)
403435

404-
toDiagnosticMessage :: Error.Diagnostic a => a -> Error.DiagnosticMessage
436+
toDiagnosticMessage :: forall a. Error.Diagnostic a => a -> Error.DiagnosticMessage
405437
toDiagnosticMessage message =
406438
Error.DiagnosticMessage
407-
{ diagMessage = Error.diagnosticMessage message
439+
{ diagMessage = Error.diagnosticMessage
440+
#if MIN_VERSION_ghc(9,5,0)
441+
(Error.defaultDiagnosticOpts @a)
442+
#endif
443+
message
444+
408445
, diagReason = Error.diagnosticReason message
409446
, diagHints = Error.diagnosticHints message
410447
}
@@ -480,7 +517,12 @@ codeAction state plId (CodeActionParams _ _ docId ran _) = liftIO $
480517
(L (AsSrcSpan l@(RealSrcSpan spLoc _)) expr :: LHsExpr GhcPs)
481518
| spanIsRelevant l ->
482519
case expr of
520+
#if MIN_VERSION_ghc(9,5,0)
521+
HsTypedSplice{} -> Here (spLoc, Expr)
522+
HsUntypedSplice{} -> Here (spLoc, Expr)
523+
#else
483524
HsSpliceE {} -> Here (spLoc, Expr)
525+
#endif
484526
_ -> Continue
485527
_ -> Stop
486528
)

0 commit comments

Comments
 (0)