-- |Main function combinators for connecting to Neovim over a socket.
module Ribosome.Socket where

import Ribosome.Host.Data.BootError (BootError (BootError))
import Ribosome.Host.Data.NvimSocket (NvimSocket)
import Ribosome.Host.Interpreter.Handlers (interpretHandlersNull)
import Ribosome.Host.Interpreter.Process.Socket (interpretProcessCerealSocket)
import Ribosome.Host.Run (RpcDeps, RpcStack, interpretRpcStack)
import Ribosome.IOStack (BasicPluginStack)
import Ribosome.Interpreter.Scratch (interpretScratch)
import Ribosome.Interpreter.Settings (interpretSettingsRpc)
import Ribosome.Interpreter.UserError (interpretUserErrorPrefixed)
import Ribosome.Interpreter.VariableWatcher (interpretVariableWatcherNull)
import Ribosome.Run (PluginEffects)

-- |The stack of plugin internals.
type SocketHandlerEffects =
  PluginEffects ++ RpcStack ++ RpcDeps

-- |The complete stack of a Neovim plugin.
type PluginSocketStack c =
  SocketHandlerEffects ++ Reader NvimSocket : BasicPluginStack c

-- |Run plugin internals without IO effects.
interpretPluginSocket ::
  Members (BasicPluginStack c) r =>
  Member (Reader NvimSocket) r =>
  InterpretersFor SocketHandlerEffects r
interpretPluginSocket :: forall c (r :: EffectRow).
(Members (BasicPluginStack c) r, Member (Reader NvimSocket) r) =>
InterpretersFor SocketHandlerEffects r
interpretPluginSocket =
  Sem (UserError : r) a -> Sem r a
forall (r :: EffectRow).
Member (Reader PluginName) r =>
InterpreterFor UserError r
interpretUserErrorPrefixed (Sem (UserError : r) a -> Sem r a)
-> (Sem
      ((Scratch !! RpcError)
         : (Settings !! SettingError) : (VariableWatcher !! Report)
         : (Handlers !! Report) : Log : DataLog LogReport
         : (Rpc !! RpcError)
         : Resumable RpcError (Responses RequestId Response)
         : Events (OutChan Event) Event
         : PScoped () (EventChan Event) (Consume Event) : Reports
         : Process RpcMessage (Either Text RpcMessage) : UserError : r)
      a
    -> Sem (UserError : r) a)
-> Sem
     ((Scratch !! RpcError)
        : (Settings !! SettingError) : (VariableWatcher !! Report)
        : (Handlers !! Report) : Log : DataLog LogReport
        : (Rpc !! RpcError)
        : Resumable RpcError (Responses RequestId Response)
        : Events (OutChan Event) Event
        : PScoped () (EventChan Event) (Consume Event) : Reports
        : Process RpcMessage (Either Text RpcMessage) : UserError : r)
     a
-> Sem r a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  ProcessOptions
-> InterpreterFor
     (Resumable
        ProcessError (Process RpcMessage (Either Text RpcMessage)))
     (UserError : r)
forall a (r :: EffectRow).
(Serialize a,
 Members
   '[Reader NvimSocket, Error BootError, Log, Resource, Race, Async,
     Embed IO]
   r) =>
ProcessOptions
-> InterpreterFor (Process a (Either Text a) !! ProcessError) r
interpretProcessCerealSocket ProcessOptions
forall a. Default a => a
def (Sem
   (Resumable
      ProcessError (Process RpcMessage (Either Text RpcMessage))
      : UserError : r)
   a
 -> Sem (UserError : r) a)
-> (Sem
      ((Scratch !! RpcError)
         : (Settings !! SettingError) : (VariableWatcher !! Report)
         : (Handlers !! Report) : Log : DataLog LogReport
         : (Rpc !! RpcError)
         : Resumable RpcError (Responses RequestId Response)
         : Events (OutChan Event) Event
         : PScoped () (EventChan Event) (Consume Event) : Reports
         : Process RpcMessage (Either Text RpcMessage) : UserError : r)
      a
    -> Sem
         (Resumable
            ProcessError (Process RpcMessage (Either Text RpcMessage))
            : UserError : r)
         a)
-> Sem
     ((Scratch !! RpcError)
        : (Settings !! SettingError) : (VariableWatcher !! Report)
        : (Handlers !! Report) : Log : DataLog LogReport
        : (Rpc !! RpcError)
        : Resumable RpcError (Responses RequestId Response)
        : Events (OutChan Event) Event
        : PScoped () (EventChan Event) (Consume Event) : Reports
        : Process RpcMessage (Either Text RpcMessage) : UserError : r)
     a
-> Sem (UserError : r) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  (ProcessError -> BootError)
-> Sem
     (Process RpcMessage (Either Text RpcMessage)
        : Resumable
            ProcessError (Process RpcMessage (Either Text RpcMessage))
        : UserError : r)
     a
-> Sem
     (Resumable
        ProcessError (Process RpcMessage (Either Text RpcMessage))
        : UserError : r)
     a
forall err (eff :: (* -> *) -> * -> *) err' (r :: EffectRow) a.
Members '[Resumable err eff, Error err'] r =>
(err -> err') -> Sem (eff : r) a -> Sem r a
resumeHoistError (Text -> BootError
BootError (Text -> BootError)
-> (ProcessError -> Text) -> ProcessError -> BootError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b a. (Show a, IsString b) => a -> b
show @Text) (Sem
   (Process RpcMessage (Either Text RpcMessage)
      : Resumable
          ProcessError (Process RpcMessage (Either Text RpcMessage))
      : UserError : r)
   a
 -> Sem
      (Resumable
         ProcessError (Process RpcMessage (Either Text RpcMessage))
         : UserError : r)
      a)
-> (Sem
      ((Scratch !! RpcError)
         : (Settings !! SettingError) : (VariableWatcher !! Report)
         : (Handlers !! Report) : Log : DataLog LogReport
         : (Rpc !! RpcError)
         : Resumable RpcError (Responses RequestId Response)
         : Events (OutChan Event) Event
         : PScoped () (EventChan Event) (Consume Event) : Reports
         : Process RpcMessage (Either Text RpcMessage) : UserError : r)
      a
    -> Sem
         (Process RpcMessage (Either Text RpcMessage)
            : Resumable
                ProcessError (Process RpcMessage (Either Text RpcMessage))
            : UserError : r)
         a)
-> Sem
     ((Scratch !! RpcError)
        : (Settings !! SettingError) : (VariableWatcher !! Report)
        : (Handlers !! Report) : Log : DataLog LogReport
        : (Rpc !! RpcError)
        : Resumable RpcError (Responses RequestId Response)
        : Events (OutChan Event) Event
        : PScoped () (EventChan Event) (Consume Event) : Reports
        : Process RpcMessage (Either Text RpcMessage) : UserError : r)
     a
-> Sem
     (Resumable
        ProcessError (Process RpcMessage (Either Text RpcMessage))
        : UserError : r)
     a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  Sem (Process RpcMessage (Either Text RpcMessage) : UserError : r) a
-> Sem
     (Process RpcMessage (Either Text RpcMessage)
        : Resumable
            ProcessError (Process RpcMessage (Either Text RpcMessage))
        : UserError : r)
     a
forall (e2 :: (* -> *) -> * -> *) (e1 :: (* -> *) -> * -> *)
       (r :: EffectRow) a.
Sem (e1 : r) a -> Sem (e1 : e2 : r) a
raiseUnder (Sem
   (Process RpcMessage (Either Text RpcMessage) : UserError : r) a
 -> Sem
      (Process RpcMessage (Either Text RpcMessage)
         : Resumable
             ProcessError (Process RpcMessage (Either Text RpcMessage))
         : UserError : r)
      a)
-> (Sem
      ((Scratch !! RpcError)
         : (Settings !! SettingError) : (VariableWatcher !! Report)
         : (Handlers !! Report) : Log : DataLog LogReport
         : (Rpc !! RpcError)
         : Resumable RpcError (Responses RequestId Response)
         : Events (OutChan Event) Event
         : PScoped () (EventChan Event) (Consume Event) : Reports
         : Process RpcMessage (Either Text RpcMessage) : UserError : r)
      a
    -> Sem
         (Process RpcMessage (Either Text RpcMessage) : UserError : r) a)
-> Sem
     ((Scratch !! RpcError)
        : (Settings !! SettingError) : (VariableWatcher !! Report)
        : (Handlers !! Report) : Log : DataLog LogReport
        : (Rpc !! RpcError)
        : Resumable RpcError (Responses RequestId Response)
        : Events (OutChan Event) Event
        : PScoped () (EventChan Event) (Consume Event) : Reports
        : Process RpcMessage (Either Text RpcMessage) : UserError : r)
     a
-> Sem
     (Process RpcMessage (Either Text RpcMessage)
        : Resumable
            ProcessError (Process RpcMessage (Either Text RpcMessage))
        : UserError : r)
     a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  Sem
  (Log
     : DataLog LogReport : (Rpc !! RpcError)
     : Resumable RpcError (Responses RequestId Response)
     : Events (OutChan Event) Event
     : PScoped () (EventChan Event) (Consume Event) : Reports
     : Process RpcMessage (Either Text RpcMessage) : UserError : r)
  a
-> Sem
     (Process RpcMessage (Either Text RpcMessage) : UserError : r) a
forall (r :: EffectRow).
(Members IOStack r, Members RpcDeps r,
 Members '[Log, Reader LogConfig] r) =>
InterpretersFor RpcStack r
interpretRpcStack (Sem
   (Log
      : DataLog LogReport : (Rpc !! RpcError)
      : Resumable RpcError (Responses RequestId Response)
      : Events (OutChan Event) Event
      : PScoped () (EventChan Event) (Consume Event) : Reports
      : Process RpcMessage (Either Text RpcMessage) : UserError : r)
   a
 -> Sem
      (Process RpcMessage (Either Text RpcMessage) : UserError : r) a)
-> (Sem
      ((Scratch !! RpcError)
         : (Settings !! SettingError) : (VariableWatcher !! Report)
         : (Handlers !! Report) : Log : DataLog LogReport
         : (Rpc !! RpcError)
         : Resumable RpcError (Responses RequestId Response)
         : Events (OutChan Event) Event
         : PScoped () (EventChan Event) (Consume Event) : Reports
         : Process RpcMessage (Either Text RpcMessage) : UserError : r)
      a
    -> Sem
         (Log
            : DataLog LogReport : (Rpc !! RpcError)
            : Resumable RpcError (Responses RequestId Response)
            : Events (OutChan Event) Event
            : PScoped () (EventChan Event) (Consume Event) : Reports
            : Process RpcMessage (Either Text RpcMessage) : UserError : r)
         a)
-> Sem
     ((Scratch !! RpcError)
        : (Settings !! SettingError) : (VariableWatcher !! Report)
        : (Handlers !! Report) : Log : DataLog LogReport
        : (Rpc !! RpcError)
        : Resumable RpcError (Responses RequestId Response)
        : Events (OutChan Event) Event
        : PScoped () (EventChan Event) (Consume Event) : Reports
        : Process RpcMessage (Either Text RpcMessage) : UserError : r)
     a
-> Sem
     (Process RpcMessage (Either Text RpcMessage) : UserError : r) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  Sem
  ((Handlers !! Report)
     : Log : DataLog LogReport : (Rpc !! RpcError)
     : Resumable RpcError (Responses RequestId Response)
     : Events (OutChan Event) Event
     : PScoped () (EventChan Event) (Consume Event) : Reports
     : Process RpcMessage (Either Text RpcMessage) : UserError : r)
  a
-> Sem
     (Log
        : DataLog LogReport : (Rpc !! RpcError)
        : Resumable RpcError (Responses RequestId Response)
        : Events (OutChan Event) Event
        : PScoped () (EventChan Event) (Consume Event) : Reports
        : Process RpcMessage (Either Text RpcMessage) : UserError : r)
     a
forall (r :: EffectRow). InterpreterFor (Handlers !! Report) r
interpretHandlersNull (Sem
   ((Handlers !! Report)
      : Log : DataLog LogReport : (Rpc !! RpcError)
      : Resumable RpcError (Responses RequestId Response)
      : Events (OutChan Event) Event
      : PScoped () (EventChan Event) (Consume Event) : Reports
      : Process RpcMessage (Either Text RpcMessage) : UserError : r)
   a
 -> Sem
      (Log
         : DataLog LogReport : (Rpc !! RpcError)
         : Resumable RpcError (Responses RequestId Response)
         : Events (OutChan Event) Event
         : PScoped () (EventChan Event) (Consume Event) : Reports
         : Process RpcMessage (Either Text RpcMessage) : UserError : r)
      a)
-> (Sem
      ((Scratch !! RpcError)
         : (Settings !! SettingError) : (VariableWatcher !! Report)
         : (Handlers !! Report) : Log : DataLog LogReport
         : (Rpc !! RpcError)
         : Resumable RpcError (Responses RequestId Response)
         : Events (OutChan Event) Event
         : PScoped () (EventChan Event) (Consume Event) : Reports
         : Process RpcMessage (Either Text RpcMessage) : UserError : r)
      a
    -> Sem
         ((Handlers !! Report)
            : Log : DataLog LogReport : (Rpc !! RpcError)
            : Resumable RpcError (Responses RequestId Response)
            : Events (OutChan Event) Event
            : PScoped () (EventChan Event) (Consume Event) : Reports
            : Process RpcMessage (Either Text RpcMessage) : UserError : r)
         a)
-> Sem
     ((Scratch !! RpcError)
        : (Settings !! SettingError) : (VariableWatcher !! Report)
        : (Handlers !! Report) : Log : DataLog LogReport
        : (Rpc !! RpcError)
        : Resumable RpcError (Responses RequestId Response)
        : Events (OutChan Event) Event
        : PScoped () (EventChan Event) (Consume Event) : Reports
        : Process RpcMessage (Either Text RpcMessage) : UserError : r)
     a
-> Sem
     (Log
        : DataLog LogReport : (Rpc !! RpcError)
        : Resumable RpcError (Responses RequestId Response)
        : Events (OutChan Event) Event
        : PScoped () (EventChan Event) (Consume Event) : Reports
        : Process RpcMessage (Either Text RpcMessage) : UserError : r)
     a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  Sem
  ((VariableWatcher !! Report)
     : (Handlers !! Report) : Log : DataLog LogReport
     : (Rpc !! RpcError)
     : Resumable RpcError (Responses RequestId Response)
     : Events (OutChan Event) Event
     : PScoped () (EventChan Event) (Consume Event) : Reports
     : Process RpcMessage (Either Text RpcMessage) : UserError : r)
  a
-> Sem
     ((Handlers !! Report)
        : Log : DataLog LogReport : (Rpc !! RpcError)
        : Resumable RpcError (Responses RequestId Response)
        : Events (OutChan Event) Event
        : PScoped () (EventChan Event) (Consume Event) : Reports
        : Process RpcMessage (Either Text RpcMessage) : UserError : r)
     a
forall (r :: EffectRow).
InterpreterFor (VariableWatcher !! Report) r
interpretVariableWatcherNull (Sem
   ((VariableWatcher !! Report)
      : (Handlers !! Report) : Log : DataLog LogReport
      : (Rpc !! RpcError)
      : Resumable RpcError (Responses RequestId Response)
      : Events (OutChan Event) Event
      : PScoped () (EventChan Event) (Consume Event) : Reports
      : Process RpcMessage (Either Text RpcMessage) : UserError : r)
   a
 -> Sem
      ((Handlers !! Report)
         : Log : DataLog LogReport : (Rpc !! RpcError)
         : Resumable RpcError (Responses RequestId Response)
         : Events (OutChan Event) Event
         : PScoped () (EventChan Event) (Consume Event) : Reports
         : Process RpcMessage (Either Text RpcMessage) : UserError : r)
      a)
-> (Sem
      ((Scratch !! RpcError)
         : (Settings !! SettingError) : (VariableWatcher !! Report)
         : (Handlers !! Report) : Log : DataLog LogReport
         : (Rpc !! RpcError)
         : Resumable RpcError (Responses RequestId Response)
         : Events (OutChan Event) Event
         : PScoped () (EventChan Event) (Consume Event) : Reports
         : Process RpcMessage (Either Text RpcMessage) : UserError : r)
      a
    -> Sem
         ((VariableWatcher !! Report)
            : (Handlers !! Report) : Log : DataLog LogReport
            : (Rpc !! RpcError)
            : Resumable RpcError (Responses RequestId Response)
            : Events (OutChan Event) Event
            : PScoped () (EventChan Event) (Consume Event) : Reports
            : Process RpcMessage (Either Text RpcMessage) : UserError : r)
         a)
-> Sem
     ((Scratch !! RpcError)
        : (Settings !! SettingError) : (VariableWatcher !! Report)
        : (Handlers !! Report) : Log : DataLog LogReport
        : (Rpc !! RpcError)
        : Resumable RpcError (Responses RequestId Response)
        : Events (OutChan Event) Event
        : PScoped () (EventChan Event) (Consume Event) : Reports
        : Process RpcMessage (Either Text RpcMessage) : UserError : r)
     a
-> Sem
     ((Handlers !! Report)
        : Log : DataLog LogReport : (Rpc !! RpcError)
        : Resumable RpcError (Responses RequestId Response)
        : Events (OutChan Event) Event
        : PScoped () (EventChan Event) (Consume Event) : Reports
        : Process RpcMessage (Either Text RpcMessage) : UserError : r)
     a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  Sem
  ((Settings !! SettingError)
     : (VariableWatcher !! Report) : (Handlers !! Report) : Log
     : DataLog LogReport : (Rpc !! RpcError)
     : Resumable RpcError (Responses RequestId Response)
     : Events (OutChan Event) Event
     : PScoped () (EventChan Event) (Consume Event) : Reports
     : Process RpcMessage (Either Text RpcMessage) : UserError : r)
  a
-> Sem
     ((VariableWatcher !! Report)
        : (Handlers !! Report) : Log : DataLog LogReport
        : (Rpc !! RpcError)
        : Resumable RpcError (Responses RequestId Response)
        : Events (OutChan Event) Event
        : PScoped () (EventChan Event) (Consume Event) : Reports
        : Process RpcMessage (Either Text RpcMessage) : UserError : r)
     a
forall (r :: EffectRow).
Members '[Rpc !! RpcError, Reader PluginName] r =>
InterpreterFor (Settings !! SettingError) r
interpretSettingsRpc (Sem
   ((Settings !! SettingError)
      : (VariableWatcher !! Report) : (Handlers !! Report) : Log
      : DataLog LogReport : (Rpc !! RpcError)
      : Resumable RpcError (Responses RequestId Response)
      : Events (OutChan Event) Event
      : PScoped () (EventChan Event) (Consume Event) : Reports
      : Process RpcMessage (Either Text RpcMessage) : UserError : r)
   a
 -> Sem
      ((VariableWatcher !! Report)
         : (Handlers !! Report) : Log : DataLog LogReport
         : (Rpc !! RpcError)
         : Resumable RpcError (Responses RequestId Response)
         : Events (OutChan Event) Event
         : PScoped () (EventChan Event) (Consume Event) : Reports
         : Process RpcMessage (Either Text RpcMessage) : UserError : r)
      a)
-> (Sem
      ((Scratch !! RpcError)
         : (Settings !! SettingError) : (VariableWatcher !! Report)
         : (Handlers !! Report) : Log : DataLog LogReport
         : (Rpc !! RpcError)
         : Resumable RpcError (Responses RequestId Response)
         : Events (OutChan Event) Event
         : PScoped () (EventChan Event) (Consume Event) : Reports
         : Process RpcMessage (Either Text RpcMessage) : UserError : r)
      a
    -> Sem
         ((Settings !! SettingError)
            : (VariableWatcher !! Report) : (Handlers !! Report) : Log
            : DataLog LogReport : (Rpc !! RpcError)
            : Resumable RpcError (Responses RequestId Response)
            : Events (OutChan Event) Event
            : PScoped () (EventChan Event) (Consume Event) : Reports
            : Process RpcMessage (Either Text RpcMessage) : UserError : r)
         a)
-> Sem
     ((Scratch !! RpcError)
        : (Settings !! SettingError) : (VariableWatcher !! Report)
        : (Handlers !! Report) : Log : DataLog LogReport
        : (Rpc !! RpcError)
        : Resumable RpcError (Responses RequestId Response)
        : Events (OutChan Event) Event
        : PScoped () (EventChan Event) (Consume Event) : Reports
        : Process RpcMessage (Either Text RpcMessage) : UserError : r)
     a
-> Sem
     ((VariableWatcher !! Report)
        : (Handlers !! Report) : Log : DataLog LogReport
        : (Rpc !! RpcError)
        : Resumable RpcError (Responses RequestId Response)
        : Events (OutChan Event) Event
        : PScoped () (EventChan Event) (Consume Event) : Reports
        : Process RpcMessage (Either Text RpcMessage) : UserError : r)
     a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  Sem
  ((Scratch !! RpcError)
     : (Settings !! SettingError) : (VariableWatcher !! Report)
     : (Handlers !! Report) : Log : DataLog LogReport
     : (Rpc !! RpcError)
     : Resumable RpcError (Responses RequestId Response)
     : Events (OutChan Event) Event
     : PScoped () (EventChan Event) (Consume Event) : Reports
     : Process RpcMessage (Either Text RpcMessage) : UserError : r)
  a
-> Sem
     ((Settings !! SettingError)
        : (VariableWatcher !! Report) : (Handlers !! Report) : Log
        : DataLog LogReport : (Rpc !! RpcError)
        : Resumable RpcError (Responses RequestId Response)
        : Events (OutChan Event) Event
        : PScoped () (EventChan Event) (Consume Event) : Reports
        : Process RpcMessage (Either Text RpcMessage) : UserError : r)
     a
forall (r :: EffectRow).
Members
  '[Rpc !! RpcError, Reader PluginName, Log, Resource, Embed IO] r =>
InterpreterFor (Scratch !! RpcError) r
interpretScratch