11
11
{-# LANGUAGE StandaloneDeriving #-}
12
12
{-# LANGUAGE TypeApplications #-}
13
13
{-# LANGUAGE TypeFamilies #-}
14
+ {-# LANGUAGE ViewPatterns #-}
14
15
15
16
{-# OPTIONS -Wno-orphans #-}
16
17
@@ -51,13 +52,13 @@ import Development.IDE hiding (pluginHandlers)
51
52
import Development.IDE.Core.PositionMapping
52
53
import Development.IDE.Core.Shake (ShakeExtras (knownTargetsVar ),
53
54
toKnownFiles )
54
- import Development.IDE.GHC.Compat (GenLocated (L ), GhcRn ,
55
+ import Development.IDE.GHC.Compat (GenLocated (L ), GhcPs ,
56
+ GhcRn , GhcTc ,
55
57
HsBindLR (FunBind ),
56
58
HsGroup (.. ),
57
59
HsValBindsLR (.. ),
58
60
HscEnv , IdP , LRuleDecls ,
59
61
ModSummary (ModSummary , ms_hspp_buf , ms_mod ),
60
- NHsValBindsLR (.. ),
61
62
Outputable ,
62
63
ParsedModule (.. ),
63
64
RuleDecl (HsRule ),
@@ -67,21 +68,24 @@ import Development.IDE.GHC.Compat (GenLocated (L), GhcRn,
67
68
TyClDecl (SynDecl ),
68
69
TyClGroup (.. ), fun_id ,
69
70
hm_iface , isQual ,
70
- isQual_maybe ,
71
+ isQual_maybe , locA ,
71
72
mi_fixities ,
72
73
moduleNameString ,
73
74
nameModule_maybe ,
74
- nameRdrName , occNameFS ,
75
- occNameString ,
76
- parseModule ,
75
+ nameRdrName , noLocA ,
76
+ occNameFS , occNameString ,
77
77
pattern IsBoot ,
78
78
pattern NotBoot ,
79
79
pattern RealSrcSpan ,
80
+ pm_parsed_source ,
80
81
rdrNameOcc , rds_rules ,
81
- srcSpanFile )
82
+ srcSpanFile , unLocA )
82
83
import Development.IDE.GHC.Compat.Util hiding (catch , try )
83
- import qualified GHC (parseModule )
84
+ import qualified GHC (Module ,
85
+ ParsedModule (.. ),
86
+ moduleName , parseModule )
84
87
import GHC.Generics (Generic )
88
+ import GHC.Paths (libdir )
85
89
import Ide.PluginUtils
86
90
import Ide.Types
87
91
import Language.LSP.Server (LspM ,
@@ -94,8 +98,13 @@ import Language.LSP.Types as J hiding
94
98
SemanticTokenRelative (length ),
95
99
SemanticTokensEdit (_start ))
96
100
import Retrie.CPP (CPP (NoCPP ), parseCPP )
97
- import Retrie.ExactPrint (fix , relativiseApiAnns ,
101
+ import Retrie.ExactPrint (Annotated , fix ,
98
102
transformA , unsafeMkA )
103
+ #if MIN_VERSION_ghc(9,2,0)
104
+ import Retrie.ExactPrint (makeDeltaAst )
105
+ #else
106
+ import Retrie.ExactPrint (relativiseApiAnns )
107
+ #endif
99
108
import Retrie.Fixity (mkFixityEnv )
100
109
import qualified Retrie.GHC as GHC
101
110
import Retrie.Monad (addImports , apply ,
@@ -202,7 +211,7 @@ provider state plId (CodeActionParams _ _ (TextDocumentIdentifier uri) range ca)
202
211
++ concatMap (suggestRuleRewrites uri pos ms_mod) hs_ruleds
203
212
++ [ r
204
213
| TyClGroup {group_tyclds} <- hs_tyclds,
205
- L l g <- group_tyclds,
214
+ L (locA -> l) g <- group_tyclds,
206
215
pos `isInsideSrcSpan` l,
207
216
r <- suggestTypeRewrites uri ms_mod g
208
217
@@ -225,7 +234,7 @@ getBinds nfp = runMaybeT $ do
225
234
( HsGroup
226
235
{ hs_valds =
227
236
XValBindsLR
228
- (NValBinds binds _sigs :: NHsValBindsLR GHC. GhcRn ),
237
+ (GHC. NValBinds binds _sigs :: GHC. NHsValBindsLR GhcRn ),
229
238
hs_ruleds,
230
239
hs_tyclds
231
240
},
@@ -247,7 +256,7 @@ suggestBindRewrites ::
247
256
GHC. Module ->
248
257
HsBindLR GhcRn GhcRn ->
249
258
[(T. Text , CodeActionKind , RunRetrieParams )]
250
- suggestBindRewrites originatingFile pos ms_mod FunBind {fun_id = L l' rdrName}
259
+ suggestBindRewrites originatingFile pos ms_mod FunBind {fun_id = L (locA -> l') rdrName}
251
260
| pos `isInsideSrcSpan` l' =
252
261
let pprNameText = printOutputable rdrName
253
262
pprName = T. unpack pprNameText
@@ -267,13 +276,13 @@ describeRestriction restrictToOriginatingFile =
267
276
if restrictToOriginatingFile then " in current file" else " "
268
277
269
278
suggestTypeRewrites ::
270
- (Outputable (IdP pass )) =>
279
+ (Outputable (IdP GhcRn )) =>
271
280
Uri ->
272
281
GHC. Module ->
273
- TyClDecl pass ->
282
+ TyClDecl GhcRn ->
274
283
[(T. Text , CodeActionKind , RunRetrieParams )]
275
- suggestTypeRewrites originatingFile ms_mod SynDecl {tcdLName = L _ rdrName } =
276
- let pprNameText = printOutputable rdrName
284
+ suggestTypeRewrites originatingFile ms_mod SynDecl {tcdLName} =
285
+ let pprNameText = printOutputable (unLocA tcdLName)
277
286
pprName = T. unpack pprNameText
278
287
unfoldRewrite restrictToOriginatingFile =
279
288
let rewrites = [TypeForward (qualify ms_mod pprName)]
@@ -290,7 +299,7 @@ suggestRuleRewrites ::
290
299
Uri ->
291
300
Position ->
292
301
GHC. Module ->
293
- LRuleDecls pass ->
302
+ LRuleDecls GhcRn ->
294
303
[(T. Text , CodeActionKind , RunRetrieParams )]
295
304
suggestRuleRewrites originatingFile pos ms_mod (L _ HsRules {rds_rules}) =
296
305
concat
@@ -299,7 +308,7 @@ suggestRuleRewrites originatingFile pos ms_mod (L _ HsRules {rds_rules}) =
299
308
, backwardsRewrite ruleName True
300
309
, backwardsRewrite ruleName False
301
310
]
302
- | L l r <- rds_rules,
311
+ | L (locA -> l) r <- rds_rules,
303
312
pos `isInsideSrcSpan` l,
304
313
#if MIN_VERSION_ghc(8,8,0)
305
314
let HsRule {rd_name = L _ (_, rn)} = r,
@@ -327,8 +336,6 @@ suggestRuleRewrites originatingFile pos ms_mod (L _ HsRules {rds_rules}) =
327
336
RunRetrieParams {.. }
328
337
)
329
338
330
- suggestRuleRewrites _ _ _ _ = []
331
-
332
339
qualify :: GHC. Module -> String -> String
333
340
qualify ms_mod x = T. unpack (printOutputable ms_mod) <> " ." <> x
334
341
@@ -360,10 +367,9 @@ callRetrie ::
360
367
callRetrie state session rewrites origin restrictToOriginatingFile = do
361
368
knownFiles <- toKnownFiles . unhashed <$> readTVarIO (knownTargetsVar $ shakeExtras state)
362
369
let reuseParsedModule f = do
363
- pm <-
364
- useOrFail " GetParsedModule" NoParse GetParsedModule f
365
- (fixities, pm) <- fixFixities f (fixAnns pm)
366
- return (fixities, pm)
370
+ pm <- useOrFail " GetParsedModule" NoParse GetParsedModule f
371
+ (fixities, pm') <- fixFixities f (fixAnns pm)
372
+ return (fixities, pm')
367
373
getCPPmodule t = do
368
374
nt <- toNormalizedFilePath' <$> makeAbsolute t
369
375
let getParsedModule f contents = do
@@ -375,8 +381,7 @@ callRetrie state session rewrites origin restrictToOriginatingFile = do
375
381
Just (stringToStringBuffer contents)
376
382
}
377
383
logPriority (ideLogger state) Info $ T. pack $ " Parsing module: " <> t
378
- parsed <-
379
- evalGhcEnv session (GHC. parseModule ms')
384
+ parsed <- evalGhcEnv session (GHC. parseModule ms')
380
385
`catch` \ e -> throwIO (GHCParseError nt (show @ SomeException e))
381
386
(fixities, parsed) <- fixFixities f (fixAnns parsed)
382
387
return (fixities, parsed)
@@ -416,12 +421,19 @@ callRetrie state session rewrites origin restrictToOriginatingFile = do
416
421
(theImports, theRewrites) = partitionEithers rewrites
417
422
418
423
annotatedImports =
419
- unsafeMkA (map (GHC. noLoc . toImportDecl) theImports) mempty 0
424
+ #if MIN_VERSION_ghc(9,2,0)
425
+ unsafeMkA (map (noLocA . toImportDecl) theImports) 0
426
+ #else
427
+ unsafeMkA (map (noLocA . toImportDecl) theImports) mempty 0
428
+ #endif
420
429
421
430
(originFixities, originParsedModule) <- reuseParsedModule origin
422
431
retrie <-
423
432
(\ specs -> apply specs >> addImports annotatedImports)
424
433
<$> parseRewriteSpecs
434
+ #if MIN_VERSION_ghc(9,2,0)
435
+ libdir -- TODO: does this actualy get the proper libdir?
436
+ #endif
425
437
(\ _f -> return $ NoCPP originParsedModule)
426
438
originFixities
427
439
theRewrites
@@ -463,9 +475,13 @@ callRetrie state session rewrites origin restrictToOriginatingFile = do
463
475
let fixities = fixityEnvFromModIface hirModIface
464
476
res <- transformA pm (fix fixities)
465
477
return (fixities, res)
466
- fixAnns ParsedModule {.. } =
478
+ #if MIN_VERSION_ghc(9,2,0)
479
+ fixAnns GHC. ParsedModule {pm_parsed_source} = unsafeMkA (makeDeltaAst pm_parsed_source) 0
480
+ #else
481
+ fixAnns GHC. ParsedModule {.. } =
467
482
let ranns = relativiseApiAnns pm_parsed_source pm_annotations
468
483
in unsafeMkA pm_parsed_source ranns 0
484
+ #endif
469
485
470
486
asEditMap :: [[(Uri , TextEdit )]] -> WorkspaceEditMap
471
487
asEditMap = coerce . HM. fromListWith (++) . concatMap (map (second pure ))
@@ -533,14 +549,18 @@ toImportDecl :: ImportSpec -> GHC.ImportDecl GHC.GhcPs
533
549
toImportDecl AddImport {.. } = GHC. ImportDecl {ideclSource = ideclSource', .. }
534
550
where
535
551
ideclSource' = if ideclSource then IsBoot else NotBoot
536
- toMod = GHC. noLoc . GHC. mkModuleName
552
+ toMod = noLocA . GHC. mkModuleName
537
553
ideclName = toMod ideclNameString
538
554
ideclPkgQual = Nothing
539
555
ideclSafe = False
540
556
ideclImplicit = False
541
557
ideclHiding = Nothing
542
558
ideclSourceSrc = NoSourceText
559
+ #if MIN_VERSION_ghc(9,2,0)
560
+ ideclExt = GHC. EpAnnNotUsed
561
+ #else
543
562
ideclExt = GHC. noExtField
563
+ #endif
544
564
ideclAs = toMod <$> ideclAsString
545
565
#if MIN_VERSION_ghc(8,10,0)
546
566
ideclQualified = if ideclQualifiedBool then GHC. QualifiedPre else GHC. NotQualified
0 commit comments