@@ -32,8 +32,8 @@ import Development.IDE.Core.Shake (define, use)
32
32
import qualified Development.IDE.Core.Shake as Shake
33
33
import Development.IDE.GHC.Compat (HasSrcSpan (.. ),
34
34
HsConDetails (RecCon ),
35
- HsRecFields (.. ),
36
- LPat , Outputable , SrcSpan ,
35
+ HsRecFields (.. ), LPat ,
36
+ Outputable , SrcSpan ,
37
37
pm_mod_summary , unLoc )
38
38
import Development.IDE.GHC.Compat.Core (Extension (NamedFieldPuns ),
39
39
GhcPass (.. ),
@@ -110,10 +110,6 @@ codeActionProvider ideState pId (CodeActionParams _ _ docId range _) = pluginRes
110
110
mkTextEdit :: RenderedRecordInfo -> Maybe TextEdit
111
111
mkTextEdit (RenderedRecordInfo ss r) = TextEdit <$> srcSpanToRange ss <*> pure r
112
112
113
- -- NOTE(ozkutuk): `RecordPuns` extension is renamed to `NamedFieldPuns`
114
- -- in GHC 9.4, but we still want to insert `NamedFieldPuns` in pre-9.4
115
- -- GHC as well, hence the replacement.
116
- -- https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6156
117
113
pragmaEdit :: Maybe TextEdit
118
114
pragmaEdit = if NamedFieldPuns `elem` exts
119
115
then Nothing
@@ -166,6 +162,8 @@ instance Show CollectRecordsResult where
166
162
167
163
type instance RuleResult CollectRecords = CollectRecordsResult
168
164
165
+ -- `Extension` is wrapped so that we can provide an `NFData` instance
166
+ -- (without resorting to creating an orphan instance).
169
167
newtype GhcExtension = GhcExtension { unExt :: Extension }
170
168
171
169
instance NFData GhcExtension where
@@ -187,10 +185,15 @@ renderRecordInfo :: RecordInfo -> Maybe RenderedRecordInfo
187
185
renderRecordInfo (RecordInfoPat ss pat) = RenderedRecordInfo ss <$> showRecordPat pat
188
186
renderRecordInfo (RecordInfoCon ss expr) = RenderedRecordInfo ss <$> showRecordCon expr
189
187
190
- -- `Outputable` instance of `HsRecFields` does smart things to print
191
- -- the records that originally had wildcards with dots, even after they
192
- -- are removed by the renamer pass. Here `rec_dotdot` is set to
193
- -- `Nothing` so that fields are printed without such post-processing.
188
+ -- We make use of the `Outputable` instances on AST types to pretty-print
189
+ -- the renamed and expanded records back into source form, to be substituted
190
+ -- with the original record later. However, `Outputable` instance of
191
+ -- `HsRecFields` does smart things to print the records that originally had
192
+ -- wildcards in their original form (i.e. with dots, without field names),
193
+ -- even after the wildcard is removed by the renamer pass. This is undesirable,
194
+ -- as we want to print the records in their fully expanded form.
195
+ -- Here `rec_dotdot` is set to `Nothing` so that fields are printed without
196
+ -- such post-processing.
194
197
preprocessRecord :: HsRecFields (GhcPass c ) arg -> HsRecFields (GhcPass c ) arg
195
198
preprocessRecord flds = flds { rec_dotdot = Nothing , rec_flds = rec_flds' }
196
199
where
0 commit comments