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
@@ -119,22 +117,9 @@ data ShowDiagnostic
119117instance NFData ShowDiagnostic where
120118 rnf = rwhnf
121119
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-
120+ -- | A Maybe-like wrapper for a GhcMessage that doesn't try to compare, show, or
121+ -- force the GhcMessage inside, so that we can derive Show, Eq, Ord, NFData on
122+ -- FileDiagnostic
138123data StructuredMessage
139124 = NoStructuredMessage
140125 | SomeStructuredMessage (MsgEnvelope GhcMessage )
@@ -159,9 +144,25 @@ instance NFData StructuredMessage where
159144 rnf NoStructuredMessage = ()
160145 rnf SomeStructuredMessage {} = ()
161146
162- modifyFdLspDiagnostic :: (Diagnostic -> Diagnostic ) -> FileDiagnostic -> FileDiagnostic
163- modifyFdLspDiagnostic f diag =
164- diag { fdLspDiagnostic = f (fdLspDiagnostic diag) }
147+ -- | Human readable diagnostics for a specific file.
148+ --
149+ -- This type packages a pretty printed, human readable error message
150+ -- along with the related source location so that we can display the error
151+ -- on either the console or in the IDE at the right source location.
152+ --
153+ data FileDiagnostic = FileDiagnostic
154+ { fdFilePath :: NormalizedFilePath
155+ , fdShouldShowDiagnostic :: ShowDiagnostic
156+ , fdLspDiagnostic :: Diagnostic
157+ , fdStructuredMessage :: StructuredMessage
158+ }
159+ deriving (Eq , Ord , Show , Generic )
160+
161+ instance NFData FileDiagnostic
162+
163+ makeLensesWith
164+ (lensRules & lensField .~ mappingNamer (pure . (++ " L" )))
165+ ''FileDiagnostic
165166
166167prettyRange :: Range -> Doc Terminal. AnsiStyle
167168prettyRange Range {.. } = f _start <> " -" <> f _end
0 commit comments