Make linting work with mapped files

This commit is contained in:
Nikolay Yakimov 2015-07-02 21:45:07 +03:00
parent 5b0cca0353
commit d405ce7efa

View File

@ -8,6 +8,10 @@ import Language.Haskell.GhcMod.Monad
import Language.Haskell.GhcMod.Types
import Language.Haskell.HLint (hlint)
import Language.Haskell.GhcMod.FileMappingUtils
import Data.List (stripPrefix)
-- | Checking syntax of a target file using hlint.
-- Warnings and errors are returned.
lint :: IOish m
@ -15,7 +19,11 @@ lint :: IOish m
-> GhcModT m String
lint file = do
opt <- options
ghandle handler . pack =<< liftIO (hlint $ file : "--quiet" : hlintOpts opt)
withMappedFile file $ \tempfile ->
liftIO (hlint $ tempfile : "--quiet" : hlintOpts opt)
>>= mapM (replaceFileName tempfile)
>>= ghandle handler . pack
where
pack = convert' . map (init . show) -- init drops the last \n.
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)