@@ -9,7 +9,7 @@ import Data.Foldable (toList)
9
9
import qualified Data.HashMap.Strict as HM
10
10
import Data.Hashable (Hashable )
11
11
import qualified Data.Map as Map
12
- import Data.Maybe (fromJust )
12
+ import Data.Maybe (fromJust , mapMaybe )
13
13
import qualified Data.Text as T
14
14
import Data.Typeable (Typeable , cast )
15
15
import Development.IDE (Action , FileDiagnostic ,
@@ -80,32 +80,33 @@ rules recorder = do
80
80
void $ uses GetStanDiagnostics $ HM. keys files
81
81
where
82
82
analysisToDiagnostics :: NormalizedFilePath -> Analysis -> [FileDiagnostic ]
83
- analysisToDiagnostics file = map (observationToDianostic file) . toList . analysisObservations
84
- observationToDianostic :: NormalizedFilePath -> Observation -> FileDiagnostic
83
+ analysisToDiagnostics file = mapMaybe (observationToDianostic file) . toList . analysisObservations
84
+ observationToDianostic :: NormalizedFilePath -> Observation -> Maybe FileDiagnostic
85
85
observationToDianostic file (Observation {observationSrcSpan, observationInspectionId}) =
86
- ( file,
87
- ShowDiag ,
88
- LSP. Diagnostic
89
- { _range = realSrcSpanToRange $ observationSrcSpan,
90
- _severity = Just LSP. DsHint ,
91
- _code = Just (LSP. InR $ unId (inspectionId inspection)),
92
- _source = Just " stan" ,
93
- _message = message,
94
- _relatedInformation = Nothing ,
95
- _tags = Nothing
96
- }
97
- )
98
- where
99
- inspection = fromJust $ HM. lookup observationInspectionId inspectionsMap
100
- -- Lookin similar to Stan CLI output
101
- message :: T. Text
102
- message =
103
- T. unlines $
104
- [ " ✲ Name: " <> inspectionName inspection,
105
- " ✲ Description: " <> inspectionDescription inspection,
106
- " Possible solutions:"
107
- ]
108
- ++ map (" - " <> ) (inspectionSolution inspection)
86
+ do
87
+ inspection <- HM. lookup observationInspectionId inspectionsMap
88
+ let
89
+ -- Looking similar to Stan CLI output
90
+ message :: T. Text
91
+ message =
92
+ T. unlines $
93
+ [ " ✲ Name: " <> inspectionName inspection,
94
+ " ✲ Description: " <> inspectionDescription inspection,
95
+ " Possible solutions:"
96
+ ]
97
+ ++ map (" - " <> ) (inspectionSolution inspection)
98
+ return ( file,
99
+ ShowDiag ,
100
+ LSP. Diagnostic
101
+ { _range = realSrcSpanToRange $ observationSrcSpan,
102
+ _severity = Just LSP. DsHint ,
103
+ _code = Just (LSP. InR $ unId (inspectionId inspection)),
104
+ _source = Just " stan" ,
105
+ _message = message,
106
+ _relatedInformation = Nothing ,
107
+ _tags = Nothing
108
+ }
109
+ )
109
110
110
111
getHieFile :: NormalizedFilePath -> Action (Maybe HieFile )
111
112
getHieFile nfp = runMaybeT $ do
0 commit comments