-- |Events sent from Neovim to the host.
module Ribosome.Host.Data.Event where

import Data.MessagePack (Object)

import Ribosome.Host.Class.Msgpack.Decode (MsgpackDecode)
import Ribosome.Host.Class.Msgpack.Encode (MsgpackEncode)

-- |The name of an event, which corresponds to the RPC method in the payload.
newtype EventName =
  EventName { EventName -> Text
unEventName :: Text }
  deriving stock (EventName -> EventName -> Bool
(EventName -> EventName -> Bool)
-> (EventName -> EventName -> Bool) -> Eq EventName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EventName -> EventName -> Bool
$c/= :: EventName -> EventName -> Bool
== :: EventName -> EventName -> Bool
$c== :: EventName -> EventName -> Bool
Eq, Int -> EventName -> ShowS
[EventName] -> ShowS
EventName -> String
(Int -> EventName -> ShowS)
-> (EventName -> String)
-> ([EventName] -> ShowS)
-> Show EventName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EventName] -> ShowS
$cshowList :: [EventName] -> ShowS
show :: EventName -> String
$cshow :: EventName -> String
showsPrec :: Int -> EventName -> ShowS
$cshowsPrec :: Int -> EventName -> ShowS
Show)
  deriving newtype (String -> EventName
(String -> EventName) -> IsString EventName
forall a. (String -> a) -> IsString a
fromString :: String -> EventName
$cfromString :: String -> EventName
IsString, Eq EventName
Eq EventName
-> (EventName -> EventName -> Ordering)
-> (EventName -> EventName -> Bool)
-> (EventName -> EventName -> Bool)
-> (EventName -> EventName -> Bool)
-> (EventName -> EventName -> Bool)
-> (EventName -> EventName -> EventName)
-> (EventName -> EventName -> EventName)
-> Ord EventName
EventName -> EventName -> Bool
EventName -> EventName -> Ordering
EventName -> EventName -> EventName
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: EventName -> EventName -> EventName
$cmin :: EventName -> EventName -> EventName
max :: EventName -> EventName -> EventName
$cmax :: EventName -> EventName -> EventName
>= :: EventName -> EventName -> Bool
$c>= :: EventName -> EventName -> Bool
> :: EventName -> EventName -> Bool
$c> :: EventName -> EventName -> Bool
<= :: EventName -> EventName -> Bool
$c<= :: EventName -> EventName -> Bool
< :: EventName -> EventName -> Bool
$c< :: EventName -> EventName -> Bool
compare :: EventName -> EventName -> Ordering
$ccompare :: EventName -> EventName -> Ordering
Ord, String -> Object -> Either Text EventName
Object -> Either Text EventName
(Object -> Either Text EventName)
-> (String -> Object -> Either Text EventName)
-> MsgpackDecode EventName
forall a.
(Object -> Either Text a)
-> (String -> Object -> Either Text a) -> MsgpackDecode a
missingKey :: String -> Object -> Either Text EventName
$cmissingKey :: String -> Object -> Either Text EventName
fromMsgpack :: Object -> Either Text EventName
$cfromMsgpack :: Object -> Either Text EventName
MsgpackDecode, EventName -> Object
(EventName -> Object) -> MsgpackEncode EventName
forall a. (a -> Object) -> MsgpackEncode a
toMsgpack :: EventName -> Object
$ctoMsgpack :: EventName -> Object
MsgpackEncode)

-- |An event is an RPC notification sent by Neovim that is not intended to be dispatched to a named handler, but
-- consumed in a broadcasting fashion.
--
-- Since they aren't marked as such, the host treats any notification with an unknown method name as an event.
--
-- Events can be consumed with 'Conc.Consume' and 'Conc.subscribe'.
data Event =
  Event {
    Event -> EventName
name :: EventName,
    Event -> [Object]
payload :: [Object]
  }
  deriving stock (Event -> Event -> Bool
(Event -> Event -> Bool) -> (Event -> Event -> Bool) -> Eq Event
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Event -> Event -> Bool
$c/= :: Event -> Event -> Bool
== :: Event -> Event -> Bool
$c== :: Event -> Event -> Bool
Eq, Int -> Event -> ShowS
[Event] -> ShowS
Event -> String
(Int -> Event -> ShowS)
-> (Event -> String) -> ([Event] -> ShowS) -> Show Event
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Event] -> ShowS
$cshowList :: [Event] -> ShowS
show :: Event -> String
$cshow :: Event -> String
showsPrec :: Int -> Event -> ShowS
$cshowsPrec :: Int -> Event -> ShowS
Show)