<commit_before>{-# LANGUAGE DeriveDataTypeable        #-}
{-# LANGUAGE ExistentialQuantification #-}
{- |
Module      :  Neovim.API.IPC
Description :  Communication between Haskell processes/threads
Copyright   :  (c) <NAME>
License     :  Apache-2.0

Maintainer  :  <EMAIL>
Stability   :  experimental

-}
module Neovim.API.IPC (
    SomeMessage(..),
    RPCMessage(..),
    Request(..),
    fromMessage,

    module Data.Int,
    ) where

import           Control.Concurrent.STM
import           Data.MessagePack
import           Data.Text              as Text
import           Data.Time
import           Data.Typeable          (Typeable, cast)
import           Data.Int               (Int64)


-- | Taken from xmonad and based on ideas in /An Extensible Dynamically-Typed
-- Hierarchy of Exceptions/, <NAME>, 2006.
--
-- User-extensible messages must be a member of this class.
data SomeMessage = forall msg. Message msg => SomeMessage msg

class Typeable message => Message message where
    fromMessage :: (Message message) => SomeMessage -> Maybe message
    fromMessage (SomeMessage message) = cast message

data RPCMessage = FunctionCall Text [Object] (TMVar (Either Object Object)) UTCTime
                -- ^ Method name, parameters, callback, timestamp
                | Response !Int64 Object Object
                -- ^ Responese sent to indicate the result of a function call.
                --
                -- * identfier of the message as 'Word32'
                -- * Error value
                -- * Result value
    deriving (Typeable)

instance Message RPCMessage

data Request = Request
    { reqMethod :: Text
    , reqId     :: !Int64
    , reqArgs   :: [Object]
    }
    deriving (Typeable)

instance Message Request
<commit_msg>Remove `Message message` constraint from `fromMessage`<commit_after>{-# LANGUAGE DeriveDataTypeable        #-}
{-# LANGUAGE ExistentialQuantification #-}
{- |
Module      :  Neovim.API.IPC
Description :  Communication between Haskell processes/threads
Copyright   :  (c) <NAME>
License     :  Apache-2.0

Maintainer  :  <EMAIL>
Stability   :  experimental

-}
module Neovim.API.IPC (
    SomeMessage(..),
    RPCMessage(..),
    Request(..),
    fromMessage,

    module Data.Int,
    ) where

import           Control.Concurrent.STM
import           Data.MessagePack
import           Data.Text              as Text
import           Data.Time
import           Data.Typeable          (Typeable, cast)
import           Data.Int               (Int64)


-- | Taken from xmonad and based on ideas in /An Extensible Dynamically-Typed
-- Hierarchy of Exceptions/, <NAME>, 2006.
--
-- User-extensible messages must be a member of this class.
data SomeMessage = forall msg. Message msg => SomeMessage msg

class Typeable message => Message message where
    fromMessage :: SomeMessage -> Maybe message
    fromMessage (SomeMessage message) = cast message

data RPCMessage = FunctionCall Text [Object] (TMVar (Either Object Object)) UTCTime
                -- ^ Method name, parameters, callback, timestamp
                | Response !Int64 Object Object
                -- ^ Responese sent to indicate the result of a function call.
                --
                -- * identfier of the message as 'Word32'
                -- * Error value
                -- * Result value
    deriving (Typeable)

instance Message RPCMessage

data Request = Request
    { reqMethod :: Text
    , reqId     :: !Int64
    , reqArgs   :: [Object]
    }
    deriving (Typeable)

instance Message Request

{'fraction_non_alphanumeric': 0.08875070661390616, 'fraction_numerical': 0.00791407574901074, 'mean_word_length': 2.1180616740088105, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4118853', 'n_tokens_mistral': 1004, 'n_tokens_neox': 957, 'n_words': 313}