{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}

module Language.Haskell.LSP.Messages
  ( module Language.Haskell.LSP.Types.MessageFuncs
  , FromClientMessage(..)
  , FromServerMessage(..)
  )
where

import           Language.Haskell.LSP.Types.MessageFuncs
import           Language.Haskell.LSP.Types
import           GHC.Generics
import           Data.Aeson

-- | A wrapper around a message that originates from the client
-- and is sent to the server.
data FromClientMessage = ReqInitialize               InitializeRequest
                       | ReqShutdown                 ShutdownRequest
                       | ReqHover                    HoverRequest
                       | ReqCompletion               CompletionRequest
                       | ReqCompletionItemResolve    CompletionItemResolveRequest
                       | ReqSignatureHelp            SignatureHelpRequest
                       | ReqDefinition               DefinitionRequest
                       | ReqTypeDefinition           TypeDefinitionRequest
                       | ReqImplementation           ImplementationRequest
                       | ReqFindReferences           ReferencesRequest
                       | ReqDocumentHighlights       DocumentHighlightRequest
                       | ReqDocumentSymbols          DocumentSymbolRequest
                       | ReqWorkspaceSymbols         WorkspaceSymbolRequest
                       | ReqCodeAction               CodeActionRequest
                       | ReqCodeLens                 CodeLensRequest
                       | ReqCodeLensResolve          CodeLensResolveRequest
                       | ReqDocumentLink             DocumentLinkRequest
                       | ReqDocumentLinkResolve      DocumentLinkResolveRequest
                       | ReqDocumentColor            DocumentColorRequest
                       | ReqColorPresentation        ColorPresentationRequest
                       | ReqDocumentFormatting       DocumentFormattingRequest
                       | ReqDocumentRangeFormatting  DocumentRangeFormattingRequest
                       | ReqDocumentOnTypeFormatting DocumentOnTypeFormattingRequest
                       | ReqRename                   RenameRequest
                       | ReqPrepareRename            PrepareRenameRequest
                       | ReqFoldingRange             FoldingRangeRequest
                       | ReqExecuteCommand           ExecuteCommandRequest
                       | ReqWillSaveWaitUntil        WillSaveWaitUntilTextDocumentRequest
                       -- Responses
                       | RspApplyWorkspaceEdit       ApplyWorkspaceEditResponse
                       -- TODO: Remove this and properly decode the type of responses
                       -- based on the id
                       | RspFromClient               BareResponseMessage
                       -- Notifications
                       | NotInitialized                  InitializedNotification
                       | NotExit                         ExitNotification
                       -- A cancel request notification is duplex!
                       | NotCancelRequestFromClient      CancelNotification
                       | NotDidChangeConfiguration       DidChangeConfigurationNotification
                       | NotDidOpenTextDocument          DidOpenTextDocumentNotification
                       | NotDidChangeTextDocument        DidChangeTextDocumentNotification
                       | NotDidCloseTextDocument         DidCloseTextDocumentNotification
                       | NotWillSaveTextDocument         WillSaveTextDocumentNotification
                       | NotDidSaveTextDocument          DidSaveTextDocumentNotification
                       | NotDidChangeWatchedFiles        DidChangeWatchedFilesNotification
                       | NotDidChangeWorkspaceFolders    DidChangeWorkspaceFoldersNotification
                       | NotWorkDoneProgressCancel       WorkDoneProgressCancelNotification

                       -- It is common for language servers to add custom message types so these
                       -- three constructors can be used to handle custom request, response or notification
                       -- types.
                       | ReqCustomClient                 CustomClientRequest
                       | NotCustomClient                 CustomClientNotification
  deriving (FromClientMessage -> FromClientMessage -> Bool
(FromClientMessage -> FromClientMessage -> Bool)
-> (FromClientMessage -> FromClientMessage -> Bool)
-> Eq FromClientMessage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FromClientMessage -> FromClientMessage -> Bool
$c/= :: FromClientMessage -> FromClientMessage -> Bool
== :: FromClientMessage -> FromClientMessage -> Bool
$c== :: FromClientMessage -> FromClientMessage -> Bool
Eq,ReadPrec [FromClientMessage]
ReadPrec FromClientMessage
Int -> ReadS FromClientMessage
ReadS [FromClientMessage]
(Int -> ReadS FromClientMessage)
-> ReadS [FromClientMessage]
-> ReadPrec FromClientMessage
-> ReadPrec [FromClientMessage]
-> Read FromClientMessage
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FromClientMessage]
$creadListPrec :: ReadPrec [FromClientMessage]
readPrec :: ReadPrec FromClientMessage
$creadPrec :: ReadPrec FromClientMessage
readList :: ReadS [FromClientMessage]
$creadList :: ReadS [FromClientMessage]
readsPrec :: Int -> ReadS FromClientMessage
$creadsPrec :: Int -> ReadS FromClientMessage
Read,Int -> FromClientMessage -> ShowS
[FromClientMessage] -> ShowS
FromClientMessage -> String
(Int -> FromClientMessage -> ShowS)
-> (FromClientMessage -> String)
-> ([FromClientMessage] -> ShowS)
-> Show FromClientMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FromClientMessage] -> ShowS
$cshowList :: [FromClientMessage] -> ShowS
show :: FromClientMessage -> String
$cshow :: FromClientMessage -> String
showsPrec :: Int -> FromClientMessage -> ShowS
$cshowsPrec :: Int -> FromClientMessage -> ShowS
Show,(forall x. FromClientMessage -> Rep FromClientMessage x)
-> (forall x. Rep FromClientMessage x -> FromClientMessage)
-> Generic FromClientMessage
forall x. Rep FromClientMessage x -> FromClientMessage
forall x. FromClientMessage -> Rep FromClientMessage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FromClientMessage x -> FromClientMessage
$cfrom :: forall x. FromClientMessage -> Rep FromClientMessage x
Generic,[FromClientMessage] -> Encoding
[FromClientMessage] -> Value
FromClientMessage -> Encoding
FromClientMessage -> Value
(FromClientMessage -> Value)
-> (FromClientMessage -> Encoding)
-> ([FromClientMessage] -> Value)
-> ([FromClientMessage] -> Encoding)
-> ToJSON FromClientMessage
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [FromClientMessage] -> Encoding
$ctoEncodingList :: [FromClientMessage] -> Encoding
toJSONList :: [FromClientMessage] -> Value
$ctoJSONList :: [FromClientMessage] -> Value
toEncoding :: FromClientMessage -> Encoding
$ctoEncoding :: FromClientMessage -> Encoding
toJSON :: FromClientMessage -> Value
$ctoJSON :: FromClientMessage -> Value
ToJSON,Value -> Parser [FromClientMessage]
Value -> Parser FromClientMessage
(Value -> Parser FromClientMessage)
-> (Value -> Parser [FromClientMessage])
-> FromJSON FromClientMessage
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [FromClientMessage]
$cparseJSONList :: Value -> Parser [FromClientMessage]
parseJSON :: Value -> Parser FromClientMessage
$cparseJSON :: Value -> Parser FromClientMessage
FromJSON)

-- | A wrapper around a message that originates from the server
-- and is sent to the client.
data FromServerMessage = ReqRegisterCapability       RegisterCapabilityRequest
                       | ReqUnregisterCapability     UnregisterCapabilityRequest
                       | ReqApplyWorkspaceEdit       ApplyWorkspaceEditRequest
                       | ReqShowMessage              ShowMessageRequest
                       | ReqWorkDoneProgressCreate   WorkDoneProgressCreateRequest
                       -- Responses
                       | RspInitialize               InitializeResponse
                       | RspShutdown                 ShutdownResponse
                       | RspHover                    HoverResponse
                       | RspCompletion               CompletionResponse
                       | RspCompletionItemResolve    CompletionItemResolveResponse
                       | RspSignatureHelp            SignatureHelpResponse
                       | RspDefinition               DefinitionResponse
                       | RspTypeDefinition           TypeDefinitionResponse
                       | RspImplementation           ImplementationResponse
                       | RspFindReferences           ReferencesResponse
                       | RspDocumentHighlights       DocumentHighlightsResponse
                       | RspDocumentSymbols          DocumentSymbolsResponse
                       | RspWorkspaceSymbols         WorkspaceSymbolsResponse
                       | RspCodeAction               CodeActionResponse
                       | RspCodeLens                 CodeLensResponse
                       | RspCodeLensResolve          CodeLensResolveResponse
                       | RspDocumentLink             DocumentLinkResponse
                       | RspDocumentLinkResolve      DocumentLinkResolveResponse
                       | RspDocumentColor            DocumentColorResponse
                       | RspColorPresentation        ColorPresentationResponse
                       | RspDocumentFormatting       DocumentFormattingResponse
                       | RspDocumentRangeFormatting  DocumentRangeFormattingResponse
                       | RspDocumentOnTypeFormatting DocumentOnTypeFormattingResponse
                       | RspRename                   RenameResponse
                       | RspFoldingRange             FoldingRangeResponse
                       | RspExecuteCommand           ExecuteCommandResponse
                       | RspError                    ErrorResponse
                       | RspWillSaveWaitUntil        WillSaveWaitUntilTextDocumentResponse
                       -- Notifications
                       | NotPublishDiagnostics       PublishDiagnosticsNotification
                       | NotLogMessage               LogMessageNotification
                       | NotShowMessage              ShowMessageNotification
                       | NotWorkDoneProgressBegin    WorkDoneProgressBeginNotification
                       | NotWorkDoneProgressReport   WorkDoneProgressReportNotification
                       | NotWorkDoneProgressEnd      WorkDoneProgressEndNotification
                       | NotTelemetry                TelemetryNotification
                       -- A cancel request notification is duplex!
                       | NotCancelRequestFromServer  CancelNotificationServer

                       -- It is common for language servers to add custom message types so these
                       -- three constructors can be used to handle custom request, response or notification
                       -- types.
                       | ReqCustomServer             CustomServerRequest
                       | RspCustomServer             CustomResponse
                       | NotCustomServer             CustomServerNotification
  deriving (FromServerMessage -> FromServerMessage -> Bool
(FromServerMessage -> FromServerMessage -> Bool)
-> (FromServerMessage -> FromServerMessage -> Bool)
-> Eq FromServerMessage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FromServerMessage -> FromServerMessage -> Bool
$c/= :: FromServerMessage -> FromServerMessage -> Bool
== :: FromServerMessage -> FromServerMessage -> Bool
$c== :: FromServerMessage -> FromServerMessage -> Bool
Eq,ReadPrec [FromServerMessage]
ReadPrec FromServerMessage
Int -> ReadS FromServerMessage
ReadS [FromServerMessage]
(Int -> ReadS FromServerMessage)
-> ReadS [FromServerMessage]
-> ReadPrec FromServerMessage
-> ReadPrec [FromServerMessage]
-> Read FromServerMessage
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FromServerMessage]
$creadListPrec :: ReadPrec [FromServerMessage]
readPrec :: ReadPrec FromServerMessage
$creadPrec :: ReadPrec FromServerMessage
readList :: ReadS [FromServerMessage]
$creadList :: ReadS [FromServerMessage]
readsPrec :: Int -> ReadS FromServerMessage
$creadsPrec :: Int -> ReadS FromServerMessage
Read,Int -> FromServerMessage -> ShowS
[FromServerMessage] -> ShowS
FromServerMessage -> String
(Int -> FromServerMessage -> ShowS)
-> (FromServerMessage -> String)
-> ([FromServerMessage] -> ShowS)
-> Show FromServerMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FromServerMessage] -> ShowS
$cshowList :: [FromServerMessage] -> ShowS
show :: FromServerMessage -> String
$cshow :: FromServerMessage -> String
showsPrec :: Int -> FromServerMessage -> ShowS
$cshowsPrec :: Int -> FromServerMessage -> ShowS
Show,(forall x. FromServerMessage -> Rep FromServerMessage x)
-> (forall x. Rep FromServerMessage x -> FromServerMessage)
-> Generic FromServerMessage
forall x. Rep FromServerMessage x -> FromServerMessage
forall x. FromServerMessage -> Rep FromServerMessage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FromServerMessage x -> FromServerMessage
$cfrom :: forall x. FromServerMessage -> Rep FromServerMessage x
Generic,[FromServerMessage] -> Encoding
[FromServerMessage] -> Value
FromServerMessage -> Encoding
FromServerMessage -> Value
(FromServerMessage -> Value)
-> (FromServerMessage -> Encoding)
-> ([FromServerMessage] -> Value)
-> ([FromServerMessage] -> Encoding)
-> ToJSON FromServerMessage
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [FromServerMessage] -> Encoding
$ctoEncodingList :: [FromServerMessage] -> Encoding
toJSONList :: [FromServerMessage] -> Value
$ctoJSONList :: [FromServerMessage] -> Value
toEncoding :: FromServerMessage -> Encoding
$ctoEncoding :: FromServerMessage -> Encoding
toJSON :: FromServerMessage -> Value
$ctoJSON :: FromServerMessage -> Value
ToJSON,Value -> Parser [FromServerMessage]
Value -> Parser FromServerMessage
(Value -> Parser FromServerMessage)
-> (Value -> Parser [FromServerMessage])
-> FromJSON FromServerMessage
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [FromServerMessage]
$cparseJSONList :: Value -> Parser [FromServerMessage]
parseJSON :: Value -> Parser FromServerMessage
$cparseJSON :: Value -> Parser FromServerMessage
FromJSON)