@@ -9,7 +9,10 @@ module Development.IDE.Types.Diagnostics (
9
9
LSP. Diagnostic (.. ),
10
10
ShowDiagnostic (.. ),
11
11
FileDiagnostic (.. ),
12
+ fdFilePathL ,
12
13
fdLspDiagnosticL ,
14
+ fdShouldShowDiagnosticL ,
15
+ fdStructuredMessageL ,
13
16
StructuredMessage (.. ),
14
17
IdeResult ,
15
18
LSP. DiagnosticSeverity (.. ),
@@ -82,7 +85,15 @@ ideErrorText :: NormalizedFilePath -> T.Text -> FileDiagnostic
82
85
ideErrorText nfp msg =
83
86
ideErrorWithSource (Just " compiler" ) (Just DiagnosticSeverity_Error ) nfp msg Nothing
84
87
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.
86
97
ideErrorFromLspDiag
87
98
:: LSP. Diagnostic
88
99
-> NormalizedFilePath
@@ -101,6 +112,8 @@ ideErrorFromLspDiag lspDiag fdFilePath mbOrigMsg =
101
112
in
102
113
FileDiagnostic {.. }
103
114
115
+ -- | Set the code of the 'LSP.Diagnostic' to the GHC diagnostic code which is linked
116
+ -- to https://errors.haskell.org/.
104
117
setGhcCode :: Maybe (MsgEnvelope GhcMessage ) -> LSP. Diagnostic -> LSP. Diagnostic
105
118
#if MIN_VERSION_ghc(9,5,0)
106
119
setGhcCode mbOrigMsg diag =
@@ -216,7 +229,12 @@ data FileDiagnostic = FileDiagnostic
216
229
{ fdFilePath :: NormalizedFilePath
217
230
, fdShouldShowDiagnostic :: ShowDiagnostic
218
231
, 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
220
238
-- Eq, Ord, Show, and NFData instances. This is fine because this field
221
239
-- should only ever be metadata and should never be used to distinguish
222
240
-- between FileDiagnostics.
0 commit comments