Don't rely on ghc-mod being in PATH

This commit is contained in:
Daniel Gröber 2014-07-17 16:17:17 +02:00
parent c3b959a8e5
commit 3c04e78ba7

View File

@ -27,12 +27,13 @@ import Exception (ghandle, handleIO)
import qualified GHC as G
import Language.Haskell.GhcMod.Convert
import Language.Haskell.GhcMod.Monad
import Language.Haskell.GhcMod.Utils
import Language.Haskell.GhcMod.Types
import Name (getOccString)
import System.Directory (doesDirectoryExist, getAppUserDataDirectory, doesFileExist, getModificationTime)
import System.FilePath ((</>))
import System.IO
import System.Process (readProcess)
import System.Environment (getExecutablePath)
#ifndef MIN_VERSION_containers
#define MIN_VERSION_containers(x,y,z) 1
@ -84,9 +85,18 @@ lookupSymbol opt sym db = convert opt $ lookupSymbol' sym db
loadSymbolDb :: IO SymbolDb
loadSymbolDb = SymbolDb <$> readSymbolDb
ghcModExecutable :: IO FilePath
ghcModExecutable =
#ifndef SPEC
getExecutablePath
#else
return "dist/build/ghc-mod/ghc-mod"
#endif
readSymbolDb :: IO (Map Symbol [ModuleString])
readSymbolDb = handle (\(SomeException _) -> return M.empty) $ do
file <- chop <$> readProcess "ghc-mod" ["dumpsym"] []
ghcMod <- ghcModExecutable
file <- chop <$> readProcess' ghcMod ["dumpsym"]
M.fromAscList . map conv . lines <$> readFile file
where
conv :: String -> (Symbol,[ModuleString])