22-- SPDX-License-Identifier: Apache-2.0
33
44{-# LANGUAGE DeriveGeneric #-}
5+ {-# LANGUAGE TemplateHaskell #-}
56{-# LANGUAGE CPP #-}
67
78module Development.IDE.Types.Diagnostics (
89 LSP. Diagnostic (.. ),
910 ShowDiagnostic (.. ),
1011 FileDiagnostic (.. ),
11- fdFilePath ,
12- fdShouldShowDiagnostic ,
13- fdLspDiagnostic ,
14- fdStructuredMessage ,
15- modifyFdLspDiagnostic ,
12+ fdLspDiagnosticL ,
1613 StructuredMessage (.. ),
1714 IdeResult ,
1815 LSP. DiagnosticSeverity (.. ),
@@ -25,6 +22,7 @@ module Development.IDE.Types.Diagnostics (
2522 IdeResultNoDiagnosticsEarlyCutoff ) where
2623
2724import Control.DeepSeq
25+ import Control.Lens
2826import Data.ByteString (ByteString )
2927import Data.Maybe as Maybe
3028import qualified Data.Text as T
@@ -125,22 +123,9 @@ data ShowDiagnostic
125123instance NFData ShowDiagnostic where
126124 rnf = rwhnf
127125
128- -- | Human readable diagnostics for a specific file.
129- --
130- -- This type packages a pretty printed, human readable error message
131- -- along with the related source location so that we can display the error
132- -- on either the console or in the IDE at the right source location.
133- --
134- data FileDiagnostic = FileDiagnostic
135- { fdFilePath :: NormalizedFilePath
136- , fdShouldShowDiagnostic :: ShowDiagnostic
137- , fdLspDiagnostic :: Diagnostic
138- , fdStructuredMessage :: StructuredMessage
139- }
140- deriving (Eq , Ord , Show , Generic )
141-
142- instance NFData FileDiagnostic
143-
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
144129data StructuredMessage
145130 = NoStructuredMessage
146131 | SomeStructuredMessage (MsgEnvelope GhcMessage )
@@ -165,9 +150,25 @@ instance NFData StructuredMessage where
165150 rnf NoStructuredMessage = ()
166151 rnf SomeStructuredMessage {} = ()
167152
168- modifyFdLspDiagnostic :: (Diagnostic -> Diagnostic ) -> FileDiagnostic -> FileDiagnostic
169- modifyFdLspDiagnostic f diag =
170- 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
171172
172173prettyRange :: Range -> Doc Terminal. AnsiStyle
173174prettyRange Range {.. } = f _start <> " -" <> f _end
0 commit comments