@@ -38,12 +38,13 @@ import Development.IDE.GHC.Compat (HasSrcSpan (..),
38
38
HsRecFields (.. ), HscEnv (.. ),
39
39
LPat , Outputable , SrcSpan ,
40
40
pm_mod_summary , unLoc )
41
- import Development.IDE.GHC.Compat.Core (GenLocated (.. ), GhcPass (.. ),
41
+ import Development.IDE.GHC.Compat.Core (Extension (NamedFieldPuns ),
42
+ GhcPass (.. ),
42
43
HsExpr (RecordCon , rcon_flds ),
43
- HsRecField' (.. ), LHsExpr ,
44
- ModSummary (.. ), Pass (.. ),
45
- Pat ( .. ), extensionFlags ,
46
- hs_valds )
44
+ LHsExpr , ModSummary (.. ),
45
+ Pass (.. ), Pat (.. ),
46
+ extensionFlags , hfbPun ,
47
+ hs_valds , mapLoc )
47
48
import Development.IDE.GHC.Compat.Util (toList )
48
49
import Development.IDE.GHC.Util (printOutputable )
49
50
import Development.IDE.Graph (RuleResult )
@@ -53,7 +54,6 @@ import Development.IDE.Spans.Pragmas (NextPragmaInfo (..),
53
54
insertNewPragma )
54
55
import Development.IDE.Types.Logger (cmapWithPrio )
55
56
import GHC.Generics (Generic )
56
- import GHC.LanguageExtensions.Type (Extension (.. ))
57
57
import Ide.PluginUtils (getNormalizedFilePath ,
58
58
handleMaybeM , pluginResponse ,
59
59
subRange )
@@ -79,31 +79,26 @@ import qualified Language.LSP.Types.Lens as L
79
79
-- the records that originally had wildcards with dots, even after they
80
80
-- are removed by the renamer pass. Here `rec_dotdot` is set to
81
81
-- `Nothing` so that fields are printed without such post-processing.
82
- preprocessRecord :: HsRecFields p arg -> HsRecFields p arg
82
+ preprocessRecord :: HsRecFields ( GhcPass c ) arg -> HsRecFields ( GhcPass c ) arg
83
83
preprocessRecord flds = flds { rec_dotdot = Nothing , rec_flds = rec_flds' }
84
84
where
85
- -- TODO(ozkutuk): HsRecField' is renamed to HsFieldBind in GHC 9.4
86
- -- Add it as a pattern synonym to the ghcide compat module, so it would
87
- -- work on all HLS builds.
88
- -- https://gitlab.haskell.org/ghc/ghc/-/merge_requests/5757
89
-
90
85
no_pun_count = maybe (length (rec_flds flds)) unLoc (rec_dotdot flds)
91
86
-- Field binds of the explicit form (e.g. `{ a = a' }`) should be
92
87
-- left as is, hence the split.
93
88
(no_puns, puns) = splitAt no_pun_count (rec_flds flds)
94
89
-- `hsRecPun` is set to `True` in order to pretty-print the fields as field
95
90
-- puns (since there is similar mechanism in the `Outputable` instance as
96
91
-- explained above).
97
- puns' = map (\ ( L ss fld) -> L ss ( fld { hsRecPun = True })) puns
92
+ puns' = map (mapLoc ( \ fld -> fld { hfbPun = True })) puns
98
93
rec_flds' = no_puns <> puns'
99
94
100
- showRecordPat :: Outputable (Pat p ) => Pat p -> Maybe Text
95
+ showRecordPat :: Outputable (Pat ( GhcPass c )) => Pat ( GhcPass c ) -> Maybe Text
101
96
showRecordPat pat@ (ConPat _ _ (RecCon flds)) =
102
97
Just $ printOutputable $
103
98
pat { pat_args = RecCon (preprocessRecord flds) }
104
99
showRecordPat _ = Nothing
105
100
106
- showRecordCon :: Outputable (HsExpr p ) => HsExpr p -> Maybe Text
101
+ showRecordCon :: Outputable (HsExpr ( GhcPass c )) => HsExpr ( GhcPass c ) -> Maybe Text
107
102
showRecordCon expr@ (RecordCon _ _ flds) =
108
103
Just $ printOutputable $
109
104
expr { rcon_flds = preprocessRecord flds }
@@ -239,14 +234,14 @@ codeActionProvider ideState pId (CodeActionParams _ _ docId range _) = pluginRes
239
234
mkTextEdit :: RenderedRecordInfo -> Maybe TextEdit
240
235
mkTextEdit (RenderedRecordInfo ss r) = TextEdit <$> srcSpanToRange ss <*> pure r
241
236
242
- -- TODO (ozkutuk): `RecordPuns` extension is renamed to `NamedFieldPuns`
243
- -- in GHC 9.4, so I probably need to add this to the compat module as
244
- -- well.
237
+ -- NOTE (ozkutuk): `RecordPuns` extension is renamed to `NamedFieldPuns`
238
+ -- in GHC 9.4, but we still want to insert `NamedFieldPuns` in pre-9.4
239
+ -- GHC as well, hence the replacement .
245
240
-- https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6156
246
241
pragmaEdit :: Maybe TextEdit
247
- pragmaEdit = if RecordPuns `elem` exts
242
+ pragmaEdit = if NamedFieldPuns `elem` exts
248
243
then Nothing
249
- else Just $ patchExtName $ insertNewPragma pragma RecordPuns
244
+ else Just $ patchExtName $ insertNewPragma pragma NamedFieldPuns
250
245
where
251
246
patchExtName = L. newText %~ T. replace " Record" " NamedField"
252
247
@@ -257,7 +252,7 @@ codeActionProvider ideState pId (CodeActionParams _ _ docId range _) = pluginRes
257
252
258
253
mkCodeActionTitle :: [Extension ] -> Text
259
254
mkCodeActionTitle exts =
260
- if RecordPuns `elem` exts
255
+ if NamedFieldPuns `elem` exts
261
256
then title
262
257
else title <> " (needs extension: NamedFieldPuns)"
263
258
where
0 commit comments