Moving commands to Ghc monad
This commit is contained in:
@@ -1,17 +1,22 @@
|
||||
module Language.Haskell.GhcMod (
|
||||
browseModule
|
||||
, checkSyntax
|
||||
, check
|
||||
, module Language.Haskell.GhcMod.Cradle
|
||||
, debugInfo
|
||||
, debug
|
||||
, infoExpr
|
||||
, info
|
||||
, typeExpr
|
||||
, typeOf
|
||||
, listLanguages
|
||||
, lintSyntax
|
||||
, listModules
|
||||
, module Language.Haskell.GhcMod.Types
|
||||
, listFlags
|
||||
, getGHCVersion
|
||||
, withGHCDummyFile
|
||||
, withGHC
|
||||
) where
|
||||
|
||||
import Language.Haskell.GhcMod.Browse
|
||||
@@ -19,6 +24,7 @@ import Language.Haskell.GhcMod.Check
|
||||
import Language.Haskell.GhcMod.Cradle
|
||||
import Language.Haskell.GhcMod.Debug
|
||||
import Language.Haskell.GhcMod.Flag
|
||||
import Language.Haskell.GhcMod.GHCApi
|
||||
import Language.Haskell.GhcMod.Info
|
||||
import Language.Haskell.GhcMod.Lang
|
||||
import Language.Haskell.GhcMod.Lint
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module Language.Haskell.GhcMod.Browse (browseModule) where
|
||||
module Language.Haskell.GhcMod.Browse (browseModule, browse) where
|
||||
|
||||
import Control.Applicative
|
||||
import Data.Char
|
||||
@@ -17,7 +17,7 @@ import Var
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
browseModule :: Options -> String -> IO String
|
||||
browseModule :: Options -> String -> Ghc String
|
||||
browseModule opt mdlName = convert opt . format <$> browse opt mdlName
|
||||
where
|
||||
format
|
||||
@@ -32,8 +32,8 @@ browseModule opt mdlName = convert opt . format <$> browse opt mdlName
|
||||
(name, tail_) = break isSpace x
|
||||
formatOps' [] = error "formatOps'"
|
||||
|
||||
browse :: Options -> String -> IO [String]
|
||||
browse opt mdlName = withGHCDummyFile $ do
|
||||
browse :: Options -> String -> Ghc [String]
|
||||
browse opt mdlName = do
|
||||
initializeFlags opt
|
||||
getModule >>= getModuleInfo >>= listExports
|
||||
where
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module Language.Haskell.GhcMod.Check (checkSyntax) where
|
||||
module Language.Haskell.GhcMod.Check (checkSyntax, check) where
|
||||
|
||||
import Control.Applicative
|
||||
import Control.Monad
|
||||
@@ -12,13 +12,13 @@ import Prelude
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
checkSyntax :: Options -> Cradle -> String -> IO String
|
||||
checkSyntax :: Options -> Cradle -> String -> Ghc String
|
||||
checkSyntax opt cradle file = unlines <$> check opt cradle file
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
check :: Options -> Cradle -> String -> IO [String]
|
||||
check opt cradle fileName = withGHC fileName $ checkIt `gcatch` handleErrMsg
|
||||
check :: Options -> Cradle -> String -> Ghc [String]
|
||||
check opt cradle fileName = checkIt `gcatch` handleErrMsg
|
||||
where
|
||||
checkIt = do
|
||||
readLog <- initializeFlagsWithCradle opt cradle options True
|
||||
|
||||
@@ -6,6 +6,7 @@ import Control.Monad
|
||||
import Data.List (intercalate)
|
||||
import Data.Maybe
|
||||
import GHC
|
||||
import GhcMonad (liftIO)
|
||||
import Language.Haskell.GhcMod.CabalApi
|
||||
import Language.Haskell.GhcMod.GHCApi
|
||||
import Language.Haskell.GhcMod.Types
|
||||
@@ -13,17 +14,17 @@ import Prelude
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
debugInfo :: Options -> Cradle -> String -> String -> IO String
|
||||
debugInfo :: Options -> Cradle -> String -> String -> Ghc String
|
||||
debugInfo opt cradle ver fileName = unlines <$> debug opt cradle ver fileName
|
||||
|
||||
debug :: Options -> Cradle -> String -> String -> IO [String]
|
||||
debug :: Options -> Cradle -> String -> String -> Ghc [String]
|
||||
debug opt cradle ver fileName = do
|
||||
(gopts, incDir, pkgs) <-
|
||||
if cabal then
|
||||
fromCabalFile (ghcOpts opt) cradle ||> return (ghcOpts opt, [], [])
|
||||
liftIO $ fromCabalFile (ghcOpts opt) cradle ||> return (ghcOpts opt, [], [])
|
||||
else
|
||||
return (ghcOpts opt, [], [])
|
||||
[fast] <- withGHC fileName $ do
|
||||
[fast] <- do
|
||||
void $ initializeFlagsWithCradle opt cradle gopts True
|
||||
setTargetFile fileName
|
||||
pure . canCheckFast <$> depanal [] False
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{-# LANGUAGE TupleSections, FlexibleInstances, TypeSynonymInstances #-}
|
||||
{-# LANGUAGE Rank2Types #-}
|
||||
|
||||
module Language.Haskell.GhcMod.Info (infoExpr, typeExpr) where
|
||||
module Language.Haskell.GhcMod.Info (infoExpr, info, typeExpr, typeOf) where
|
||||
|
||||
import Control.Applicative
|
||||
import Control.Monad (void, when)
|
||||
import CoreUtils
|
||||
import Data.Function
|
||||
import Data.Generics
|
||||
import Data.Generics hiding (typeOf)
|
||||
import Data.List
|
||||
import Data.Maybe
|
||||
import Data.Ord as O
|
||||
@@ -36,10 +36,10 @@ data Cmd = Info | Type deriving Eq
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
infoExpr :: Options -> Cradle -> ModuleString -> Expression -> FilePath -> IO String
|
||||
infoExpr :: Options -> Cradle -> ModuleString -> Expression -> FilePath -> Ghc String
|
||||
infoExpr opt cradle modstr expr file = (++ "\n") <$> info opt cradle file modstr expr
|
||||
|
||||
info :: Options -> Cradle -> FilePath -> ModuleString -> Expression -> IO String
|
||||
info :: Options -> Cradle -> FilePath -> ModuleString -> Expression -> Ghc String
|
||||
info opt cradle fileName modstr expr =
|
||||
inModuleContext Info opt cradle fileName modstr exprToInfo "Cannot show info"
|
||||
where
|
||||
@@ -67,10 +67,10 @@ instance HasType (LHsBind Id) where
|
||||
instance HasType (LPat Id) where
|
||||
getType _ (L spn pat) = return $ Just (spn, hsPatType pat)
|
||||
|
||||
typeExpr :: Options -> Cradle -> ModuleString -> Int -> Int -> FilePath -> IO String
|
||||
typeExpr opt cradle modstr lineNo colNo file = Language.Haskell.GhcMod.Info.typeOf opt cradle file modstr lineNo colNo
|
||||
typeExpr :: Options -> Cradle -> ModuleString -> Int -> Int -> FilePath -> Ghc String
|
||||
typeExpr opt cradle modstr lineNo colNo file = typeOf opt cradle file modstr lineNo colNo
|
||||
|
||||
typeOf :: Options -> Cradle -> FilePath -> ModuleString -> Int -> Int -> IO String
|
||||
typeOf :: Options -> Cradle -> FilePath -> ModuleString -> Int -> Int -> Ghc String
|
||||
typeOf opt cradle fileName modstr lineNo colNo =
|
||||
inModuleContext Type opt cradle fileName modstr exprToType errmsg
|
||||
where
|
||||
@@ -141,9 +141,9 @@ pprInfo pefas (thing, fixity, insts)
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
inModuleContext :: Cmd -> Options -> Cradle -> FilePath -> ModuleString -> Ghc String -> String -> IO String
|
||||
inModuleContext :: Cmd -> Options -> Cradle -> FilePath -> ModuleString -> Ghc String -> String -> Ghc String
|
||||
inModuleContext cmd opt cradle fileName modstr action errmsg =
|
||||
withGHCDummyFile (valid ||> invalid ||> return errmsg)
|
||||
valid ||> invalid ||> return errmsg
|
||||
where
|
||||
valid = do
|
||||
void $ initializeFlagsWithCradle opt cradle ["-w:"] False
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module Language.Haskell.GhcMod.List (listModules) where
|
||||
module Language.Haskell.GhcMod.List (listModules, list) where
|
||||
|
||||
import Control.Applicative
|
||||
import Data.List
|
||||
@@ -10,11 +10,11 @@ import UniqFM
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
listModules :: Options -> IO String
|
||||
listModules :: Options -> Ghc String
|
||||
listModules opt = convert opt . nub . sort <$> list opt
|
||||
|
||||
list :: Options -> IO [String]
|
||||
list opt = withGHCDummyFile $ do
|
||||
list :: Options -> Ghc [String]
|
||||
list opt = do
|
||||
initializeFlags opt
|
||||
getExposedModules <$> getSessionDynFlags
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user