@@ -10,6 +10,7 @@ module Development.IDE.Types.Diagnostics (
10
10
ShowDiagnostic (.. ),
11
11
FileDiagnostic (.. ),
12
12
fdLspDiagnosticL ,
13
+ StructuredMessage (.. ),
13
14
IdeResult ,
14
15
LSP. DiagnosticSeverity (.. ),
15
16
DiagnosticStore ,
@@ -86,6 +87,10 @@ ideErrorFromLspDiag
86
87
-> FileDiagnostic
87
88
ideErrorFromLspDiag lspDiag fdFilePath mbOrigMsg =
88
89
let fdShouldShowDiagnostic = ShowDiag
90
+ fdStructuredMessage =
91
+ case mbOrigMsg of
92
+ Nothing -> NoStructuredMessage
93
+ Just msg -> SomeStructuredMessage msg
89
94
fdLspDiagnostic =
90
95
lspDiag
91
96
& attachReason (fmap (diagnosticReason . errMsgDiagnostic) mbOrigMsg)
@@ -167,16 +172,52 @@ data ShowDiagnostic
167
172
instance NFData ShowDiagnostic where
168
173
rnf = rwhnf
169
174
175
+ -- | A Maybe-like wrapper for a GhcMessage that doesn't try to compare, show, or
176
+ -- force the GhcMessage inside, so that we can derive Show, Eq, Ord, NFData on
177
+ -- FileDiagnostic. FileDiagnostic only uses this as metadata so we can safely
178
+ -- ignore it in fields.
179
+ data StructuredMessage
180
+ = NoStructuredMessage
181
+ | SomeStructuredMessage (MsgEnvelope GhcMessage )
182
+ deriving (Generic )
183
+
184
+ instance Show StructuredMessage where
185
+ show NoStructuredMessage = " NoStructuredMessage"
186
+ show SomeStructuredMessage {} = " SomeStructuredMessage"
187
+
188
+ instance Eq StructuredMessage where
189
+ (==) NoStructuredMessage NoStructuredMessage = True
190
+ (==) SomeStructuredMessage {} SomeStructuredMessage {} = True
191
+ (==) _ _ = False
192
+
193
+ instance Ord StructuredMessage where
194
+ compare NoStructuredMessage NoStructuredMessage = EQ
195
+ compare SomeStructuredMessage {} SomeStructuredMessage {} = EQ
196
+ compare NoStructuredMessage SomeStructuredMessage {} = GT
197
+ compare SomeStructuredMessage {} NoStructuredMessage = LT
198
+
199
+ instance NFData StructuredMessage where
200
+ rnf NoStructuredMessage = ()
201
+ rnf SomeStructuredMessage {} = ()
202
+
170
203
-- | Human readable diagnostics for a specific file.
171
204
--
172
205
-- This type packages a pretty printed, human readable error message
173
206
-- along with the related source location so that we can display the error
174
207
-- on either the console or in the IDE at the right source location.
175
208
--
209
+ -- It also optionally keeps a structured diagnostic message GhcMessage in
210
+ -- StructuredMessage.
211
+ --
176
212
data FileDiagnostic = FileDiagnostic
177
213
{ fdFilePath :: NormalizedFilePath
178
214
, fdShouldShowDiagnostic :: ShowDiagnostic
179
215
, fdLspDiagnostic :: Diagnostic
216
+ -- | The optional GhcMessage inside of this StructuredMessage is ignored for
217
+ -- Eq, Ord, Show, and NFData instances. This is fine because this field
218
+ -- should only ever be metadata and should never be used to distinguish
219
+ -- between FileDiagnostics.
220
+ , fdStructuredMessage :: StructuredMessage
180
221
}
181
222
deriving (Eq , Ord , Show , Generic )
182
223
0 commit comments