@@ -26,6 +26,7 @@ module Development.IDE.Types.Diagnostics (
26
26
attachReason ,
27
27
attachedReason ) where
28
28
29
+ import Control.Applicative ((<|>) )
29
30
import Control.DeepSeq
30
31
import Control.Lens
31
32
import qualified Data.Aeson as JSON
@@ -78,20 +79,32 @@ ideErrorFromLspDiag
78
79
-> NormalizedFilePath
79
80
-> Maybe (MsgEnvelope GhcMessage )
80
81
-> FileDiagnostic
81
- ideErrorFromLspDiag lspDiag fdFilePath origMsg =
82
+ ideErrorFromLspDiag lspDiag fdFilePath mbOrigMsg =
82
83
let fdShouldShowDiagnostic = ShowDiag
83
84
fdStructuredMessage =
84
- case origMsg of
85
+ case mbOrigMsg of
85
86
Nothing -> NoStructuredMessage
86
87
Just msg -> SomeStructuredMessage msg
87
- fdLspDiagnostic = (attachReason (fmap (diagnosticReason . errMsgDiagnostic) origMsg) lspDiag)
88
- #if MIN_VERSION_ghc(9,6,1)
89
- { _code = fmap (InR . showGhcCode) . diagnosticCode . errMsgDiagnostic =<< origMsg
90
- }
91
- #endif
88
+ fdLspDiagnostic =
89
+ lspDiag
90
+ & attachReason (fmap (diagnosticReason . errMsgDiagnostic) mbOrigMsg)
91
+ & setGhcCode mbOrigMsg
92
92
in
93
93
FileDiagnostic {.. }
94
94
95
+ setGhcCode :: Maybe (MsgEnvelope GhcMessage ) -> LSP. Diagnostic -> LSP. Diagnostic
96
+ #if MIN_VERSION_ghc(9,6,1)
97
+ setGhcCode mbOrigMsg diag =
98
+ let mbGhcCode = do
99
+ origMsg <- mbOrigMsg
100
+ code <- diagnosticCode (errMsgDiagnostic origMsg)
101
+ pure (InR (showGhcCode code))
102
+ in
103
+ diag { _code = mbGhcCode <|> _code diag }
104
+ #else
105
+ setGhcCode _ diag = diag
106
+ #endif
107
+
95
108
#if MIN_VERSION_ghc(9,10,1)
96
109
-- DiagnosticCode only got a show instance in 9.10.1
97
110
showGhcCode :: DiagnosticCode -> T. Text
0 commit comments