module Yi.Boot (yi, yiDriver, reload) where
import qualified Config.Dyre as Dyre
import qualified Config.Dyre.Options as Dyre
import qualified Config.Dyre.Params as Dyre
import Config.Dyre.Relaunch
import Control.Lens
import Data.Text ()
import System.Environment
import System.Exit
import Yi.Boot.Internal
import Yi.Buffer.Misc (BufferId(..))
import Yi.Config
import Yi.Editor
import Yi.Keymap
import Yi.Main
import Yi.Paths (getCustomConfigPath)
import Yi.Rope (fromString)
realMain :: (Config, ConsoleConfig) -> IO ()
realMain configs = restoreBinaryState Nothing >>= main configs
showErrorsInConf :: (Config, ConsoleConfig) -> String -> (Config, ConsoleConfig)
showErrorsInConf c errs = c & _1 . initialActionsA %~ (makeAction openErrBuf :)
where
openErrBuf = splitE >> newBufferE (MemBuffer "*errors*") (fromString errs)
yi :: Config -> IO ()
yi = yiDriver
yiDriver :: Config -> IO ()
yiDriver cfg = do
args <- Dyre.withDyreOptions Dyre.defaultParams getArgs
case do_args cfg args of
Left (Err err code) -> putStrLn err >> exitWith code
Right (finalCfg, cfgcon) -> do
modules <- getCustomConfigPath (userConfigDir cfgcon) "modules"
let yiParams = Dyre.defaultParams
{ Dyre.projectName = "yi"
, Dyre.realMain = realMain
, Dyre.showError = showErrorsInConf
, Dyre.configDir = Just $ userConfigDir cfgcon
, Dyre.ghcOpts = ["-threaded", "-O2", "-rtsopts"]
++ ["-i" ++ modules]
++ profilingParams
++ ghcOptions cfgcon
, Dyre.includeCurrentDirectory = False
, Dyre.rtsOptsHandling = Dyre.RTSAppend ["-I5"]
}
Dyre.wrapMain yiParams (finalCfg, cfgcon)
profilingParams :: [String]
profilingParams =
#ifdef EVENTLOG
["-eventlog", "-rtsopts"] ++
#endif
#ifdef PROFILING
["-prof", "-auto-all", "-rtsopts"
, "-osuf=p_o", "-hisuf=p_hi"] ++
#endif
[]