Skip to content

Commit d213705

Browse files
committed
Improve documentation
1 parent b93422a commit d213705

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

ghcide/src/Development/IDE/Spans/Pragmas.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ getNextPragmaInfo dynFlags sourceText =
3636
| otherwise
3737
-> NextPragmaInfo 0 Nothing
3838

39+
-- NOTE(ozkutuk): `RecordPuns` extension is renamed to `NamedFieldPuns`
40+
-- in GHC 9.4, but we still want to insert `NamedFieldPuns` in pre-9.4
41+
-- GHC as well, hence the replacement.
42+
-- https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6156
3943
showExtension :: Extension -> Text
4044
showExtension RecordPuns = "NamedFieldPuns"
4145
showExtension ext = pack (show ext)

plugins/hls-explicit-record-fields-plugin/src/Ide/Plugin/ExplicitFields.hs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import Development.IDE.Core.Shake (define, use)
3232
import qualified Development.IDE.Core.Shake as Shake
3333
import Development.IDE.GHC.Compat (HasSrcSpan (..),
3434
HsConDetails (RecCon),
35-
HsRecFields (..),
36-
LPat, Outputable, SrcSpan,
35+
HsRecFields (..), LPat,
36+
Outputable, SrcSpan,
3737
pm_mod_summary, unLoc)
3838
import Development.IDE.GHC.Compat.Core (Extension (NamedFieldPuns),
3939
GhcPass (..),
@@ -110,10 +110,6 @@ codeActionProvider ideState pId (CodeActionParams _ _ docId range _) = pluginRes
110110
mkTextEdit :: RenderedRecordInfo -> Maybe TextEdit
111111
mkTextEdit (RenderedRecordInfo ss r) = TextEdit <$> srcSpanToRange ss <*> pure r
112112

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
117113
pragmaEdit :: Maybe TextEdit
118114
pragmaEdit = if NamedFieldPuns `elem` exts
119115
then Nothing
@@ -166,6 +162,8 @@ instance Show CollectRecordsResult where
166162

167163
type instance RuleResult CollectRecords = CollectRecordsResult
168164

165+
-- `Extension` is wrapped so that we can provide an `NFData` instance
166+
-- (without resorting to creating an orphan instance).
169167
newtype GhcExtension = GhcExtension { unExt :: Extension }
170168

171169
instance NFData GhcExtension where
@@ -187,10 +185,15 @@ renderRecordInfo :: RecordInfo -> Maybe RenderedRecordInfo
187185
renderRecordInfo (RecordInfoPat ss pat) = RenderedRecordInfo ss <$> showRecordPat pat
188186
renderRecordInfo (RecordInfoCon ss expr) = RenderedRecordInfo ss <$> showRecordCon expr
189187

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.
194197
preprocessRecord :: HsRecFields (GhcPass c) arg -> HsRecFields (GhcPass c) arg
195198
preprocessRecord flds = flds { rec_dotdot = Nothing , rec_flds = rec_flds' }
196199
where

0 commit comments

Comments
 (0)