Skip to content

Commit 20b9c23

Browse files
Set the diagnostic code description on GHC diagnostics (#4629)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 11bb99a commit 20b9c23

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,19 @@ ideErrorFromLspDiag lspDiag fdFilePath mbOrigMsg =
102102
fdLspDiagnostic =
103103
lspDiag
104104
& attachReason (fmap (diagnosticReason . errMsgDiagnostic) mbOrigMsg)
105-
& setGhcCode mbOrigMsg
105+
& attachDiagnosticCode ((diagnosticCode . errMsgDiagnostic) =<< mbOrigMsg)
106106
in
107107
FileDiagnostic {..}
108108

109-
-- | Set the code of the 'LSP.Diagnostic' to the GHC diagnostic code which is linked
109+
-- | Set the code of the 'LSP.Diagnostic' to the GHC diagnostic code, and include the link
110110
-- to https://errors.haskell.org/.
111-
setGhcCode :: Maybe (MsgEnvelope GhcMessage) -> LSP.Diagnostic -> LSP.Diagnostic
112-
setGhcCode mbOrigMsg diag =
113-
let mbGhcCode = do
114-
origMsg <- mbOrigMsg
115-
code <- diagnosticCode (errMsgDiagnostic origMsg)
116-
pure (InR (showGhcCode code))
117-
in
118-
diag { _code = mbGhcCode <|> _code diag }
111+
attachDiagnosticCode :: Maybe DiagnosticCode -> LSP.Diagnostic -> LSP.Diagnostic
112+
attachDiagnosticCode Nothing diag = diag
113+
attachDiagnosticCode (Just code) diag =
114+
let
115+
textualCode = showGhcCode code
116+
codeDesc = LSP.CodeDescription{ _href = Uri $ "https://errors.haskell.org/messages/" <> textualCode }
117+
in diag { _code = Just (InR textualCode), _codeDescription = Just codeDesc}
119118

120119
#if MIN_VERSION_ghc(9,9,0)
121120
-- DiagnosticCode only got a show instance in 9.10.1

0 commit comments

Comments
 (0)