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

Commit 28fd70b

Browse files
committed
Use argsSettings instead of autoSettings
1 parent a6cb029 commit 28fd70b

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

hie-apply-refact/Haskell/Ide/ApplyRefactPlugin.hs

+25-14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Haskell.Ide.ApplyRefactPlugin where
44

55
import Control.Arrow
66
import Control.Monad.IO.Class
7+
import Control.Monad.Trans.Either
78
import Data.Aeson
89
import qualified Data.Text as T
910
import qualified Data.Text.IO as T
@@ -12,7 +13,7 @@ import Haskell.Ide.Engine.MonadFunctions
1213
import Haskell.Ide.Engine.PluginDescriptor
1314
import Haskell.Ide.Engine.PluginUtils
1415
import Haskell.Ide.Engine.SemanticTypes
15-
import Language.Haskell.HLint3
16+
import Language.Haskell.HLint3 as Hlint
1617
import Refact.Apply
1718
import qualified Refact.Types as R
1819
import Refact.Types hiding (SrcSpan)
@@ -78,19 +79,29 @@ applyAllCmd = CmdSync $ \_ctxs req -> do
7879
applyHint :: FilePath -> Maybe Pos -> IO (Either String HieDiff)
7980
applyHint file mpos = do
8081
withTempFile $ \f -> do
81-
(flags,classify,hint) <- autoSettings
82-
res <- parseModuleEx flags file Nothing
83-
case res of
84-
Left err -> return $ Left (unlines [show $ parseErrorLocation err
85-
,parseErrorMessage err
86-
,parseErrorContents err])
87-
Right mod -> do
88-
let commands = map (show &&& ideaRefactoring) $ applyHints classify hint [mod]
89-
logm $ "applyHint:commands=" ++ show commands
90-
appliedFile <- applyRefactorings mpos commands file
91-
diff <- makeDiffResult file (T.pack appliedFile)
92-
logm $ "applyHint:diff=" ++ show diff
93-
return $ Right diff
82+
let optsf = "-o " ++ f
83+
opts = case mpos of
84+
Nothing -> optsf
85+
Just (r,c) -> optsf ++ " --pos " ++ show r ++ "," ++ show c
86+
hlintOpts = [file, "--quiet", "--refactor", "--refactor-options=" ++ opts ]
87+
runEitherT $ do
88+
ideas <- runHlint file hlintOpts
89+
liftIO $ logm $ "applyHint:ideas=" ++ show ideas
90+
let commands = map (show &&& ideaRefactoring) ideas
91+
appliedFile <- liftIO $ applyRefactorings mpos commands file
92+
diff <- liftIO $ makeDiffResult file (T.pack appliedFile)
93+
liftIO $ logm $ "applyHint:diff=" ++ show diff
94+
return diff
95+
96+
97+
runHlint :: FilePath -> [String] -> EitherT String IO [Idea]
98+
runHlint file args =
99+
do (flags,classify,hint) <- liftIO $ argsSettings args
100+
res <- bimapEitherT showParseError id $ EitherT $ parseModuleEx flags file Nothing
101+
pure $ applyHints classify hint [res]
102+
103+
showParseError :: Hlint.ParseError -> String
104+
showParseError (Hlint.ParseError loc message content) = unlines [show loc, message, content]
94105

95106
makeDiffResult :: FilePath -> T.Text -> IO HieDiff
96107
makeDiffResult orig new = do

0 commit comments

Comments
 (0)