Merge pull request #738 from atom-haskell/find-cache-master
Non-interactive find cache
This commit is contained in:
commit
28356c1367
@ -56,7 +56,8 @@ import Data.Map (Map)
|
|||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import Data.Set (Set)
|
import Data.Set (Set)
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
|
import Language.Haskell.GhcMod.PathsAndFiles
|
||||||
|
import System.Directory
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
@ -83,7 +84,7 @@ isOutdated db =
|
|||||||
-- | Looking up 'SymbolDb' with 'Symbol' to \['ModuleString'\]
|
-- | Looking up 'SymbolDb' with 'Symbol' to \['ModuleString'\]
|
||||||
-- which will be concatenated. 'loadSymbolDb' is called internally.
|
-- which will be concatenated. 'loadSymbolDb' is called internally.
|
||||||
findSymbol :: IOish m => String -> GhcModT m String
|
findSymbol :: IOish m => String -> GhcModT m String
|
||||||
findSymbol sym = loadSymbolDb >>= lookupSymbol sym
|
findSymbol sym = loadSymbolDb' >>= lookupSymbol sym
|
||||||
|
|
||||||
-- | Looking up 'SymbolDb' with 'Symbol' to \['ModuleString'\]
|
-- | Looking up 'SymbolDb' with 'Symbol' to \['ModuleString'\]
|
||||||
-- which will be concatenated.
|
-- which will be concatenated.
|
||||||
@ -95,6 +96,21 @@ lookupSym sym db = map (ModuleString . unpackFS . mkFastStringByteString') $ S.t
|
|||||||
|
|
||||||
---------------------------------------------------------------
|
---------------------------------------------------------------
|
||||||
|
|
||||||
|
loadSymbolDb' :: IOish m => GhcModT m SymbolDb
|
||||||
|
loadSymbolDb' = do
|
||||||
|
cache <- symbolCache <$> cradle
|
||||||
|
let doLoad True = do
|
||||||
|
db <- decode <$> liftIO (LBS.readFile cache)
|
||||||
|
outdated <- isOutdated db
|
||||||
|
if outdated
|
||||||
|
then doLoad False
|
||||||
|
else return db
|
||||||
|
doLoad False = do
|
||||||
|
db <- loadSymbolDb
|
||||||
|
liftIO $ LBS.writeFile cache $ encode db
|
||||||
|
return db
|
||||||
|
doLoad =<< liftIO (doesFileExist cache)
|
||||||
|
|
||||||
-- | Loading a file and creates 'SymbolDb'.
|
-- | Loading a file and creates 'SymbolDb'.
|
||||||
loadSymbolDb :: IOish m => GhcModT m SymbolDb
|
loadSymbolDb :: IOish m => GhcModT m SymbolDb
|
||||||
loadSymbolDb = do
|
loadSymbolDb = do
|
||||||
|
@ -220,7 +220,7 @@ packageCache = "package.cache"
|
|||||||
|
|
||||||
-- | Filename of the symbol table cache file.
|
-- | Filename of the symbol table cache file.
|
||||||
symbolCache :: Cradle -> FilePath
|
symbolCache :: Cradle -> FilePath
|
||||||
symbolCache crdl = cradleTempDir crdl </> symbolCacheFile
|
symbolCache crdl = cradleRootDir crdl </> cradleDistDir crdl </> symbolCacheFile
|
||||||
|
|
||||||
symbolCacheFile :: String
|
symbolCacheFile :: String
|
||||||
symbolCacheFile = "ghc-mod.symbol-cache"
|
symbolCacheFile = "ghc-mod.symbol-cache"
|
||||||
|
@ -19,7 +19,6 @@ data World = World {
|
|||||||
, worldCabalFile :: Maybe TimedFile
|
, worldCabalFile :: Maybe TimedFile
|
||||||
, worldCabalConfig :: Maybe TimedFile
|
, worldCabalConfig :: Maybe TimedFile
|
||||||
, worldCabalSandboxConfig :: Maybe TimedFile
|
, worldCabalSandboxConfig :: Maybe TimedFile
|
||||||
, worldSymbolCache :: Maybe TimedFile
|
|
||||||
} deriving (Eq)
|
} deriving (Eq)
|
||||||
|
|
||||||
timedPackageCaches :: IOish m => GhcModT m [TimedFile]
|
timedPackageCaches :: IOish m => GhcModT m [TimedFile]
|
||||||
@ -35,14 +34,12 @@ getCurrentWorld = do
|
|||||||
mCabalFile <- liftIO $ timeFile `traverse` cradleCabalFile crdl
|
mCabalFile <- liftIO $ timeFile `traverse` cradleCabalFile crdl
|
||||||
mCabalConfig <- liftIO $ timeMaybe (setupConfigFile crdl)
|
mCabalConfig <- liftIO $ timeMaybe (setupConfigFile crdl)
|
||||||
mCabalSandboxConfig <- liftIO $ timeMaybe (sandboxConfigFile crdl)
|
mCabalSandboxConfig <- liftIO $ timeMaybe (sandboxConfigFile crdl)
|
||||||
mSymbolCache <- liftIO $ timeMaybe (symbolCache crdl)
|
|
||||||
|
|
||||||
return World {
|
return World {
|
||||||
worldPackageCaches = pkgCaches
|
worldPackageCaches = pkgCaches
|
||||||
, worldCabalFile = mCabalFile
|
, worldCabalFile = mCabalFile
|
||||||
, worldCabalConfig = mCabalConfig
|
, worldCabalConfig = mCabalConfig
|
||||||
, worldCabalSandboxConfig = mCabalSandboxConfig
|
, worldCabalSandboxConfig = mCabalSandboxConfig
|
||||||
, worldSymbolCache = mSymbolCache
|
|
||||||
}
|
}
|
||||||
|
|
||||||
didWorldChange :: IOish m => World -> GhcModT m Bool
|
didWorldChange :: IOish m => World -> GhcModT m Bool
|
||||||
|
Loading…
Reference in New Issue
Block a user