Skip to content
Open
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
27 changes: 19 additions & 8 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Data.Tuple (swap)
import Data.Void
import GHC.Generics (Generic)
import Prelude hiding (takeWhile)
import System.IO (stderr, hPutStrLn)
import System.IO (stderr, hPutStrLn, hSetEncoding, utf8)

-- containers
import Data.Set (Set)
Expand Down Expand Up @@ -91,6 +91,7 @@ data Options = Options
{ overwrite :: Bool
, localModulesFromCurrentDir :: Bool
, reportProgress :: Bool
, useStack :: Bool
, filePaths :: [String]
}

Expand All @@ -117,6 +118,13 @@ options = do
& mconcat
& Options.switch

useStack <-
[ Options.long "use-stack"
, Options.help "Run with support for stack."
]
& mconcat
& Options.switch

filePaths <-
[ Options.metavar "FILES..."
, Options.help "The files whose imports will be grouped"
Expand Down Expand Up @@ -153,14 +161,15 @@ groupFileImports
, localModulesFromCurrentDir
, reportProgress
, filePaths
, useStack
} = do

when
reportProgress
(liftIO $ putStrLn $ "processing " ++ show (length filePaths) ++ " number of files.")

globalModulesFromAllGhcPackages <-
liftIO getPackageModulesFromGhcDump
liftIO (getPackageModulesFromGhcDump useStack)
<* when
reportProgress
(liftIO $ putStrLn "got all exposed modules from GHC package set")
Expand Down Expand Up @@ -781,12 +790,14 @@ parseCabalDependencies = do
)
) <?> "package name"

getPackageModulesFromGhcDump :: IO (MonoidalMap ModuleName (NESet PackageSource))
getPackageModulesFromGhcDump = do
(_, hOut, _, _) <-
runInteractiveCommand "ghc-pkg dump"
Text.hGetContents hOut
<&> parse parsePackageDump ""
getPackageModulesFromGhcDump :: Bool -> IO (MonoidalMap ModuleName (NESet PackageSource))
getPackageModulesFromGhcDump useStack' = do
(_hIn, hOut, _hErr, _) <-
runInteractiveCommand (if useStack'
then "stack exec ghc-pkg dump"
else "ghc-pkg dump")
hSetEncoding hOut utf8
Text.hGetContents hOut <&> parse parsePackageDump ""
>>= \case
Left e ->
putStrLn
Expand Down