Skip to content

Commit 65300ef

Browse files
committed
Revert "Remove StructuredDiagnostic"
This reverts commit 0776c65.
1 parent 0776c65 commit 65300ef

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Development.IDE.Types.Diagnostics (
1010
ShowDiagnostic(..),
1111
FileDiagnostic(..),
1212
fdLspDiagnosticL,
13+
StructuredMessage(..),
1314
IdeResult,
1415
LSP.DiagnosticSeverity(..),
1516
DiagnosticStore,
@@ -86,6 +87,10 @@ ideErrorFromLspDiag
8687
-> FileDiagnostic
8788
ideErrorFromLspDiag lspDiag fdFilePath mbOrigMsg =
8889
let fdShouldShowDiagnostic = ShowDiag
90+
fdStructuredMessage =
91+
case mbOrigMsg of
92+
Nothing -> NoStructuredMessage
93+
Just msg -> SomeStructuredMessage msg
8994
fdLspDiagnostic =
9095
lspDiag
9196
& attachReason (fmap (diagnosticReason . errMsgDiagnostic) mbOrigMsg)
@@ -167,16 +172,52 @@ data ShowDiagnostic
167172
instance NFData ShowDiagnostic where
168173
rnf = rwhnf
169174

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+
170203
-- | Human readable diagnostics for a specific file.
171204
--
172205
-- This type packages a pretty printed, human readable error message
173206
-- along with the related source location so that we can display the error
174207
-- on either the console or in the IDE at the right source location.
175208
--
209+
-- It also optionally keeps a structured diagnostic message GhcMessage in
210+
-- StructuredMessage.
211+
--
176212
data FileDiagnostic = FileDiagnostic
177213
{ fdFilePath :: NormalizedFilePath
178214
, fdShouldShowDiagnostic :: ShowDiagnostic
179215
, 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
180221
}
181222
deriving (Eq, Ord, Show, Generic)
182223

ghcide/test/exe/UnitTests.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ tests = do
6464
, _message = ""
6565
, _relatedInformation = Nothing
6666
, _tags = Nothing
67-
}
67+
} Diagnostics.NoStructuredMessage
6868
let shown = T.unpack (Diagnostics.showDiagnostics [diag])
6969
let expected = "1:2-3:4"
7070
assertBool (unwords ["expected to find range", expected, "in diagnostic", shown]) $

0 commit comments

Comments
 (0)