{-# options_haddock prune, hide #-}

-- |An example for the docs.
module Ribosome.Examples.Example1 where

import Ribosome
import Ribosome.Api

count ::
  Member (Rpc !! RpcError) r =>
  Int ->
  Handler r Int
count :: forall (r :: [(* -> *) -> * -> *]).
Member (Resumable RpcError Rpc) r =>
Int -> Handler r Int
count Int
n = do
  Int
s <- Int
0 Int -> Sem (Rpc : Stop Report : r) Int -> Handler r Int
forall err (eff :: (* -> *) -> * -> *) (r :: [(* -> *) -> * -> *])
       a.
Member (Resumable err eff) r =>
a -> Sem (eff : r) a -> Sem r a
<! Text -> Sem (Rpc : Stop Report : r) Int
forall a (r :: [(* -> *) -> * -> *]).
(Member Rpc r, MsgpackDecode a) =>
Text -> Sem r a
nvimGetVar Text
"counter"
  let s' :: Int
s' = Int
s Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n
  Sem (Rpc : Stop Report : r) () -> Sem (Stop Report : r) ()
forall (r :: [(* -> *) -> * -> *]) a.
Member (Resumable RpcError Rpc) r =>
Sem (Rpc : r) a -> Sem r ()
ignoreRpcError (Text -> Int -> Sem (Rpc : Stop Report : r) ()
forall p_1 (r :: [(* -> *) -> * -> *]).
(Member Rpc r, MsgpackEncode p_1) =>
Text -> p_1 -> Sem r ()
nvimSetVar Text
"counter" Int
s')
  pure Int
s'

main :: IO ()
main :: IO ()
main =
  PluginConfig () -> [RpcHandler (RemoteStack ())] -> IO ()
runNvimPluginIO_ PluginConfig ()
"counter" [RpcName
-> Execution
-> (Int
    -> Handler
         '[Resumable RpcError Scratch, Resumable SettingError Settings,
           Resumable Report VariableWatcher, Resumable Report Handlers, Log,
           DataLog LogReport, Resumable RpcError Rpc,
           Resumable RpcError (Responses RequestId Response),
           Events (OutChan Event) Event,
           PScoped () (EventChan Event) (Consume Event), Reports,
           Process RpcMessage (Either Text RpcMessage), UserError,
           Reader PluginName, Reader (CustomConfig ()), Log,
           Tagged "stderr" Log, Tagged "file" Log, Reader LogConfig,
           Reader HostConfig, Time Time Date, Error BootError,
           UninterruptibleMaskIO, UninterruptibleMaskIO, GatesIO, Race, Async,
           Resource, Embed IO, Final IO]
         Int)
-> RpcHandler
     '[Resumable RpcError Scratch, Resumable SettingError Settings,
       Resumable Report VariableWatcher, Resumable Report Handlers, Log,
       DataLog LogReport, Resumable RpcError Rpc,
       Resumable RpcError (Responses RequestId Response),
       Events (OutChan Event) Event,
       PScoped () (EventChan Event) (Consume Event), Reports,
       Process RpcMessage (Either Text RpcMessage), UserError,
       Reader PluginName, Reader (CustomConfig ()), Log,
       Tagged "stderr" Log, Tagged "file" Log, Reader LogConfig,
       Reader HostConfig, Time Time Date, Error BootError,
       UninterruptibleMaskIO, UninterruptibleMaskIO, GatesIO, Race, Async,
       Resource, Embed IO, Final IO]
forall (r :: [(* -> *) -> * -> *]) h.
HandlerCodec h r =>
RpcName -> Execution -> h -> RpcHandler r
rpcFunction RpcName
"Count" Execution
Sync Int
-> Handler
     '[Resumable RpcError Scratch, Resumable SettingError Settings,
       Resumable Report VariableWatcher, Resumable Report Handlers, Log,
       DataLog LogReport, Resumable RpcError Rpc,
       Resumable RpcError (Responses RequestId Response),
       Events (OutChan Event) Event,
       PScoped () (EventChan Event) (Consume Event), Reports,
       Process RpcMessage (Either Text RpcMessage), UserError,
       Reader PluginName, Reader (CustomConfig ()), Log,
       Tagged "stderr" Log, Tagged "file" Log, Reader LogConfig,
       Reader HostConfig, Time Time Date, Error BootError,
       UninterruptibleMaskIO, UninterruptibleMaskIO, GatesIO, Race, Async,
       Resource, Embed IO, Final IO]
     Int
forall (r :: [(* -> *) -> * -> *]).
Member (Resumable RpcError Rpc) r =>
Int -> Handler r Int
count]