Skip to content

Commit 0a2174d

Browse files
dylan-thinnesJaro Reinders
authored andcommitted
Only override the LSP diagnostic code when not already set
1 parent 1a7856b commit 0a2174d

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module Development.IDE.Types.Diagnostics (
2626
attachReason,
2727
attachedReason) where
2828

29+
import Control.Applicative ((<|>))
2930
import Control.DeepSeq
3031
import Control.Lens
3132
import qualified Data.Aeson as JSON
@@ -78,20 +79,32 @@ ideErrorFromLspDiag
7879
-> NormalizedFilePath
7980
-> Maybe (MsgEnvelope GhcMessage)
8081
-> FileDiagnostic
81-
ideErrorFromLspDiag lspDiag fdFilePath origMsg =
82+
ideErrorFromLspDiag lspDiag fdFilePath mbOrigMsg =
8283
let fdShouldShowDiagnostic = ShowDiag
8384
fdStructuredMessage =
84-
case origMsg of
85+
case mbOrigMsg of
8586
Nothing -> NoStructuredMessage
8687
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
9292
in
9393
FileDiagnostic {..}
9494

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+
95108
#if MIN_VERSION_ghc(9,10,1)
96109
-- DiagnosticCode only got a show instance in 9.10.1
97110
showGhcCode :: DiagnosticCode -> T.Text

0 commit comments

Comments
 (0)