{-# 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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Trace] -> ShowS
$cshowList :: [Trace] -> ShowS
show :: Trace -> String
$cshow :: Trace -> String
showsPrec :: Int -> Trace -> ShowS
$cshowsPrec :: Int -> Trace -> ShowS
Show, ReadPrec [Trace]
ReadPrec Trace
Int -> ReadS Trace
ReadS [Trace]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Trace]
$creadListPrec :: ReadPrec [Trace]
readPrec :: ReadPrec Trace
$creadPrec :: ReadPrec Trace
readList :: ReadS [Trace]
$creadList :: ReadS [Trace]
readsPrec :: Int -> ReadS Trace
$creadsPrec :: Int -> ReadS Trace
Read, Trace -> Trace -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Trace -> Trace -> Bool
$c/= :: Trace -> Trace -> Bool
== :: Trace -> Trace -> Bool
$c== :: 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"      -> forall (m :: * -> *) a. Monad m => a -> m a
return Trace
TraceOff
    String
"messages" -> forall (m :: * -> *) a. Monad m => a -> m a
return Trace
TraceMessages
    String
"verbose"  -> forall (m :: * -> *) a. Monad m => a -> m a
return Trace
TraceVerbose
    String
_          -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Trace"
  parseJSON Value
_          = 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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ClientInfo] -> ShowS
$cshowList :: [ClientInfo] -> ShowS
show :: ClientInfo -> String
$cshow :: ClientInfo -> String
showsPrec :: Int -> ClientInfo -> ShowS
$cshowsPrec :: Int -> ClientInfo -> ShowS
Show, ReadPrec [ClientInfo]
ReadPrec ClientInfo
Int -> ReadS ClientInfo
ReadS [ClientInfo]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ClientInfo]
$creadListPrec :: ReadPrec [ClientInfo]
readPrec :: ReadPrec ClientInfo
$creadPrec :: ReadPrec ClientInfo
readList :: ReadS [ClientInfo]
$creadList :: ReadS [ClientInfo]
readsPrec :: Int -> ReadS ClientInfo
$creadsPrec :: Int -> ReadS ClientInfo
Read, ClientInfo -> ClientInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ClientInfo -> ClientInfo -> Bool
$c/= :: ClientInfo -> ClientInfo -> Bool
== :: ClientInfo -> ClientInfo -> Bool
$c== :: 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]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InitializeError]
$creadListPrec :: ReadPrec [InitializeError]
readPrec :: ReadPrec InitializeError
$creadPrec :: ReadPrec InitializeError
readList :: ReadS [InitializeError]
$creadList :: ReadS [InitializeError]
readsPrec :: Int -> ReadS InitializeError
$creadsPrec :: Int -> ReadS InitializeError
Read, Int -> InitializeError -> ShowS
[InitializeError] -> ShowS
InitializeError -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InitializeError] -> ShowS
$cshowList :: [InitializeError] -> ShowS
show :: InitializeError -> String
$cshow :: InitializeError -> String
showsPrec :: Int -> InitializeError -> ShowS
$cshowsPrec :: Int -> InitializeError -> ShowS
Show, InitializeError -> InitializeError -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InitializeError -> InitializeError -> Bool
$c/= :: InitializeError -> InitializeError -> Bool
== :: InitializeError -> InitializeError -> Bool
$c== :: 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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ServerInfo] -> ShowS
$cshowList :: [ServerInfo] -> ShowS
show :: ServerInfo -> String
$cshow :: ServerInfo -> String
showsPrec :: Int -> ServerInfo -> ShowS
$cshowsPrec :: Int -> ServerInfo -> ShowS
Show, ReadPrec [ServerInfo]
ReadPrec ServerInfo
Int -> ReadS ServerInfo
ReadS [ServerInfo]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ServerInfo]
$creadListPrec :: ReadPrec [ServerInfo]
readPrec :: ReadPrec ServerInfo
$creadPrec :: ReadPrec ServerInfo
readList :: ReadS [ServerInfo]
$creadList :: ReadS [ServerInfo]
readsPrec :: Int -> ReadS ServerInfo
$creadsPrec :: Int -> ReadS ServerInfo
Read, ServerInfo -> ServerInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ServerInfo -> ServerInfo -> Bool
$c/= :: ServerInfo -> ServerInfo -> Bool
== :: ServerInfo -> ServerInfo -> Bool
$c== :: 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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InitializeResult] -> ShowS
$cshowList :: [InitializeResult] -> ShowS
show :: InitializeResult -> String
$cshow :: InitializeResult -> String
showsPrec :: Int -> InitializeResult -> ShowS
$cshowsPrec :: Int -> InitializeResult -> ShowS
Show, ReadPrec [InitializeResult]
ReadPrec InitializeResult
Int -> ReadS InitializeResult
ReadS [InitializeResult]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InitializeResult]
$creadListPrec :: ReadPrec [InitializeResult]
readPrec :: ReadPrec InitializeResult
$creadPrec :: ReadPrec InitializeResult
readList :: ReadS [InitializeResult]
$creadList :: ReadS [InitializeResult]
readsPrec :: Int -> ReadS InitializeResult
$creadsPrec :: Int -> ReadS InitializeResult
Read, InitializeResult -> InitializeResult -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InitializeResult -> InitializeResult -> Bool
$c/= :: InitializeResult -> InitializeResult -> Bool
== :: InitializeResult -> InitializeResult -> Bool
$c== :: InitializeResult -> InitializeResult -> Bool
Eq)

deriveJSON lspOptions ''InitializeResult

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

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

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

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