on master help sign in
Changed Diagnostics to FileDiagnostics (#897)

* Changed Diagnostics to FileDiagnostics * Hlint fixes * Fix tests * Removed the lenses

commit32b6a5fe0012cdb1d81509ee267fb28ec332ef80 authorDavidM-D <dmillardurrant@gmail.com> dateFri 3 May 2019, 19:43 (7 years ago) parentb7e7ae5
9 files changed+60−112
BUILD.bazel−1 src/Development/IDE/Functions/Compile.hs+9−9 src/Development/IDE/Functions/FindImports.hs+3−3 src/Development/IDE/Functions/GHCError.hs+9−8 src/Development/IDE/Functions/Warnings.hs+1−1 src/Development/IDE/State/Rules.hs+10−10 src/Development/IDE/State/Service.hs+1−1 src/Development/IDE/State/Shake.hs+8−9 src/Development/IDE/Types/Diagnostics.hs+19−70
BUILD.bazel−1
@@ -22,7 +22,6 @@ da_haskell_library(
2222 "hashable",
2323 "haskell-lsp",
2424 "haskell-lsp-types",
25− "lens",
2625 "mtl",
2726 "pretty",
2827 "safe-exceptions",
src/Development/IDE/Functions/Compile.hs+9−9
@@ -123,14 +123,14 @@ parseModule
123123 -> PackageState
124124 -> FilePath
125125 -> (UTCTime, SB.StringBuffer)
126− -> IO ([Diagnostic], Maybe ParsedModule)
126+ -> IO ([FileDiagnostic], Maybe ParsedModule)
127127parseModule opt@CompileOpts{..} packageState file =
128128 fmap (either (, Nothing) (second Just)) . Ex.runExceptT .
129129 -- We need packages since imports fail to resolve otherwise.
130130 runGhcSessionExcept opt Nothing packageState . parseFileContents optPreprocessor file
131131
132132computePackageDeps ::
133− CompileOpts -> PackageState -> InstalledUnitId -> IO (Either [Diagnostic] [InstalledUnitId])
133+ CompileOpts -> PackageState -> InstalledUnitId -> IO (Either [FileDiagnostic] [InstalledUnitId])
134134computePackageDeps opts packageState iuid =
135135 Ex.runExceptT $
136136 runGhcSessionExcept opts Nothing packageState $
@@ -155,7 +155,7 @@ typecheckModule
155155 -> [TcModuleResult]
156156 -> [LoadPackageResult]
157157 -> ParsedModule
158− -> IO ([Diagnostic], Maybe TcModuleResult)
158+ -> IO ([FileDiagnostic], Maybe TcModuleResult)
159159typecheckModule opt mod packageState uniqSupply deps pkgs pm =
160160 fmap (either (, Nothing) (second Just)) $ Ex.runExceptT $
161161 runGhcSessionExcept opt (Just mod) packageState $
@@ -173,7 +173,7 @@ loadPackage ::
173173 -> UniqSupply
174174 -> [LoadPackageResult]
175175 -> InstalledUnitId
176− -> IO (Either [Diagnostic] LoadPackageResult)
176+ -> IO (Either [FileDiagnostic] LoadPackageResult)
177177loadPackage opt packageState us lps p =
178178 Ex.runExceptT $
179179 runGhcSessionExcept opt Nothing packageState $
@@ -202,7 +202,7 @@ compileModule
202202 -> [TcModuleResult]
203203 -> [LoadPackageResult]
204204 -> TcModuleResult
205− -> IO ([Diagnostic], Maybe GhcModule)
205+ -> IO ([FileDiagnostic], Maybe GhcModule)
206206compileModule opt mod packageState uniqSupply deps pkgs tmr =
207207 fmap (either (, Nothing) (second Just)) $ Ex.runExceptT $
208208 runGhcSessionExcept opt (Just mod) packageState $
@@ -406,7 +406,7 @@ getModSummaryFromBuffer
406406 -> (SB.StringBuffer, UTCTime)
407407 -> DynFlags
408408 -> GHC.ParsedSource
409− -> Ex.ExceptT [Diagnostic] m ModSummary
409+ -> Ex.ExceptT [FileDiagnostic] m ModSummary
410410getModSummaryFromBuffer fp (contents, fileDate) dflags parsed = do
411411 (modName, imports) <- FindImports.getImportsParsed dflags parsed
412412
@@ -445,7 +445,7 @@ parseFileContents
445445 => (GHC.ParsedSource -> ([(GHC.SrcSpan, String)], GHC.ParsedSource))
446446 -> FilePath -- ^ the filename (for source locations)
447447 -> (UTCTime, SB.StringBuffer) -- ^ Haskell module source text (full Unicode is supported)
448− -> Ex.ExceptT [Diagnostic] m ([Diagnostic], ParsedModule)
448+ -> Ex.ExceptT [FileDiagnostic] m ([FileDiagnostic], ParsedModule)
449449parseFileContents preprocessor filename (time, contents) = do
450450 let loc = mkRealSrcLoc (mkFastString filename) 1 1
451451 dflags <- parsePragmasIntoDynFlags filename contents
@@ -479,7 +479,7 @@ parsePragmasIntoDynFlags
479479 :: GhcMonad m
480480 => FilePath
481481 -> SB.StringBuffer
482− -> Ex.ExceptT [Diagnostic] m DynFlags
482+ -> Ex.ExceptT [FileDiagnostic] m DynFlags
483483parsePragmasIntoDynFlags fp contents = catchSrcErrors $ do
484484 dflags0 <- getSessionDynFlags
485485 let opts = Hdr.getOptions dflags0 contents fp
@@ -494,7 +494,7 @@ generatePackageState paths hideAllPkgs pkgImports = do
494494
495495-- | Run something in a Ghc monad and catch the errors (SourceErrors and
496496-- compiler-internal exceptions like Panic or InstallationError).
497−catchSrcErrors :: GhcMonad m => m a -> Ex.ExceptT [Diagnostic] m a
497+catchSrcErrors :: GhcMonad m => m a -> Ex.ExceptT [FileDiagnostic] m a
498498catchSrcErrors ghcM = do
499499 dflags <- getDynFlags
500500 Ex.ExceptT $
src/Development/IDE/Functions/FindImports.hs+3−3
@@ -39,7 +39,7 @@ data Import
3939getImportsParsed :: Monad m =>
4040 DynFlags ->
4141 GHC.ParsedSource ->
42− Ex.ExceptT [Diagnostic] m
42+ Ex.ExceptT [FileDiagnostic] m
4343 (M.ModuleName, [(Maybe FastString, Located M.ModuleName)])
4444getImportsParsed dflags (L loc parsed) = do
4545 let modName = maybe (GHC.mkModuleName "Main") GHC.unLoc $ GHC.hsmodName parsed
@@ -82,7 +82,7 @@ locateModule
8282 -> (FilePath -> m Bool)
8383 -> Located ModuleName
8484 -> Maybe FastString
85− -> m (Either [Diagnostic] Import)
85+ -> m (Either [FileDiagnostic] Import)
8686locateModule dflags doesExist modName mbPkgName = do
8787 case mbPkgName of
8888 -- if a package name is given we only go look for a package
@@ -101,7 +101,7 @@ locateModule dflags doesExist modName mbPkgName = do
101101 reason -> return $ Left $ notFoundErr dfs modName reason
102102
103103-- | Don't call this on a found module.
104−notFoundErr :: DynFlags -> Located M.ModuleName -> LookupResult -> [Diagnostic]
104+notFoundErr :: DynFlags -> Located M.ModuleName -> LookupResult -> [FileDiagnostic]
105105notFoundErr dfs modName reason =
106106 mkError' $ ppr' $ cannotFindModule dfs modName0 $ lookupToFindResult reason
107107 where
src/Development/IDE/Functions/GHCError.hs+9−8
@@ -5,6 +5,7 @@ module Development.IDE.Functions.GHCError
55 ( mkDiag
66 , toDiagnostics
77 , srcSpanToLocation
8+ , srcSpanToFilename
89
910 -- * Producing GHC ErrorMessages
1011 , mkErrors
@@ -14,6 +15,7 @@ module Development.IDE.Functions.GHCError
1415
1516 -- * Handling errors in the GHC monad (SourceError, ErrorMessages)
1617 , Diagnostic
18+ , FileDiagnostic
1719 , ErrorMessages -- included in module export below
1820 , ErrMsg
1921 , errMsgSpan
@@ -26,7 +28,6 @@ module Development.IDE.Functions.GHCError
2628 , noSpan
2729 ) where
2830
29−import Control.Lens
3031import Development.IDE.Types.Diagnostics as D
3132import qualified Data.Text as T
3233import Development.IDE.UtilGHC()
@@ -41,16 +42,16 @@ import qualified Language.Haskell.LSP.Types as LSP
4142
4243
4344
44−toDiagnostics :: DynFlags -> ErrorMessages -> [Diagnostic]
45+toDiagnostics :: DynFlags -> ErrorMessages -> [FileDiagnostic]
4546toDiagnostics dflags = mapMaybe (mkDiag dflags $ T.pack "Compiler") . bagToList
4647
4748
48−mkDiag :: DynFlags -> T.Text -> ErrMsg -> Maybe Diagnostic
49+mkDiag :: DynFlags -> T.Text -> ErrMsg -> Maybe FileDiagnostic
4950mkDiag dflags src e =
5051 case toDSeverity $ errMsgSeverity e of
5152 Nothing -> Nothing
5253 Just bSeverity ->
53− Just $ set dLocation (Just $ srcSpanToLocation $ errMsgSpan e)
54+ Just $ (srcSpanToFilename $ errMsgSpan e,)
5455 Diagnostic
5556 { _range = srcSpanToRange $ errMsgSpan e
5657 , _severity = Just bSeverity
@@ -94,15 +95,15 @@ toDSeverity SevFatal = Just DsError
9495
9596-- | Produce a bag of GHC-style errors (@ErrorMessages@) from the given
9697-- (optional) locations and message strings.
97−mkErrors :: DynFlags -> [(SrcSpan, String)] -> [Diagnostic]
98+mkErrors :: DynFlags -> [(SrcSpan, String)] -> [FileDiagnostic]
9899mkErrors dflags = concatMap (uncurry $ mkError dflags)
99100
100101-- | Produce a GHC-style error from a source span and a message.
101−mkError :: DynFlags -> SrcSpan -> String -> [Diagnostic]
102+mkError :: DynFlags -> SrcSpan -> String -> [FileDiagnostic]
102103mkError dflags sp = toDiagnostics dflags . Bag.listToBag . pure . mkPlainErrMsg dflags sp . Out.text
103104
104105-- | Produce a GHC-style error from a source span and a message.
105−mkErrorDoc :: DynFlags -> SrcSpan -> Out.SDoc -> [Diagnostic]
106+mkErrorDoc :: DynFlags -> SrcSpan -> Out.SDoc -> [FileDiagnostic]
106107mkErrorDoc dflags sp = toDiagnostics dflags . Bag.listToBag . pure . mkPlainErrMsg dflags sp
107108
108109
@@ -123,7 +124,7 @@ realSpan = \case
123124 UnhelpfulSpan _ -> Nothing
124125
125126
126−mkErrorsGhcException :: DynFlags -> GhcException -> [Diagnostic]
127+mkErrorsGhcException :: DynFlags -> GhcException -> [FileDiagnostic]
127128mkErrorsGhcException dflags exc = mkErrors dflags [(noSpan "<Internal>", showGHCE dflags exc)]
128129
129130showGHCE :: DynFlags -> GhcException -> String
src/Development/IDE/Functions/Warnings.hs+1−1
@@ -26,7 +26,7 @@ import Development.IDE.Functions.GHCError
2626-- https://github.com/ghc/ghc/blob/5f1d949ab9e09b8d95319633854b7959df06eb58/compiler/main/GHC.hs#L623-L640
2727-- which basically says that log_action is taken from the ModSummary when GHC feels like it.
2828-- The given argument lets you refresh a ModSummary log_action
29−withWarnings :: GhcMonad m => T.Text -> ((ModSummary -> ModSummary) -> m a) -> m ([Diagnostic], a)
29+withWarnings :: GhcMonad m => T.Text -> ((ModSummary -> ModSummary) -> m a) -> m ([FileDiagnostic], a)
3030withWarnings phase action = do
3131 warnings <- liftIO $ newVar []
3232 oldFlags <- getDynFlags
src/Development/IDE/State/Rules.hs+10−10
@@ -25,7 +25,6 @@ module Development.IDE.State.Rules(
2525
2626import Control.Concurrent.Extra
2727import Control.Exception (evaluate)
28−import Control.Lens (set)
2928import Control.Monad.Except
3029import Control.Monad.Extra (whenJust)
3130import qualified Development.IDE.Functions.Compile as Compile
@@ -56,11 +55,11 @@ import Development.IDE.State.Shake
5655
5756-- LEGACY STUFF ON THE OLD STYLE
5857
59−toIdeResultNew :: Either [Diagnostic] v -> IdeResult v
58+toIdeResultNew :: Either [FileDiagnostic] v -> IdeResult v
6059toIdeResultNew = either (, Nothing) (([],) . Just)
6160
6261-- Convert to a legacy Ide result but dropping dependencies
63−toIdeResultSilent :: Maybe v -> Either [Diagnostic] v
62+toIdeResultSilent :: Maybe v -> Either [FileDiagnostic] v
6463toIdeResultSilent val = maybe (Left []) Right val
6564
6665
@@ -116,17 +115,17 @@ getDefinition file pos = do
116115
117116useE
118117 :: IdeRule k v
119− => k -> FilePath -> ExceptT [Diagnostic] Action v
118+ => k -> FilePath -> ExceptT [FileDiagnostic] Action v
120119useE k = ExceptT . fmap toIdeResultSilent . use k
121120
122121-- picks the first error
123122usesE
124123 :: IdeRule k v
125− => k -> [FilePath] -> ExceptT [Diagnostic] Action [v]
124+ => k -> [FilePath] -> ExceptT [FileDiagnostic] Action [v]
126125usesE k = ExceptT . fmap (mapM toIdeResultSilent) . uses k
127126
128127-- | Generate the GHC Core for the supplied file and its dependencies.
129−coresForFile :: FilePath -> ExceptT [Diagnostic] Action [CoreModule]
128+coresForFile :: FilePath -> ExceptT [FileDiagnostic] Action [CoreModule]
130129coresForFile file = do
131130 files <- transitiveModuleDeps <$> useE GetDependencies file
132131 pms <- usesE GetParsedModule $ files ++ [file]
@@ -141,14 +140,14 @@ coresForFile file = do
141140getAtPointForFile
142141 :: FilePath
143142 -> Position
144− -> ExceptT [Diagnostic] Action (Maybe (Maybe Range, [HoverText]))
143+ -> ExceptT [FileDiagnostic] Action (Maybe (Maybe Range, [HoverText]))
145144getAtPointForFile file pos = do
146145 files <- transitiveModuleDeps <$> useE GetDependencies file
147146 tms <- usesE TypeCheck (file : files)
148147 spans <- useE GetSpanInfo file
149148 return $ AtPoint.atPoint (map Compile.tmrModule tms) spans pos
150149
151−getDefinitionForFile :: FilePath -> Position -> ExceptT [Diagnostic] Action (Maybe Location)
150+getDefinitionForFile :: FilePath -> Position -> ExceptT [FileDiagnostic] Action (Maybe Location)
152151getDefinitionForFile file pos = do
153152 spans <- useE GetSpanInfo file
154153 return $ AtPoint.gotoDefinition spans pos
@@ -193,7 +192,7 @@ getLocatedImportsRule =
193192
194193-- | Given a target file path, construct the raw dependency results by following
195194-- imports recursively.
196−rawDependencyInformation :: FilePath -> ExceptT [Diagnostic] Action RawDependencyInformation
195+rawDependencyInformation :: FilePath -> ExceptT [FileDiagnostic] Action RawDependencyInformation
197196rawDependencyInformation f = go (Set.singleton f) Map.empty Map.empty
198197 where go fs !modGraph !pkgs =
199198 case Set.minView fs of
@@ -241,7 +240,7 @@ reportImportCyclesRule =
241240 where cycleErrorInFile f (PartOfCycle imp fs)
242241 | f `elem` fs = Just (imp, fs)
243242 cycleErrorInFile _ _ = Nothing
244− toDiag imp mods = set dLocation (Just loc) $ Diagnostic
243+ toDiag imp mods = (fp ,) $ Diagnostic
245244 { _range = (_range :: Location -> Range) loc
246245 , _severity = Just DsError
247246 , _source = Just "Import cycle detection"
@@ -250,6 +249,7 @@ reportImportCyclesRule =
250249 , _relatedInformation = Nothing
251250 }
252251 where loc = srcSpanToLocation (getLoc imp)
252+ fp = srcSpanToFilename (getLoc imp)
253253 getModuleName file = do
254254 pm <- useE GetParsedModule file
255255 pure (moduleNameString . moduleName . ms_mod $ pm_mod_summary pm)
src/Development/IDE/State/Service.hs+1−1
@@ -59,7 +59,7 @@ mkEnv options = do
5959 , envUniqSupplyVar = uniqSupplyVar
6060 }
6161
62−getDiagnostics :: IdeState -> IO [Diagnostic]
62+getDiagnostics :: IdeState -> IO [FileDiagnostic]
6363getDiagnostics = getAllDiagnostics
6464
6565unsafeClearDiagnostics :: IdeState -> IO ()
src/Development/IDE/State/Shake.hs+8−9
@@ -61,7 +61,6 @@ import Development.IDE.Types.Diagnostics
6161import Control.Concurrent.Extra
6262import Control.Exception
6363import Control.DeepSeq
64−import Control.Lens (view, set)
6564import System.Time.Extra
6665import Data.Typeable
6766import Data.Tuple.Extra
@@ -149,7 +148,7 @@ instance Hashable Key where
149148--
150149-- A rule on a file should only return diagnostics for that given file. It should
151150-- not propagate diagnostic errors through multiple phases.
152−type IdeResult v = ([Diagnostic], Maybe v)
151+type IdeResult v = ([FileDiagnostic], Maybe v)
153152
154153type IdeRule k v =
155154 ( Shake.RuleResult k ~ v
@@ -198,7 +197,7 @@ setValues :: IdeRule k v
198197 -> k
199198 -> FilePath
200199 -> IdeResult v
201− -> IO (Maybe [Diagnostic], [Diagnostic]) -- ^ (before, after)
200+ -> IO (Maybe [FileDiagnostic], [FileDiagnostic]) -- ^ (before, after)
202201setValues state key file val = modifyVar state $ \inVal -> do
203202 let k = Key key
204203 outVal = Map.insertWith Map.union file (Map.singleton k $ second (fmap toDyn) val) inVal
@@ -261,7 +260,7 @@ useStale IdeState{shakeExtras=ShakeExtras{state}} k fp =
261260 join <$> getValues state k fp
262261
263262
264−getAllDiagnostics :: IdeState -> IO [Diagnostic]
263+getAllDiagnostics :: IdeState -> IO [FileDiagnostic]
265264getAllDiagnostics IdeState{shakeExtras = ShakeExtras{state}} = do
266265 val <- readVar state
267266 return $ concatMap (concatMap fst . Map.elems) $ Map.elems val
@@ -362,7 +361,7 @@ defineEarlyCutoff op = addBuiltinRule noLint noIdentity $ \(Q (key, file)) old m
362361 (bs, res) <- actionCatch
363362 (do v <- op key file; liftIO $ evaluate $ force v) $
364363 \(e :: SomeException) -> pure (Nothing, ([ideErrorText file $ T.pack $ show e | not $ isBadDependency e],Nothing))
365− res <- return $ first (map $ set dFilePath $ Just file) res
364+ res <- return $ first (map $ \(_,d) -> (file,d)) res
366365
367366 (before, after) <- liftIO $ setValues state key file res
368367 updateFileDiagnostics file before after
@@ -380,8 +379,8 @@ defineEarlyCutoff op = addBuiltinRule noLint noIdentity $ \(Q (key, file)) old m
380379
381380updateFileDiagnostics ::
382381 FilePath
383− -> Maybe [Diagnostic] -- ^ previous results for this file
384− -> [Diagnostic] -- ^ current results
382+ -> Maybe [FileDiagnostic] -- ^ previous results for this file
383+ -> [FileDiagnostic] -- ^ current results
385384 -> Action ()
386385updateFileDiagnostics afp previousAll currentAll = do
387386 -- TODO (MK) We canonicalize to make sure that the two files agree on use of
@@ -392,13 +391,13 @@ updateFileDiagnostics afp previousAll currentAll = do
392391 let filtM diags = do
393392 diags' <-
394393 filterM
395− (\x -> fmap (== Just afp') (traverse canonicalizePath $ view dFilePath x))
394+ (\x -> fmap (== afp') (canonicalizePath $ fst x))
396395 diags
397396 pure (Set.fromList diags')
398397 previous <- liftIO $ traverse filtM previousAll
399398 current <- liftIO $ filtM currentAll
400399 when (Just current /= previous) $
401− sendEvent $ EventFileDiagnostics $ (filePathToUri afp, Set.toList current)
400+ sendEvent $ EventFileDiagnostics $ (afp, map snd $ Set.toList current)
402401
403402
404403setPriority :: (Enum a) => a -> Action ()
src/Development/IDE/Types/Diagnostics.hs+19−70
@@ -8,6 +8,7 @@
88module Development.IDE.Types.Diagnostics (
99 LSP.Diagnostic(..),
1010 FileDiagnostics,
11+ FileDiagnostic,
1112 Location(..),
1213 Range(..),
1314 LSP.DiagnosticSeverity(..),
@@ -30,21 +31,17 @@ module Development.IDE.Types.Diagnostics (
3031 defDiagnostic,
3132 addDiagnostics,
3233 filterSeriousErrors,
33− dLocation,
34− dFilePath,
3534 filePathToUri,
3635 getDiagnosticsFromStore
3736 ) where
3837
3938import Control.Exception
40−import Control.Lens (Lens', lens, set, view)
4139import Data.Either.Combinators
4240import Data.Maybe as Maybe
4341import Data.Foldable
4442import qualified Data.Map as Map
4543import qualified Data.Text as T
4644import Data.Text.Prettyprint.Doc.Syntax
47−import Data.String (IsString(..))
4845import qualified Text.PrettyPrint.Annotated.HughesPJClass as Pretty
4946import Language.Haskell.LSP.Types as LSP (
5047 DiagnosticSeverity(..)
@@ -59,15 +56,15 @@ import Language.Haskell.LSP.Diagnostics
5956
6057import Development.IDE.Types.Location
6158
62−ideErrorText :: FilePath -> T.Text -> LSP.Diagnostic
59+ideErrorText :: FilePath -> T.Text -> FileDiagnostic
6360ideErrorText fp = errorDiag fp "Ide Error"
6461
65−ideErrorPretty :: Pretty.Pretty e => FilePath -> e -> LSP.Diagnostic
62+ideErrorPretty :: Pretty.Pretty e => FilePath -> e -> FileDiagnostic
6663ideErrorPretty fp = ideErrorText fp . T.pack . Pretty.prettyShow
6764
68−errorDiag :: FilePath -> T.Text -> T.Text -> LSP.Diagnostic
69−errorDiag fp src =
70− set dFilePath (Just fp) . diagnostic noRange LSP.DsError src
65+errorDiag :: FilePath -> T.Text -> T.Text -> FileDiagnostic
66+errorDiag fp src msg =
67+ (fp, diagnostic noRange LSP.DsError src msg)
7168
7269-- | This is for compatibility with our old diagnostic type
7370diagnostic :: Range
@@ -99,33 +96,6 @@ defDiagnostic _range _message = LSP.Diagnostic {
9996 , _relatedInformation = Nothing
10097 }
10198
102−-- | setLocation but with no range information
103−dFilePath ::
104− Lens' LSP.Diagnostic (Maybe FilePath)
105−dFilePath = lens g s where
106− g :: LSP.Diagnostic -> Maybe FilePath
107− g d = (uriToFilePath . _uri) =<< view dLocation d
108− s :: LSP.Diagnostic -> Maybe FilePath -> LSP.Diagnostic
109− s d@Diagnostic{..} fp = set dLocation
110− (Location <$> (filePathToUri <$> fp) <*> pure _range) d
111−
112−-- | This adds location information to the diagnostics but this is only used in
113−-- the case of serious errors to give some context to what went wrong
114−dLocation ::
115− Lens' LSP.Diagnostic (Maybe Location)
116−dLocation = lens g s where
117− s :: LSP.Diagnostic -> Maybe Location -> LSP.Diagnostic
118− s d = \case
119− Just loc ->
120− d {LSP._range=(_range :: Location -> Range) loc
121− , LSP._relatedInformation = Just $ LSP.List [DiagnosticRelatedInformation loc "dLocation: Unknown error"]}
122− Nothing -> d {LSP._range = noRange, LSP._relatedInformation = Nothing}
123− g :: LSP.Diagnostic -> Maybe Location
124− g Diagnostic{..} = case _relatedInformation of
125− Just (List [DiagnosticRelatedInformation loc _]) -> Just loc
126− Just (List xs) -> error $ "Diagnostic created, expected 1 related information but got" <> show xs
127− Nothing -> Nothing
128−
12999filterSeriousErrors ::
130100 FilePath ->
131101 [LSP.Diagnostic] ->
@@ -148,7 +118,7 @@ addDiagnostics fp diags ds =
148118 Nothing $
149119 partitionBySource diags
150120
151−ideTryIOException :: FilePath -> IO a -> IO (Either LSP.Diagnostic a)
121+ideTryIOException :: FilePath -> IO a -> IO (Either FileDiagnostic a)
152122ideTryIOException fp act =
153123 mapLeft (\(e :: IOException) -> ideErrorText fp $ T.pack $ show e) <$> try act
154124
@@ -158,7 +128,8 @@ ideTryIOException fp act =
158128-- along with the related source location so that we can display the error
159129-- on either the console or in the IDE at the right source location.
160130--
161−type FileDiagnostics = (Uri, [Diagnostic])
131+type FileDiagnostics = (FilePath, [Diagnostic])
132+type FileDiagnostic = (FilePath, Diagnostic)
162133
163134prettyRange :: Range -> Doc SyntaxClass
164135prettyRange Range{..} = f _start <> "-" <> f _end
@@ -167,20 +138,20 @@ prettyRange Range{..} = f _start <> "-" <> f _end
167138stringParagraphs :: T.Text -> Doc a
168139stringParagraphs = vcat . map (fillSep . map pretty . T.words) . T.lines
169140
170−showDiagnostics :: [LSP.Diagnostic] -> T.Text
141+showDiagnostics :: [FileDiagnostic] -> T.Text
171142showDiagnostics = srenderPlain . prettyDiagnostics
172143
173−showDiagnosticsColored :: [LSP.Diagnostic] -> T.Text
144+showDiagnosticsColored :: [FileDiagnostic] -> T.Text
174145showDiagnosticsColored = srenderColored . prettyDiagnostics
175146
176147
177−prettyDiagnostics :: [LSP.Diagnostic] -> Doc SyntaxClass
148+prettyDiagnostics :: [FileDiagnostic] -> Doc SyntaxClass
178149prettyDiagnostics = vcat . map prettyDiagnostic
179150
180−prettyDiagnostic :: LSP.Diagnostic -> Doc SyntaxClass
181−prettyDiagnostic d@LSP.Diagnostic{..} =
151+prettyDiagnostic :: FileDiagnostic -> Doc SyntaxClass
152+prettyDiagnostic (fp, LSP.Diagnostic{..}) =
182153 vcat
183− [ slabel_ "File: " $ pretty $ view dFilePath d
154+ [ slabel_ "File: " $ pretty fp
184155 , slabel_ "Range: " $ prettyRange _range
185156 , slabel_ "Source: " $ pretty _source
186157 , slabel_ "Severity:" $ pretty $ show sev
@@ -199,38 +170,16 @@ prettyDiagnostic d@LSP.Diagnostic{..} =
199170prettyDiagnosticStore :: DiagnosticStore -> Doc SyntaxClass
200171prettyDiagnosticStore ds =
201172 vcat $
202− map prettyFileDiagnostics $
173+ map (\(uri, diags) -> prettyFileDiagnostics (fromMaybe noFilePath $ uriToFilePath uri, diags)) $
203174 Map.assocs $
204175 Map.map getDiagnosticsFromStore ds
205176
206177prettyFileDiagnostics :: FileDiagnostics -> Doc SyntaxClass
207−prettyFileDiagnostics (uri, diags) =
178+prettyFileDiagnostics (filePath, diags) =
208179 slabel_ "Compiler error in" $ vcat
209180 [ slabel_ "File:" $ pretty filePath
210− , slabel_ "Errors:" $ vcat $ map prettyDiagnostic diags
211− ] where
212−
213− -- prettyFileDiags :: (FilePath, [(T.Text, [LSP.Diagnostic])]) -> Doc SyntaxClass
214− -- prettyFileDiags (fp,stages) =
215− -- slabel_ ("File: "<>fp) $ vcat $ map prettyStage stages
216−
217− -- prettyStage :: (T.Text, [LSP.Diagnostic]) -> Doc SyntaxClass
218− -- prettyStage (stage,diags) =
219− -- slabel_ ("Stage: "<>T.unpack stage) $ vcat $ map prettyDiagnostic diags
220−
221− filePath :: FilePath
222− filePath = fromMaybe dontKnow $ uriToFilePath uri
223−
224− -- storeContents ::
225− -- (FilePath, [(T.Text, [LSP.Diagnostic])])
226− -- -- ^ Source File, Stage Source, Diags
227− -- storeContents = (fromMaybe dontKnow $ uriToFilePath uri, getDiags diags)
228−
229− dontKnow :: IsString s => s
230− dontKnow = "<unknown>"
231−
232− -- getDiags :: DiagnosticsBySource -> [(T.Text, [LSP.Diagnostic])]
233− -- getDiags = map (\(ds, diag) -> (fromMaybe dontKnow ds, toList diag)) . Map.assocs
181+ , slabel_ "Errors:" $ vcat $ map (prettyDiagnostic . (filePath,)) diags
182+ ]
234183
235184getDiagnosticsFromStore :: StoreItem -> [Diagnostic]
236185getDiagnosticsFromStore (StoreItem _ diags) =