diff --git a/Language/Haskell/GhcMod/Find.hs b/Language/Haskell/GhcMod/Find.hs index eb7d99d..b001e0d 100644 --- a/Language/Haskell/GhcMod/Find.hs +++ b/Language/Haskell/GhcMod/Find.hs @@ -56,7 +56,9 @@ isOutdated db = -- | Looking up 'SymbolDb' with 'Symbol' to \['ModuleString'\] -- which will be concatenated. 'loadSymbolDb' is called internally. findSymbol :: IOish m => Symbol -> GhcModT m String -findSymbol sym = loadSymbolDb >>= lookupSymbol sym +findSymbol sym = do + tmpdir <- cradleTempDir <$> cradle + loadSymbolDb tmpdir >>= lookupSymbol sym -- | Looking up 'SymbolDb' with 'Symbol' to \['ModuleString'\] -- which will be concatenated. @@ -69,12 +71,11 @@ lookupSym sym db = M.findWithDefault [] sym $ table db --------------------------------------------------------------- -- | Loading a file and creates 'SymbolDb'. -loadSymbolDb :: IOish m => GhcModT m SymbolDb -loadSymbolDb = do +loadSymbolDb :: IOish m => FilePath -> GhcModT m SymbolDb +loadSymbolDb dir = do ghcMod <- liftIO ghcModExecutable - tmpdir <- cradleTempDir <$> cradle readProc <- gmReadProcess - file <- liftIO $ chop <$> readProc ghcMod ["dumpsym", tmpdir] "" + file <- liftIO $ chop <$> readProc ghcMod ["dumpsym", dir] "" !db <- M.fromAscList . map conv . lines <$> liftIO (readFile file) return $ SymbolDb { table = db diff --git a/src/GHCMod.hs b/src/GHCMod.hs index 7c738cc..540260a 100644 --- a/src/GHCMod.hs +++ b/src/GHCMod.hs @@ -373,7 +373,8 @@ legacyInteractive :: IOish m => GhcModT m () legacyInteractive = do opt <- options prepareCabalHelper - symdbreq <- liftIO $ newSymDbReq opt + tmpdir <- cradleTempDir <$> cradle + symdbreq <- liftIO $ newSymDbReq opt tmpdir world <- getCurrentWorld legacyInteractiveLoop symdbreq world diff --git a/src/Misc.hs b/src/Misc.hs index 2064a7f..bc5ff9d 100644 --- a/src/Misc.hs +++ b/src/Misc.hs @@ -20,9 +20,9 @@ import Language.Haskell.GhcMod.Internal hiding (MonadIO,liftIO) type SymDbReqAction = (Either GhcModError SymbolDb, GhcModLog) data SymDbReq = SymDbReq (IORef (Async SymDbReqAction)) (IO SymDbReqAction) -newSymDbReq :: Options -> IO SymDbReq -newSymDbReq opt = do - let act = runGhcModT opt loadSymbolDb +newSymDbReq :: Options -> FilePath -> IO SymDbReq +newSymDbReq opt dir = do + let act = runGhcModT opt $ loadSymbolDb dir req <- async act ref <- newIORef req return $ SymDbReq ref act