module IdeSession.State
(
Computed(..)
, IdeSession(..)
, IdeStaticInfo(..)
, IdeSessionState(..)
, LogicalTimestamp
, IdeIdleState(..)
, ManagedFilesInternal(..)
, ManagedFile
, GhcServer(..)
, RunActions(..)
, IdeCallbacks(..)
, ideLogicalTimestamp
, ideComputed
, ideGhcOpts
, ideRelativeIncludes
, ideGenerateCode
, ideManagedFiles
, ideObjectFiles
, ideBuildExeStatus
, ideBuildDocStatus
, ideBuildLicensesStatus
, ideEnv
, ideArgs
, ideGhcServer
, ideGhcVersion
, ideStdoutBufferMode
, ideStderrBufferMode
, ideBreakInfo
, ideTargets
, ideRtsOpts
, managedSource
, managedData
, ideSourceDir
, ideDataDir
, defaultIdeCallbacks
, ideLogFunc
) where
import Control.Concurrent (ThreadId)
import Data.Accessor (Accessor, accessor)
import Data.Digest.Pure.MD5 (MD5Digest)
import System.Exit (ExitCode)
import System.Posix.Types (EpochTime)
import qualified Data.ByteString as BSS
import IdeSession.Config
import IdeSession.GHC.API (GhcVersion)
import IdeSession.RPC.Client (RpcServer, RpcConversation, ExternalException)
import IdeSession.Strict.Container
import IdeSession.Strict.MVar (StrictMVar)
import IdeSession.Types.Private hiding (RunResult)
import qualified IdeSession.Types.Public as Public
import IdeSession.Util.Logger
import System.FilePath ((</>))
data Computed = Computed {
computedErrors :: !(Strict [] SourceError)
, computedLoadedModules :: !(Strict [] ModuleName)
, computedFileMap :: !(Strict (Map FilePath) ModuleId)
, computedImports :: !(Strict (Map ModuleName) (Strict [] Import))
, computedAutoMap :: !(Strict (Map ModuleName) (Strict Trie (Strict [] IdInfo)))
, computedSpanInfo :: !(Strict (Map ModuleName) IdMap)
, computedExpTypes :: !(Strict (Map ModuleName) ExpMap)
, computedUseSites :: !(Strict (Map ModuleName) UseSites)
, computedPkgDeps :: !(Strict (Map ModuleName) (Strict [] PackageId))
, computedCache :: !ExplicitSharingCache
}
deriving Show
data IdeSession = IdeSession {
ideStaticInfo :: IdeStaticInfo
, ideState :: StrictMVar IdeSessionState
, ideCallbacks :: IdeCallbacks
}
data IdeStaticInfo = IdeStaticInfo {
ideConfig :: !SessionConfig
, ideSessionDir :: !FilePath
, ideDistDir :: !FilePath
}
data IdeSessionState =
IdeSessionIdle IdeIdleState
| IdeSessionShutdown
| IdeSessionServerDied ExternalException IdeIdleState
type LogicalTimestamp = EpochTime
data IdeIdleState = IdeIdleState {
_ideLogicalTimestamp :: !LogicalTimestamp
, _ideComputed :: !(Strict Maybe Computed)
, _ideGhcOpts :: ![String]
, _ideRelativeIncludes :: ![FilePath]
, _ideGenerateCode :: !Bool
, _ideManagedFiles :: !ManagedFilesInternal
, _ideObjectFiles :: !ObjectFiles
, _ideBuildExeStatus :: !(Maybe ExitCode)
, _ideBuildDocStatus :: !(Maybe ExitCode)
, _ideBuildLicensesStatus :: !(Maybe ExitCode)
, _ideEnv :: ![(String, Maybe String)]
, _ideArgs :: ![String]
, _ideGhcServer :: GhcServer
, _ideGhcVersion :: GhcVersion
, _ideStdoutBufferMode :: !Public.RunBufferMode
, _ideStderrBufferMode :: !Public.RunBufferMode
, _ideBreakInfo :: !(Strict Maybe Public.BreakInfo)
, _ideTargets :: !Public.Targets
, _ideRtsOpts :: [String]
}
data ManagedFilesInternal = ManagedFilesInternal
{ _managedSource :: [ManagedFile]
, _managedData :: [ManagedFile]
}
type ManagedFile = (FilePath, (MD5Digest, LogicalTimestamp))
type ObjectFiles = [(FilePath, (FilePath, LogicalTimestamp))]
data GhcServer = OutProcess RpcServer
| InProcess RpcConversation ThreadId
data RunActions a = RunActions {
runWait :: IO (Either BSS.ByteString a)
, interrupt :: IO ()
, supplyStdin :: BSS.ByteString -> IO ()
, forceCancel :: IO ()
}
data IdeCallbacks = IdeCallbacks
{ ideCallbacksLogFunc :: LogFunc
}
ideLogicalTimestamp :: Accessor IdeIdleState LogicalTimestamp
ideComputed :: Accessor IdeIdleState (Strict Maybe Computed)
ideGhcOpts :: Accessor IdeIdleState [String]
ideRelativeIncludes :: Accessor IdeIdleState [FilePath]
ideGenerateCode :: Accessor IdeIdleState Bool
ideManagedFiles :: Accessor IdeIdleState ManagedFilesInternal
ideObjectFiles :: Accessor IdeIdleState ObjectFiles
ideBuildExeStatus :: Accessor IdeIdleState (Maybe ExitCode)
ideBuildDocStatus :: Accessor IdeIdleState (Maybe ExitCode)
ideBuildLicensesStatus :: Accessor IdeIdleState (Maybe ExitCode)
ideEnv :: Accessor IdeIdleState [(String, Maybe String)]
ideArgs :: Accessor IdeIdleState [String]
ideGhcServer :: Accessor IdeIdleState GhcServer
ideGhcVersion :: Accessor IdeIdleState GhcVersion
ideStdoutBufferMode :: Accessor IdeIdleState Public.RunBufferMode
ideStderrBufferMode :: Accessor IdeIdleState Public.RunBufferMode
ideBreakInfo :: Accessor IdeIdleState (Strict Maybe Public.BreakInfo)
ideTargets :: Accessor IdeIdleState Public.Targets
ideRtsOpts :: Accessor IdeIdleState [String]
ideLogicalTimestamp = accessor _ideLogicalTimestamp $ \x s -> s { _ideLogicalTimestamp = x }
ideComputed = accessor _ideComputed $ \x s -> s { _ideComputed = x }
ideGhcOpts = accessor _ideGhcOpts $ \x s -> s { _ideGhcOpts = x }
ideRelativeIncludes = accessor _ideRelativeIncludes $ \x s -> s { _ideRelativeIncludes = x }
ideGenerateCode = accessor _ideGenerateCode $ \x s -> s { _ideGenerateCode = x }
ideManagedFiles = accessor _ideManagedFiles $ \x s -> s { _ideManagedFiles = x }
ideObjectFiles = accessor _ideObjectFiles $ \x s -> s { _ideObjectFiles = x }
ideBuildExeStatus = accessor _ideBuildExeStatus $ \x s -> s { _ideBuildExeStatus = x }
ideBuildDocStatus = accessor _ideBuildDocStatus $ \x s -> s { _ideBuildDocStatus = x }
ideBuildLicensesStatus =
accessor _ideBuildLicensesStatus $ \x s -> s { _ideBuildLicensesStatus = x }
ideEnv = accessor _ideEnv $ \x s -> s { _ideEnv = x }
ideArgs = accessor _ideArgs $ \x s -> s { _ideArgs = x }
ideGhcServer = accessor _ideGhcServer $ \x s -> s { _ideGhcServer = x }
ideGhcVersion = accessor _ideGhcVersion $ \x s -> s { _ideGhcVersion = x }
ideStdoutBufferMode = accessor _ideStdoutBufferMode $ \x s -> s { _ideStdoutBufferMode = x }
ideStderrBufferMode = accessor _ideStderrBufferMode $ \x s -> s { _ideStderrBufferMode = x }
ideBreakInfo = accessor _ideBreakInfo $ \x s -> s { _ideBreakInfo = x }
ideTargets = accessor _ideTargets $ \x s -> s { _ideTargets = x }
ideRtsOpts = accessor _ideRtsOpts $ \x s -> s { _ideRtsOpts = x }
managedSource :: Accessor ManagedFilesInternal [ManagedFile]
managedData :: Accessor ManagedFilesInternal [ManagedFile]
managedSource = accessor _managedSource $ \x s -> s { _managedSource = x }
managedData = accessor _managedData $ \x s -> s { _managedData = x }
ideSourceDir :: IdeStaticInfo -> FilePath
ideSourceDir IdeStaticInfo{..} =
case configLocalWorkingDir ideConfig of
Just path -> path
Nothing -> ideSessionDir </> "src"
ideDataDir :: IdeStaticInfo -> FilePath
ideDataDir IdeStaticInfo{..} =
case configLocalWorkingDir ideConfig of
Just path -> path
Nothing -> ideSessionDir </> "data"
defaultIdeCallbacks :: IdeCallbacks
defaultIdeCallbacks = IdeCallbacks
{ ideCallbacksLogFunc = \_ _ _ _ -> return ()
}
ideLogFunc :: IdeSession -> LogFunc
ideLogFunc = ideCallbacksLogFunc . ideCallbacks