Skip to content

Commit

Permalink
Remove StructuredDiagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
noughtmare committed Oct 28, 2024
1 parent 6c05e23 commit 0776c65
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 42 deletions.
41 changes: 0 additions & 41 deletions ghcide/src/Development/IDE/Types/Diagnostics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module Development.IDE.Types.Diagnostics (
ShowDiagnostic(..),
FileDiagnostic(..),
fdLspDiagnosticL,
StructuredMessage(..),
IdeResult,
LSP.DiagnosticSeverity(..),
DiagnosticStore,
Expand Down Expand Up @@ -87,10 +86,6 @@ ideErrorFromLspDiag
-> FileDiagnostic
ideErrorFromLspDiag lspDiag fdFilePath mbOrigMsg =
let fdShouldShowDiagnostic = ShowDiag
fdStructuredMessage =
case mbOrigMsg of
Nothing -> NoStructuredMessage
Just msg -> SomeStructuredMessage msg
fdLspDiagnostic =
lspDiag
& attachReason (fmap (diagnosticReason . errMsgDiagnostic) mbOrigMsg)
Expand Down Expand Up @@ -172,52 +167,16 @@ data ShowDiagnostic
instance NFData ShowDiagnostic where
rnf = rwhnf

-- | A Maybe-like wrapper for a GhcMessage that doesn't try to compare, show, or
-- force the GhcMessage inside, so that we can derive Show, Eq, Ord, NFData on
-- FileDiagnostic. FileDiagnostic only uses this as metadata so we can safely
-- ignore it in fields.
data StructuredMessage
= NoStructuredMessage
| SomeStructuredMessage (MsgEnvelope GhcMessage)
deriving (Generic)

instance Show StructuredMessage where
show NoStructuredMessage = "NoStructuredMessage"
show SomeStructuredMessage {} = "SomeStructuredMessage"

instance Eq StructuredMessage where
(==) NoStructuredMessage NoStructuredMessage = True
(==) SomeStructuredMessage {} SomeStructuredMessage {} = True
(==) _ _ = False

instance Ord StructuredMessage where
compare NoStructuredMessage NoStructuredMessage = EQ
compare SomeStructuredMessage {} SomeStructuredMessage {} = EQ
compare NoStructuredMessage SomeStructuredMessage {} = GT
compare SomeStructuredMessage {} NoStructuredMessage = LT

instance NFData StructuredMessage where
rnf NoStructuredMessage = ()
rnf SomeStructuredMessage {} = ()

-- | Human readable diagnostics for a specific file.
--
-- This type packages a pretty printed, human readable error message
-- along with the related source location so that we can display the error
-- on either the console or in the IDE at the right source location.
--
-- It also optionally keeps a structured diagnostic message GhcMessage in
-- StructuredMessage.
--
data FileDiagnostic = FileDiagnostic
{ fdFilePath :: NormalizedFilePath
, fdShouldShowDiagnostic :: ShowDiagnostic
, fdLspDiagnostic :: Diagnostic
-- | The optional GhcMessage inside of this StructuredMessage is ignored for
-- Eq, Ord, Show, and NFData instances. This is fine because this field
-- should only ever be metadata and should never be used to distinguish
-- between FileDiagnostics.
, fdStructuredMessage :: StructuredMessage
}
deriving (Eq, Ord, Show, Generic)

Expand Down
2 changes: 1 addition & 1 deletion ghcide/test/exe/UnitTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ tests = do
, _message = ""
, _relatedInformation = Nothing
, _tags = Nothing
} Diagnostics.NoStructuredMessage
}
let shown = T.unpack (Diagnostics.showDiagnostics [diag])
let expected = "1:2-3:4"
assertBool (unwords ["expected to find range", expected, "in diagnostic", shown]) $
Expand Down

0 comments on commit 0776c65

Please sign in to comment.