From dfa0e7e31ecf6b70d5343d93149d324f3b101b85 Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Tue, 5 Jan 2016 10:14:07 +0300 Subject: [PATCH] Use new hlint API --- Language/Haskell/GhcMod/Lint.hs | 21 +++++++++++---------- ghc-mod.cabal | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Language/Haskell/GhcMod/Lint.hs b/Language/Haskell/GhcMod/Lint.hs index 854d1d1..5241e5c 100644 --- a/Language/Haskell/GhcMod/Lint.hs +++ b/Language/Haskell/GhcMod/Lint.hs @@ -6,11 +6,10 @@ import Language.Haskell.GhcMod.Logger (checkErrorPrefix) import Language.Haskell.GhcMod.Convert import Language.Haskell.GhcMod.Types import Language.Haskell.GhcMod.Monad -import Language.Haskell.HLint (hlint) +import Language.Haskell.HLint3 import Language.Haskell.GhcMod.Utils (withMappedFile) - -import Data.List (stripPrefix) +import Language.Haskell.Exts.Pretty (prettyPrint) -- | Checking syntax of a target file using hlint. -- Warnings and errors are returned. @@ -18,12 +17,14 @@ lint :: IOish m => LintOpts -- ^ Configuration parameters -> FilePath -- ^ A target file. -> GhcModT m String -lint opt file = - withMappedFile file $ \tempfile -> - liftIO (hlint $ tempfile : "--quiet" : optLintHlintOpts opt) - >>= mapM (replaceFileName tempfile) - >>= ghandle handler . pack - where +lint opt file = ghandle handler $ + withMappedFile file $ \tempfile -> do + (flags, classify, hint) <- liftIO $ argsSettings $ optLintHlintOpts opt + res <- liftIO $ parseModuleEx flags file =<< Just `fmap` readFile tempfile + case res of + Right m -> pack . map show $ applyHints classify hint [m] + Left ParseError{parseErrorLocation=loc, parseErrorMessage=err} -> + return $ prettyPrint loc ++ ":Error:" ++ err ++ "\n" + where pack = convert' . map init -- init drops the last \n. handler (SomeException e) = return $ checkErrorPrefix ++ show e ++ "\n" - replaceFileName fp s = return $ maybe (show s) (file++) $ stripPrefix fp (show s) diff --git a/ghc-mod.cabal b/ghc-mod.cabal index fec548d..25edb40 100644 --- a/ghc-mod.cabal +++ b/ghc-mod.cabal @@ -167,7 +167,7 @@ Library , ghc < 7.11 , ghc-paths < 0.2 , ghc-syb-utils < 0.3 - , hlint < 1.10 && >= 1.8.61 + , hlint < 1.10 && >= 1.9.26 , monad-journal < 0.8 && >= 0.4 , old-time < 1.2 , pretty < 1.2