module Neovim.Debug (
debug,
debug',
develMain,
runNeovim,
runNeovim',
module Neovim,
) where
import Neovim
import Neovim.Context (runNeovim)
import qualified Neovim.Context.Internal as Internal
import Neovim.Log (disableLogger)
import Neovim.Main (CommandLineOptions (..),
runPluginProvider)
import Neovim.RPC.Common (RPCConfig)
import Control.Concurrent
import Control.Monad
import Foreign.Store
import Prelude
debug :: r -> st -> Internal.Neovim r st a -> IO (Either String (a, st))
debug r st a = disableLogger $ do
runPluginProvider def { env = True } Nothing finalizer Nothing
where
finalizer tids cfg = takeMVar (Internal.quit cfg) >>= \case
Internal.Failure e ->
return $ Left e
Internal.InitSuccess -> do
res <- Internal.runNeovim
(cfg { Internal.customConfig = r, Internal.pluginSettings = Nothing })
st
a
mapM_ killThread tids
return res
_ ->
return $ Left "Unexpected finalizer state."
debug' :: Internal.Neovim' a -> IO (Either String a)
debug' a = fmap fst <$> debug () () a
develMain :: IO (Either String ([ThreadId], Internal.Config RPCConfig ()))
develMain = lookupStore 0 >>= \case
Nothing -> do
x <- disableLogger $
runPluginProvider def { env = True } Nothing finalizer Nothing
void $ newStore x
return x
Just x ->
readStore x
where
finalizer tids cfg = takeMVar (Internal.quit cfg) >>= \case
Internal.Failure e ->
return $ Left e
Internal.InitSuccess ->
return $ Right (tids, cfg)
_ ->
return $ Left "Unexpected finalizer state for develMain."
runNeovim' :: Internal.Config r st -> Neovim' a -> IO (Either String a)
runNeovim' cfg =
fmap (fmap fst) . runNeovim (Internal.retypeConfig () () cfg) ()