-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A haskell package to build your own Language Server client.
--   
--   This package is intended for developers of text editors who want to
--   make their text editor compatible with the <a>Language Server
--   Protocol</a>. I have developed this package with plans to integrate it
--   in the <a>Yi Editor</a>.
@package haskell-lsp-client
@version 1.0.0.0


-- | This module contains an implementation of a client for the <a>Language
--   Server Protocol</a>. It uses the same data types as the
--   <a>haskell-lsp</a> library.
--   
--   This client is intended to be used by text editors written in haskell
--   to provide the user with IDE-like features.
--   
--   This module is intended to be imported qualified:
--   
--   <pre>
--   import qualified LSP.Client as Client
--   </pre>
--   
--   In the examples in this module it is assumed that the following
--   modules are imported:
--   
--   <pre>
--   import qualified Language.Haskell.LSP.TH.DataTypesJSON as LSP
--   </pre>
--   
--   A complete example can be found in the github repository.
--   
--   TODO:
--   
--   <ul>
--   <li>Implement proper exception handling.</li>
--   </ul>
module LSP.Client

-- | Start the language server.
--   
--   Example:
--   
--   <pre>
--   reqVar &lt;- Client.start myConfig
--   </pre>
--   
--   Where <tt>inp</tt> and <tt>out</tt> are the <a>Handle</a>s of the lsp
--   client and <tt>testHandleNotification</tt> and
--   <tt>testHandleRequestMessage</tt> are
--   <a>NotificationMessageHandler</a> and <a>RequestMessageHandler</a>
--   respectively. <tt>reqVar</tt> can be passed to the
--   <a>sendClientRequest</a> and <a>sendClientNotification</a> functions.
start :: Config -> IO (MVar ClientMessage)

-- | The configuration of the Language Server Protocol client.
--   <a>toServer</a> and <a>fromServer</a> are the <a>Handle</a>s which can
--   be used to send messages to and receive messages from the server.
--   
--   Create this configuration and pass it to the <a>start</a> function.
--   
--   Example:
--   
--   <pre>
--   (Just inp, Just out, _, _) &lt;- createProcess (proc "hie" ["--lsp"])
--     {std_in = CreatePipe, std_out = CreatePipe, std_err = CreatePipe}
--   let myConfig = Config inp out testHandleNotificationMessage testHandleRequestMessage
--   </pre>
--   
--   This example will run <tt>hie --lsp</tt> and combine the <tt>inp</tt>
--   and <tt>out</tt> <a>Handle</a>s with the
--   <tt>testHandleNotificationMessage</tt> and
--   <tt>testHandleRequestMessage</tt> handlers to form the configuration
--   of the client.
data Config
Config :: !Handle -> !Handle -> !NotificationMessageHandler -> !RequestMessageHandler -> Config
[toServer] :: Config -> !Handle
[fromServer] :: Config -> !Handle
[handleNotification] :: Config -> !NotificationMessageHandler
[handleRequest] :: Config -> !RequestMessageHandler

-- | The handlers for request messages from the server. Define these once
--   and pass them via the <a>Config</a> data type to the <a>start</a>
--   function.
--   
--   Example:
--   
--   <pre>
--   testRequestMessageHandler :: Client.RequestMessageHandler
--   testRequestMessageHandler = Client.RequestMessageHandler
--     (m -&gt; emptyResponse m &lt;$ print m)
--     (m -&gt; emptyResponse m &lt;$ print m)
--     (m -&gt; emptyResponse m &lt;$ print m)
--     (m -&gt; emptyResponse m &lt;$ print m)
--     where
--       toRspId (LSP.IdInt i) = LSP.IdRspInt i
--       toRspId (LSP.IdString t) = LSP.IdRspString t
--   
--       emptyResponse :: LSP.RequestMessage m req resp -&gt; LSP.ResponseMessage a
--       emptyResponse m = LSP.ResponseMessage (m ^. LSP.jsonrpc) (toRspId (m ^. LSP.id)) Nothing Nothing
--   </pre>
--   
--   This example will print all request messages to and send back an empty
--   response message.
data RequestMessageHandler
RequestMessageHandler :: (ShowMessageRequest -> IO ShowMessageResponse) -> (RegisterCapabilityRequest -> IO ErrorResponse) -> (UnregisterCapabilityRequest -> IO ErrorResponse) -> (ApplyWorkspaceEditRequest -> IO ApplyWorkspaceEditResponse) -> RequestMessageHandler
[handleWindowShowMessageRequest] :: RequestMessageHandler -> ShowMessageRequest -> IO ShowMessageResponse
[handleClientRegisterCapability] :: RequestMessageHandler -> RegisterCapabilityRequest -> IO ErrorResponse
[handleClientUnregisterCapability] :: RequestMessageHandler -> UnregisterCapabilityRequest -> IO ErrorResponse
[handleWorkspaceApplyEdit] :: RequestMessageHandler -> ApplyWorkspaceEditRequest -> IO ApplyWorkspaceEditResponse

-- | The handlers for notification messages from the server. Define these
--   once and pass them via the <a>Config</a> data type to the <a>start</a>
--   function.
--   
--   Example:
--   
--   <pre>
--   testNotificationMessageHandler :: Client.NotificationMessageHandler
--   testNotificationMessageHandler = Client.NotificationMessageHandler
--     (T.putStrLn . view (LSP.params . LSP.message))
--     (T.putStrLn . view (LSP.params . LSP.message))
--     (print . view LSP.params)
--     (mapM_ T.putStrLn . (^.. LSP.params . LSP.diagnostics . traverse . LSP.message))
--   </pre>
--   
--   This example will print the message content of each notification.
data NotificationMessageHandler
NotificationMessageHandler :: (ShowMessageNotification -> IO ()) -> (LogMessageNotification -> IO ()) -> (TelemetryNotification -> IO ()) -> (PublishDiagnosticsNotification -> IO ()) -> NotificationMessageHandler
[handleWindowShowMessage] :: NotificationMessageHandler -> ShowMessageNotification -> IO ()
[handleWindowLogMessage] :: NotificationMessageHandler -> LogMessageNotification -> IO ()
[handleTelemetryEvent] :: NotificationMessageHandler -> TelemetryNotification -> IO ()
[handleTextDocumentPublishDiagnostics] :: NotificationMessageHandler -> PublishDiagnosticsNotification -> IO ()

-- | Send a request message to the Language Server and wait for its
--   response.
--   
--   Example:
--   
--   <pre>
--   Client.sendClientRequest (Proxy :: Proxy LSP.InitializeRequest)
--                            reqVar
--                            LSP.Initialize
--                            initializeParams
--   </pre>
--   
--   Where <tt>reqVar</tt> is the <tt>MVar</tt> generated by the
--   <a>start</a> function and <tt>initializeParams</tt> are the parameters
--   to the initialize request as specified in the Language Server Protocol
--   and the haskell-lsp package. Note that in this case the result is
--   ignored.
sendClientRequest :: forall params resp. (ToJSON params, ToJSON resp, FromJSON resp) => Proxy (RequestMessage ClientMethod params resp) -> MVar ClientMessage -> ClientMethod -> params -> IO (Maybe (Either ResponseError resp))

-- | Send a notification message to the Language Server.
--   
--   Example:
--   
--   <pre>
--   Client.sendClientNotification reqVar LSP.Initialized (Just LSP.InitializedParams)
--   </pre>
--   
--   Where <tt>reqVar</tt> is the <tt>MVar</tt> generated by the
--   <a>start</a> function.
sendClientNotification :: forall params. (ToJSON params) => MVar ClientMessage -> ClientMethod -> params -> IO ()
instance Data.Traversable.Traversable Language.Haskell.LSP.TH.DataTypesJSON.List
instance Data.Foldable.Foldable Language.Haskell.LSP.TH.DataTypesJSON.List
