Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Prevent hie crash if hlint crashes #1153

Merged
merged 1 commit into from
Apr 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions src/Haskell/Ide/Engine/Plugin/ApplyRefact.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
module Haskell.Ide.Engine.Plugin.ApplyRefact where

import Control.Arrow
import Control.Lens hiding (List)
import Control.Exception ( IOException
, try
)
import Control.Lens hiding ( List )
import Control.Monad.IO.Class
import Control.Monad.Trans.Except
import Data.Aeson hiding (Error)
Expand Down Expand Up @@ -105,14 +108,25 @@ lintCmd = CmdSync $ \uri -> do
-- AZ:TODO: Why is this in IdeGhcM?
lintCmd' :: Uri -> IdeGhcM (IdeResult PublishDiagnosticsParams)
lintCmd' uri = pluginGetFile "lintCmd: " uri $ \fp -> do
res <- GM.withMappedFile fp $ \file' -> liftIO $ runExceptT $ runLintCmd file' []
case res of
Left diags ->
return (IdeResultOk (PublishDiagnosticsParams (filePathToUri fp) $ List diags))
Right fs ->
return $ IdeResultOk $
PublishDiagnosticsParams (filePathToUri fp)
$ List (map hintToDiagnostic $ stripIgnores fs)
eitherErrorResult <- GM.withMappedFile fp $ \file' ->
liftIO (try $ runExceptT $ runLintCmd file' [] :: IO (Either IOException (Either [Diagnostic] [Idea])))

case eitherErrorResult of
Left err ->
return
$ IdeResultFail (IdeError PluginError
(T.pack $ "lintCmd: " ++ show err) Null)
Right res -> case res of
Left diags ->
return
(IdeResultOk
(PublishDiagnosticsParams (filePathToUri fp) $ List diags)
)
Right fs ->
return
$ IdeResultOk
$ PublishDiagnosticsParams (filePathToUri fp)
$ List (map hintToDiagnostic $ stripIgnores fs)

runLintCmd :: FilePath -> [String] -> ExceptT [Diagnostic] IO [Idea]
runLintCmd fp args = do
Expand Down