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

module Language.LSP.Types.Rename where

import Data.Aeson
import Data.Aeson.TH
import Data.Text (Text)
import Data.Scientific (Scientific)

import Language.LSP.Types.Location
import Language.LSP.Types.TextDocument
import Language.LSP.Types.Progress
import Language.LSP.Types.Utils

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

instance ToJSON PrepareSupportDefaultBehavior where
  toJSON :: PrepareSupportDefaultBehavior -> Value
toJSON PrepareSupportDefaultBehavior
PsIdentifier  = Scientific -> Value
Number Scientific
1
  toJSON (PsUnknown Scientific
i) = Scientific -> Value
Number Scientific
i

instance FromJSON PrepareSupportDefaultBehavior where
  parseJSON :: Value -> Parser PrepareSupportDefaultBehavior
parseJSON (Number Scientific
1) = PrepareSupportDefaultBehavior
-> Parser PrepareSupportDefaultBehavior
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PrepareSupportDefaultBehavior
PsIdentifier
  parseJSON Value
_          = String -> Parser PrepareSupportDefaultBehavior
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"PrepareSupportDefaultBehavior"

data RenameClientCapabilities =
  RenameClientCapabilities
    { -- | Whether rename supports dynamic registration.
      RenameClientCapabilities -> Maybe Bool
_dynamicRegistration :: Maybe Bool
      -- | Client supports testing for validity of rename operations
      -- before execution.
      --
      -- Since LSP 3.12.0
    , RenameClientCapabilities -> Maybe Bool
_prepareSupport :: Maybe Bool
      -- | Client supports the default behavior result
      -- (`{ defaultBehavior: boolean }`).
      --
      -- The value indicates the default behavior used by the client.
      --
      -- @since 3.16.0
    , RenameClientCapabilities -> Maybe PrepareSupportDefaultBehavior
prepareSupportDefaultBehavior :: Maybe PrepareSupportDefaultBehavior
      -- | Whether the client honors the change annotations in
      -- text edits and resource operations returned via the
      -- rename request's workspace edit by for example presenting
      -- the workspace edit in the user interface and asking
      -- for confirmation.
      --
      -- @since 3.16.0
    , RenameClientCapabilities -> Maybe Bool
honorsChangeAnnotations :: Maybe Bool
    } deriving (Int -> RenameClientCapabilities -> ShowS
[RenameClientCapabilities] -> ShowS
RenameClientCapabilities -> String
(Int -> RenameClientCapabilities -> ShowS)
-> (RenameClientCapabilities -> String)
-> ([RenameClientCapabilities] -> ShowS)
-> Show RenameClientCapabilities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RenameClientCapabilities -> ShowS
showsPrec :: Int -> RenameClientCapabilities -> ShowS
$cshow :: RenameClientCapabilities -> String
show :: RenameClientCapabilities -> String
$cshowList :: [RenameClientCapabilities] -> ShowS
showList :: [RenameClientCapabilities] -> ShowS
Show, ReadPrec [RenameClientCapabilities]
ReadPrec RenameClientCapabilities
Int -> ReadS RenameClientCapabilities
ReadS [RenameClientCapabilities]
(Int -> ReadS RenameClientCapabilities)
-> ReadS [RenameClientCapabilities]
-> ReadPrec RenameClientCapabilities
-> ReadPrec [RenameClientCapabilities]
-> Read RenameClientCapabilities
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS RenameClientCapabilities
readsPrec :: Int -> ReadS RenameClientCapabilities
$creadList :: ReadS [RenameClientCapabilities]
readList :: ReadS [RenameClientCapabilities]
$creadPrec :: ReadPrec RenameClientCapabilities
readPrec :: ReadPrec RenameClientCapabilities
$creadListPrec :: ReadPrec [RenameClientCapabilities]
readListPrec :: ReadPrec [RenameClientCapabilities]
Read, RenameClientCapabilities -> RenameClientCapabilities -> Bool
(RenameClientCapabilities -> RenameClientCapabilities -> Bool)
-> (RenameClientCapabilities -> RenameClientCapabilities -> Bool)
-> Eq RenameClientCapabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RenameClientCapabilities -> RenameClientCapabilities -> Bool
== :: RenameClientCapabilities -> RenameClientCapabilities -> Bool
$c/= :: RenameClientCapabilities -> RenameClientCapabilities -> Bool
/= :: RenameClientCapabilities -> RenameClientCapabilities -> Bool
Eq)

deriveJSON lspOptions ''RenameClientCapabilities

makeExtendingDatatype "RenameOptions" [''WorkDoneProgressOptions]
  [("_prepareProvider", [t| Maybe Bool |])]
deriveJSON lspOptions ''RenameOptions

makeExtendingDatatype "RenameRegistrationOptions"
  [ ''TextDocumentRegistrationOptions
  , ''RenameOptions
  ] []
deriveJSON lspOptions ''RenameRegistrationOptions

makeExtendingDatatype "RenameParams"
  [ ''TextDocumentPositionParams
  , ''WorkDoneProgressParams
  ]
  [("_newName", [t| Text |])]
deriveJSON lspOptions ''RenameParams

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

makeExtendingDatatype "PrepareRenameParams" [''TextDocumentPositionParams] []
deriveJSON lspOptions ''PrepareRenameParams

data RangeWithPlaceholder =
  RangeWithPlaceholder
  {
    RangeWithPlaceholder -> Range
_range :: Range
  , RangeWithPlaceholder -> Text
_placeholder :: Text
  } deriving RangeWithPlaceholder -> RangeWithPlaceholder -> Bool
(RangeWithPlaceholder -> RangeWithPlaceholder -> Bool)
-> (RangeWithPlaceholder -> RangeWithPlaceholder -> Bool)
-> Eq RangeWithPlaceholder
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RangeWithPlaceholder -> RangeWithPlaceholder -> Bool
== :: RangeWithPlaceholder -> RangeWithPlaceholder -> Bool
$c/= :: RangeWithPlaceholder -> RangeWithPlaceholder -> Bool
/= :: RangeWithPlaceholder -> RangeWithPlaceholder -> Bool
Eq
deriveJSON lspOptions ''RangeWithPlaceholder