2
2
-- SPDX-License-Identifier: Apache-2.0
3
3
4
4
{-# LANGUAGE DeriveGeneric #-}
5
+ {-# LANGUAGE TemplateHaskell #-}
5
6
{-# LANGUAGE CPP #-}
6
7
7
8
module Development.IDE.Types.Diagnostics (
8
9
LSP. Diagnostic (.. ),
9
10
ShowDiagnostic (.. ),
10
11
FileDiagnostic (.. ),
11
- fdFilePath ,
12
- fdShouldShowDiagnostic ,
13
- fdLspDiagnostic ,
14
- fdStructuredMessage ,
15
- modifyFdLspDiagnostic ,
12
+ fdLspDiagnosticL ,
16
13
StructuredMessage (.. ),
17
14
IdeResult ,
18
15
LSP. DiagnosticSeverity (.. ),
@@ -25,6 +22,7 @@ module Development.IDE.Types.Diagnostics (
25
22
IdeResultNoDiagnosticsEarlyCutoff ) where
26
23
27
24
import Control.DeepSeq
25
+ import Control.Lens
28
26
import Data.ByteString (ByteString )
29
27
import Data.Maybe as Maybe
30
28
import qualified Data.Text as T
@@ -68,14 +66,20 @@ ideErrorFromLspDiag
68
66
ideErrorFromLspDiag lspDiag fdFilePath origMsg =
69
67
let fdShouldShowDiagnostic = ShowDiag
70
68
fdStructuredMessage =
71
- maybe NoStructuredMessage SomeStructuredMessage origMsg
69
+ case origMsg of
70
+ Nothing -> NoStructuredMessage
71
+ Just msg -> SomeStructuredMessage msg
72
72
fdLspDiagnostic = lspDiag
73
+ #if MIN_VERSION_ghc(9,6,1)
73
74
{ _code = fmap ghcCodeToLspCode . diagnosticCode . errMsgDiagnostic =<< origMsg
74
75
}
76
+ #endif
77
+ #if MIN_VERSION_ghc(9,8,1)
75
78
ghcCodeToLspCode :: DiagnosticCode -> Int32 LSP. |? T. Text
76
- #if MIN_VERSION_ghc(9,10,1)
77
79
ghcCodeToLspCode = InR . T. pack . show
78
- #else
80
+ #elif MIN_VERSION_ghc(9,6,1)
81
+ -- DiagnosticCode only got a show instance in 9.8.1
82
+ ghcCodeToLspCode :: DiagnosticCode -> Int32 LSP. |? T. Text
79
83
ghcCodeToLspCode (DiagnosticCode prefix c) = InR $ T. pack $ prefix ++ " -" ++ printf " %05d" c
80
84
#endif
81
85
in
@@ -119,22 +123,9 @@ data ShowDiagnostic
119
123
instance NFData ShowDiagnostic where
120
124
rnf = rwhnf
121
125
122
- -- | Human readable diagnostics for a specific file.
123
- --
124
- -- This type packages a pretty printed, human readable error message
125
- -- along with the related source location so that we can display the error
126
- -- on either the console or in the IDE at the right source location.
127
- --
128
- data FileDiagnostic = FileDiagnostic
129
- { fdFilePath :: NormalizedFilePath
130
- , fdShouldShowDiagnostic :: ShowDiagnostic
131
- , fdLspDiagnostic :: Diagnostic
132
- , fdStructuredMessage :: StructuredMessage
133
- }
134
- deriving (Eq , Ord , Show , Generic )
135
-
136
- instance NFData FileDiagnostic
137
-
126
+ -- | A Maybe-like wrapper for a GhcMessage that doesn't try to compare, show, or
127
+ -- force the GhcMessage inside, so that we can derive Show, Eq, Ord, NFData on
128
+ -- FileDiagnostic
138
129
data StructuredMessage
139
130
= NoStructuredMessage
140
131
| SomeStructuredMessage (MsgEnvelope GhcMessage )
@@ -159,9 +150,25 @@ instance NFData StructuredMessage where
159
150
rnf NoStructuredMessage = ()
160
151
rnf SomeStructuredMessage {} = ()
161
152
162
- modifyFdLspDiagnostic :: (Diagnostic -> Diagnostic ) -> FileDiagnostic -> FileDiagnostic
163
- modifyFdLspDiagnostic f diag =
164
- diag { fdLspDiagnostic = f (fdLspDiagnostic diag) }
153
+ -- | Human readable diagnostics for a specific file.
154
+ --
155
+ -- This type packages a pretty printed, human readable error message
156
+ -- along with the related source location so that we can display the error
157
+ -- on either the console or in the IDE at the right source location.
158
+ --
159
+ data FileDiagnostic = FileDiagnostic
160
+ { fdFilePath :: NormalizedFilePath
161
+ , fdShouldShowDiagnostic :: ShowDiagnostic
162
+ , fdLspDiagnostic :: Diagnostic
163
+ , fdStructuredMessage :: StructuredMessage
164
+ }
165
+ deriving (Eq , Ord , Show , Generic )
166
+
167
+ instance NFData FileDiagnostic
168
+
169
+ makeLensesWith
170
+ (lensRules & lensField .~ mappingNamer (pure . (++ " L" )))
171
+ ''FileDiagnostic
165
172
166
173
prettyRange :: Range -> Doc Terminal. AnsiStyle
167
174
prettyRange Range {.. } = f _start <> " -" <> f _end
0 commit comments