Skip to content

Commit 4c9e7a3

Browse files
committed
Add documentation to diagnostic helpers
1 parent 649e2ba commit 4c9e7a3

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

ghcide/src/Development/IDE/Types/Diagnostics.hs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ module Development.IDE.Types.Diagnostics (
99
LSP.Diagnostic(..),
1010
ShowDiagnostic(..),
1111
FileDiagnostic(..),
12+
fdFilePathL,
1213
fdLspDiagnosticL,
14+
fdShouldShowDiagnosticL,
15+
fdStructuredMessageL,
1316
StructuredMessage(..),
1417
IdeResult,
1518
LSP.DiagnosticSeverity(..),
@@ -82,7 +85,15 @@ ideErrorText :: NormalizedFilePath -> T.Text -> FileDiagnostic
8285
ideErrorText nfp msg =
8386
ideErrorWithSource (Just "compiler") (Just DiagnosticSeverity_Error) nfp msg Nothing
8487

85-
88+
-- | Create a 'FileDiagnostic' from an existing 'LSP.Diagnostic' for a
89+
-- specific 'NormalizedFilePath'.
90+
-- The optional 'MsgEnvelope GhcMessage' is the original error message
91+
-- that was used for creating the 'LSP.Diagnostic'.
92+
-- It is included here, to allow downstream consumers, such as HLS plugins,
93+
-- to provide LSP features based on the structured error messages.
94+
-- Additionally, if available, we insert the ghc error code into the
95+
-- 'LSP.Diagnostic'. These error codes are used in https://errors.haskell.org/
96+
-- to provide documentation and explanations for error messages.
8697
ideErrorFromLspDiag
8798
:: LSP.Diagnostic
8899
-> NormalizedFilePath
@@ -101,6 +112,8 @@ ideErrorFromLspDiag lspDiag fdFilePath mbOrigMsg =
101112
in
102113
FileDiagnostic {..}
103114

115+
-- | Set the code of the 'LSP.Diagnostic' to the GHC diagnostic code which is linked
116+
-- to https://errors.haskell.org/.
104117
setGhcCode :: Maybe (MsgEnvelope GhcMessage) -> LSP.Diagnostic -> LSP.Diagnostic
105118
#if MIN_VERSION_ghc(9,5,0)
106119
setGhcCode mbOrigMsg diag =
@@ -216,7 +229,12 @@ data FileDiagnostic = FileDiagnostic
216229
{ fdFilePath :: NormalizedFilePath
217230
, fdShouldShowDiagnostic :: ShowDiagnostic
218231
, fdLspDiagnostic :: Diagnostic
219-
-- | The optional GhcMessage inside of this StructuredMessage is ignored for
232+
-- | The original diagnostic that was used to produce 'fdLspDiagnostic'.
233+
-- We keep it here, so downstream consumers, e.g. HLS plugins, can use the
234+
-- the structured error messages and don't have to resort to parsing
235+
-- error messages via regexes or similar.
236+
--
237+
-- The optional GhcMessage inside of this StructuredMessage is ignored for
220238
-- Eq, Ord, Show, and NFData instances. This is fine because this field
221239
-- should only ever be metadata and should never be used to distinguish
222240
-- between FileDiagnostics.

0 commit comments

Comments
 (0)