Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using multiple files with same htdevtools instance #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions src/CommandArgs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ data HDevTools
| Check
{ socket :: Maybe FilePath
, ghcOpts :: [String]
, file :: String
, files :: [String]
}
| ModuleFile
{ socket :: Maybe FilePath
Expand Down Expand Up @@ -77,7 +77,7 @@ dummyCheck :: HDevTools
dummyCheck = Check
{ socket = Nothing
, ghcOpts = []
, file = ""
, files = []
}

dummyModuleFile :: HDevTools
Expand Down Expand Up @@ -117,8 +117,8 @@ check :: Annotate Ann
check = record dummyCheck
[ socket := def += typFile += help "socket file to use"
, ghcOpts := def += typ "OPTION" += help "ghc options"
, file := def += typFile += argPos 0 += opt ""
] += help "Check a haskell source file for errors and warnings"
, files := def += typ "FILES..." += args += opt ([] :: [FilePath])
] += help "Check haskell source files for errors and warnings"

moduleFile :: Annotate Ann
moduleFile = record dummyModuleFile
Expand Down
8 changes: 4 additions & 4 deletions src/CommandLoop.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module CommandLoop
, startCommandLoop
) where

import Control.Monad (when)
import Control.Monad (forM, when)
import Data.IORef
import Data.List (find)
import MonadUtils (MonadIO, liftIO)
Expand Down Expand Up @@ -101,10 +101,10 @@ configSession state clientSend ghcOpts = do
return ()

runCommand :: IORef State -> ClientSend -> Command -> GHC.Ghc ()
runCommand _ clientSend (CmdCheck file) = do
runCommand _ clientSend (CmdCheck files) = do
let noPhase = Nothing
target <- GHC.guessTarget file noPhase
GHC.setTargets [target]
targets <- forM files $ \f -> GHC.guessTarget f noPhase
GHC.setTargets targets
let handler err = GHC.printException err >> return GHC.Failed
flag <- GHC.handleSourceError handler (GHC.load GHC.LoadAllTargets)
liftIO $ case flag of
Expand Down
20 changes: 13 additions & 7 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,22 @@ doModuleFile sock args =
serverCommand sock (CmdModuleFile (module_ args)) (ghcOpts args)

doFileCommand :: String -> (HDevTools -> Command) -> FilePath -> HDevTools -> IO ()
doFileCommand cmdName cmd sock args
| null (file args) = do
progName <- getProgName
hPutStrLn stderr "You must provide a haskell source file. See:"
hPutStrLn stderr $ progName ++ " " ++ cmdName ++ " --help"
| otherwise = serverCommand sock (cmd args) (ghcOpts args)
doFileCommand cmdName cmd sock args = do
case args of
Check { files = [] } -> missingFileError
Check {} -> serverCommand sock (cmd args) (ghcOpts args)
-- The other commands take only one file; here the check is against "".
_ | null (file args) -> missingFileError
_ -> serverCommand sock (cmd args) (ghcOpts args)
where
missingFileError = do
progName <- getProgName
hPutStrLn stderr "You must provide a haskell source file. See:"
hPutStrLn stderr $ progName ++ " " ++ cmdName ++ " --help"

doCheck :: FilePath -> HDevTools -> IO ()
doCheck = doFileCommand "check" $
\args -> CmdCheck (file args)
\args -> CmdCheck (files args)

doInfo :: FilePath -> HDevTools -> IO ()
doInfo = doFileCommand "info" $
Expand Down
2 changes: 1 addition & 1 deletion src/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ data ClientDirective
deriving (Read, Show)

data Command
= CmdCheck FilePath
= CmdCheck [FilePath]
| CmdModuleFile String
| CmdInfo FilePath String
| CmdType FilePath (Int, Int)
Expand Down