{-# LANGUAGE TemplateHaskell       #-}
{-# LANGUAGE DuplicateRecordFields #-}

module Language.LSP.Types.Initialize where

import Data.Aeson
import Data.Aeson.TH
import Data.Text (Text)
import qualified Data.Text as T
import Language.LSP.Types.ClientCapabilities
import Language.LSP.Types.Common
import Language.LSP.Types.Progress
import Language.LSP.Types.ServerCapabilities
import Language.LSP.Types.Uri
import Language.LSP.Types.Utils
import Language.LSP.Types.WorkspaceFolders

data Trace = TraceOff | TraceMessages | TraceVerbose
           deriving (Int -> Trace -> ShowS
[Trace] -> ShowS
Trace -> String
(Int -> Trace -> ShowS)
-> (Trace -> String) -> ([Trace] -> ShowS) -> Show Trace
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Trace -> ShowS
showsPrec :: Int -> Trace -> ShowS
$cshow :: Trace -> String
show :: Trace -> String
$cshowList :: [Trace] -> ShowS
showList :: [Trace] -> ShowS
Show, ReadPrec [Trace]
ReadPrec Trace
Int -> ReadS Trace
ReadS [Trace]
(Int -> ReadS Trace)
-> ReadS [Trace]
-> ReadPrec Trace
-> ReadPrec [Trace]
-> Read Trace
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Trace
readsPrec :: Int -> ReadS Trace
$creadList :: ReadS [Trace]
readList :: ReadS [Trace]
$creadPrec :: ReadPrec Trace
readPrec :: ReadPrec Trace
$creadListPrec :: ReadPrec [Trace]
readListPrec :: ReadPrec [Trace]
Read, Trace -> Trace -> Bool
(Trace -> Trace -> Bool) -> (Trace -> Trace -> Bool) -> Eq Trace
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Trace -> Trace -> Bool
== :: Trace -> Trace -> Bool
$c/= :: Trace -> Trace -> Bool
/= :: Trace -> Trace -> Bool
Eq)

instance ToJSON Trace where
  toJSON :: Trace -> Value
toJSON Trace
TraceOff      = Text -> Value
String (String -> Text
T.pack String
"off")
  toJSON Trace
TraceMessages = Text -> Value
String (String -> Text
T.pack String
"messages")
  toJSON Trace
TraceVerbose  = Text -> Value
String (String -> Text
T.pack String
"verbose")

instance FromJSON Trace where
  parseJSON :: Value -> Parser Trace
parseJSON (String Text
s) = case Text -> String
T.unpack Text
s of
    String
"off"      -> Trace -> Parser Trace
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Trace
TraceOff
    String
"messages" -> Trace -> Parser Trace
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Trace
TraceMessages
    String
"verbose"  -> Trace -> Parser Trace
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Trace
TraceVerbose
    String
_          -> String -> Parser Trace
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Trace"
  parseJSON Value
_          = String -> Parser Trace
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Trace"

data ClientInfo =
  ClientInfo
  { -- | The name of the client as defined by the client.
    ClientInfo -> Text
_name    :: Text
    -- | The client's version as defined by the client.
  , ClientInfo -> Maybe Text
_version :: Maybe Text
  } deriving (Int -> ClientInfo -> ShowS
[ClientInfo] -> ShowS
ClientInfo -> String
(Int -> ClientInfo -> ShowS)
-> (ClientInfo -> String)
-> ([ClientInfo] -> ShowS)
-> Show ClientInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ClientInfo -> ShowS
showsPrec :: Int -> ClientInfo -> ShowS
$cshow :: ClientInfo -> String
show :: ClientInfo -> String
$cshowList :: [ClientInfo] -> ShowS
showList :: [ClientInfo] -> ShowS
Show, ReadPrec [ClientInfo]
ReadPrec ClientInfo
Int -> ReadS ClientInfo
ReadS [ClientInfo]
(Int -> ReadS ClientInfo)
-> ReadS [ClientInfo]
-> ReadPrec ClientInfo
-> ReadPrec [ClientInfo]
-> Read ClientInfo
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS ClientInfo
readsPrec :: Int -> ReadS ClientInfo
$creadList :: ReadS [ClientInfo]
readList :: ReadS [ClientInfo]
$creadPrec :: ReadPrec ClientInfo
readPrec :: ReadPrec ClientInfo
$creadListPrec :: ReadPrec [ClientInfo]
readListPrec :: ReadPrec [ClientInfo]
Read, ClientInfo -> ClientInfo -> Bool
(ClientInfo -> ClientInfo -> Bool)
-> (ClientInfo -> ClientInfo -> Bool) -> Eq ClientInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ClientInfo -> ClientInfo -> Bool
== :: ClientInfo -> ClientInfo -> Bool
$c/= :: ClientInfo -> ClientInfo -> Bool
/= :: ClientInfo -> ClientInfo -> Bool
Eq)
deriveJSON lspOptions ''ClientInfo

makeExtendingDatatype "InitializeParams" [''WorkDoneProgressParams]
  [ ("_processId",             [t| Maybe Int32|])
  , ("_clientInfo",            [t| Maybe ClientInfo |])
  , ("_rootPath",              [t| Maybe Text |])
  , ("_rootUri",               [t| Maybe Uri  |])
  , ("_initializationOptions", [t| Maybe Value |])
  , ("_capabilities",          [t| ClientCapabilities |])
  , ("_trace",                 [t| Maybe Trace |])
  , ("_workspaceFolders",      [t| Maybe (List WorkspaceFolder) |])
  ]

deriveJSON lspOptions ''InitializeParams

data InitializeError =
  InitializeError
    { InitializeError -> Bool
_retry :: Bool
    } deriving (ReadPrec [InitializeError]
ReadPrec InitializeError
Int -> ReadS InitializeError
ReadS [InitializeError]
(Int -> ReadS InitializeError)
-> ReadS [InitializeError]
-> ReadPrec InitializeError
-> ReadPrec [InitializeError]
-> Read InitializeError
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS InitializeError
readsPrec :: Int -> ReadS InitializeError
$creadList :: ReadS [InitializeError]
readList :: ReadS [InitializeError]
$creadPrec :: ReadPrec InitializeError
readPrec :: ReadPrec InitializeError
$creadListPrec :: ReadPrec [InitializeError]
readListPrec :: ReadPrec [InitializeError]
Read, Int -> InitializeError -> ShowS
[InitializeError] -> ShowS
InitializeError -> String
(Int -> InitializeError -> ShowS)
-> (InitializeError -> String)
-> ([InitializeError] -> ShowS)
-> Show InitializeError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InitializeError -> ShowS
showsPrec :: Int -> InitializeError -> ShowS
$cshow :: InitializeError -> String
show :: InitializeError -> String
$cshowList :: [InitializeError] -> ShowS
showList :: [InitializeError] -> ShowS
Show, InitializeError -> InitializeError -> Bool
(InitializeError -> InitializeError -> Bool)
-> (InitializeError -> InitializeError -> Bool)
-> Eq InitializeError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InitializeError -> InitializeError -> Bool
== :: InitializeError -> InitializeError -> Bool
$c/= :: InitializeError -> InitializeError -> Bool
/= :: InitializeError -> InitializeError -> Bool
Eq)

deriveJSON lspOptions ''InitializeError

data ServerInfo =
  ServerInfo
  { -- | The name of the server as defined by the server.
    ServerInfo -> Text
_name    :: Text
    -- | The server's version as defined by the server.
  , ServerInfo -> Maybe Text
_version :: Maybe Text
  } deriving (Int -> ServerInfo -> ShowS
[ServerInfo] -> ShowS
ServerInfo -> String
(Int -> ServerInfo -> ShowS)
-> (ServerInfo -> String)
-> ([ServerInfo] -> ShowS)
-> Show ServerInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ServerInfo -> ShowS
showsPrec :: Int -> ServerInfo -> ShowS
$cshow :: ServerInfo -> String
show :: ServerInfo -> String
$cshowList :: [ServerInfo] -> ShowS
showList :: [ServerInfo] -> ShowS
Show, ReadPrec [ServerInfo]
ReadPrec ServerInfo
Int -> ReadS ServerInfo
ReadS [ServerInfo]
(Int -> ReadS ServerInfo)
-> ReadS [ServerInfo]
-> ReadPrec ServerInfo
-> ReadPrec [ServerInfo]
-> Read ServerInfo
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS ServerInfo
readsPrec :: Int -> ReadS ServerInfo
$creadList :: ReadS [ServerInfo]
readList :: ReadS [ServerInfo]
$creadPrec :: ReadPrec ServerInfo
readPrec :: ReadPrec ServerInfo
$creadListPrec :: ReadPrec [ServerInfo]
readListPrec :: ReadPrec [ServerInfo]
Read, ServerInfo -> ServerInfo -> Bool
(ServerInfo -> ServerInfo -> Bool)
-> (ServerInfo -> ServerInfo -> Bool) -> Eq ServerInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ServerInfo -> ServerInfo -> Bool
== :: ServerInfo -> ServerInfo -> Bool
$c/= :: ServerInfo -> ServerInfo -> Bool
/= :: ServerInfo -> ServerInfo -> Bool
Eq)
deriveJSON lspOptions ''ServerInfo

data InitializeResult =
  InitializeResult
  { -- | The capabilities the language server provides.
    InitializeResult -> ServerCapabilities
_capabilities :: ServerCapabilities
    -- | Information about the server.
    -- Since LSP 3.15.0
  , InitializeResult -> Maybe ServerInfo
_serverInfo   :: Maybe ServerInfo
  } deriving (Int -> InitializeResult -> ShowS
[InitializeResult] -> ShowS
InitializeResult -> String
(Int -> InitializeResult -> ShowS)
-> (InitializeResult -> String)
-> ([InitializeResult] -> ShowS)
-> Show InitializeResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InitializeResult -> ShowS
showsPrec :: Int -> InitializeResult -> ShowS
$cshow :: InitializeResult -> String
show :: InitializeResult -> String
$cshowList :: [InitializeResult] -> ShowS
showList :: [InitializeResult] -> ShowS
Show, ReadPrec [InitializeResult]
ReadPrec InitializeResult
Int -> ReadS InitializeResult
ReadS [InitializeResult]
(Int -> ReadS InitializeResult)
-> ReadS [InitializeResult]
-> ReadPrec InitializeResult
-> ReadPrec [InitializeResult]
-> Read InitializeResult
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS InitializeResult
readsPrec :: Int -> ReadS InitializeResult
$creadList :: ReadS [InitializeResult]
readList :: ReadS [InitializeResult]
$creadPrec :: ReadPrec InitializeResult
readPrec :: ReadPrec InitializeResult
$creadListPrec :: ReadPrec [InitializeResult]
readListPrec :: ReadPrec [InitializeResult]
Read, InitializeResult -> InitializeResult -> Bool
(InitializeResult -> InitializeResult -> Bool)
-> (InitializeResult -> InitializeResult -> Bool)
-> Eq InitializeResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InitializeResult -> InitializeResult -> Bool
== :: InitializeResult -> InitializeResult -> Bool
$c/= :: InitializeResult -> InitializeResult -> Bool
/= :: InitializeResult -> InitializeResult -> Bool
Eq)

deriveJSON lspOptions ''InitializeResult

-- ---------------------------------------------------------------------

data InitializedParams =
  InitializedParams
  {
  } deriving (Int -> InitializedParams -> ShowS
[InitializedParams] -> ShowS
InitializedParams -> String
(Int -> InitializedParams -> ShowS)
-> (InitializedParams -> String)
-> ([InitializedParams] -> ShowS)
-> Show InitializedParams
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InitializedParams -> ShowS
showsPrec :: Int -> InitializedParams -> ShowS
$cshow :: InitializedParams -> String
show :: InitializedParams -> String
$cshowList :: [InitializedParams] -> ShowS
showList :: [InitializedParams] -> ShowS
Show, ReadPrec [InitializedParams]
ReadPrec InitializedParams
Int -> ReadS InitializedParams
ReadS [InitializedParams]
(Int -> ReadS InitializedParams)
-> ReadS [InitializedParams]
-> ReadPrec InitializedParams
-> ReadPrec [InitializedParams]
-> Read InitializedParams
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS InitializedParams
readsPrec :: Int -> ReadS InitializedParams
$creadList :: ReadS [InitializedParams]
readList :: ReadS [InitializedParams]
$creadPrec :: ReadPrec InitializedParams
readPrec :: ReadPrec InitializedParams
$creadListPrec :: ReadPrec [InitializedParams]
readListPrec :: ReadPrec [InitializedParams]
Read, InitializedParams -> InitializedParams -> Bool
(InitializedParams -> InitializedParams -> Bool)
-> (InitializedParams -> InitializedParams -> Bool)
-> Eq InitializedParams
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InitializedParams -> InitializedParams -> Bool
== :: InitializedParams -> InitializedParams -> Bool
$c/= :: InitializedParams -> InitializedParams -> Bool
/= :: InitializedParams -> InitializedParams -> Bool
Eq)

instance FromJSON InitializedParams where
  parseJSON :: Value -> Parser InitializedParams
parseJSON (Object Object
_) = InitializedParams -> Parser InitializedParams
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InitializedParams
InitializedParams
  parseJSON Value
_          = String -> Parser InitializedParams
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"InitializedParams"

instance ToJSON InitializedParams where
  toJSON :: InitializedParams -> Value
toJSON InitializedParams
InitializedParams = Object -> Value
Object Object
forall a. Monoid a => a
mempty