{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE DuplicateRecordFields      #-}
{-# LANGUAGE TemplateHaskell            #-}
module Language.LSP.Types.FoldingRange where

import qualified Data.Aeson                    as A
import           Data.Aeson.TH
import           Data.Text                    (Text)
import           Language.LSP.Types.Common
import           Language.LSP.Types.Progress
import           Language.LSP.Types.StaticRegistrationOptions
import           Language.LSP.Types.TextDocument
import           Language.LSP.Types.Utils


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

data FoldingRangeClientCapabilities =
  FoldingRangeClientCapabilities
    { -- | Whether implementation supports dynamic registration for folding range
      -- providers. If this is set to `true` the client supports the new
      -- `(FoldingRangeProviderOptions & TextDocumentRegistrationOptions & StaticRegistrationOptions)`
      -- return value for the corresponding server capability as well.
      FoldingRangeClientCapabilities -> Maybe Bool
_dynamicRegistration :: Maybe Bool
      -- | The maximum number of folding ranges that the client prefers to receive
      -- per document. The value serves as a hint, servers are free to follow the limit.
    , FoldingRangeClientCapabilities -> Maybe UInt
_rangeLimit          :: Maybe UInt
      -- | If set, the client signals that it only supports folding complete lines. If set,
      -- client will ignore specified `startCharacter` and `endCharacter` properties in a
      -- FoldingRange.
    , FoldingRangeClientCapabilities -> Maybe Bool
_lineFoldingOnly     :: Maybe Bool
    } deriving (Int -> FoldingRangeClientCapabilities -> ShowS
[FoldingRangeClientCapabilities] -> ShowS
FoldingRangeClientCapabilities -> String
(Int -> FoldingRangeClientCapabilities -> ShowS)
-> (FoldingRangeClientCapabilities -> String)
-> ([FoldingRangeClientCapabilities] -> ShowS)
-> Show FoldingRangeClientCapabilities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FoldingRangeClientCapabilities -> ShowS
showsPrec :: Int -> FoldingRangeClientCapabilities -> ShowS
$cshow :: FoldingRangeClientCapabilities -> String
show :: FoldingRangeClientCapabilities -> String
$cshowList :: [FoldingRangeClientCapabilities] -> ShowS
showList :: [FoldingRangeClientCapabilities] -> ShowS
Show, ReadPrec [FoldingRangeClientCapabilities]
ReadPrec FoldingRangeClientCapabilities
Int -> ReadS FoldingRangeClientCapabilities
ReadS [FoldingRangeClientCapabilities]
(Int -> ReadS FoldingRangeClientCapabilities)
-> ReadS [FoldingRangeClientCapabilities]
-> ReadPrec FoldingRangeClientCapabilities
-> ReadPrec [FoldingRangeClientCapabilities]
-> Read FoldingRangeClientCapabilities
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS FoldingRangeClientCapabilities
readsPrec :: Int -> ReadS FoldingRangeClientCapabilities
$creadList :: ReadS [FoldingRangeClientCapabilities]
readList :: ReadS [FoldingRangeClientCapabilities]
$creadPrec :: ReadPrec FoldingRangeClientCapabilities
readPrec :: ReadPrec FoldingRangeClientCapabilities
$creadListPrec :: ReadPrec [FoldingRangeClientCapabilities]
readListPrec :: ReadPrec [FoldingRangeClientCapabilities]
Read, FoldingRangeClientCapabilities
-> FoldingRangeClientCapabilities -> Bool
(FoldingRangeClientCapabilities
 -> FoldingRangeClientCapabilities -> Bool)
-> (FoldingRangeClientCapabilities
    -> FoldingRangeClientCapabilities -> Bool)
-> Eq FoldingRangeClientCapabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FoldingRangeClientCapabilities
-> FoldingRangeClientCapabilities -> Bool
== :: FoldingRangeClientCapabilities
-> FoldingRangeClientCapabilities -> Bool
$c/= :: FoldingRangeClientCapabilities
-> FoldingRangeClientCapabilities -> Bool
/= :: FoldingRangeClientCapabilities
-> FoldingRangeClientCapabilities -> Bool
Eq)

deriveJSON lspOptions ''FoldingRangeClientCapabilities

makeExtendingDatatype "FoldingRangeOptions" [''WorkDoneProgressOptions] []
deriveJSON lspOptions ''FoldingRangeOptions

makeExtendingDatatype "FoldingRangeRegistrationOptions"
  [ ''TextDocumentRegistrationOptions
  , ''FoldingRangeOptions
  , ''StaticRegistrationOptions
  ] []
deriveJSON lspOptions ''FoldingRangeRegistrationOptions


makeExtendingDatatype "FoldingRangeParams"
  [ ''WorkDoneProgressParams
  , ''PartialResultParams
  ]
  [("_textDocument", [t| TextDocumentIdentifier |])]
deriveJSON lspOptions ''FoldingRangeParams

-- | Enum of known range kinds
data FoldingRangeKind = FoldingRangeComment
                        -- ^ Folding range for a comment
                      | FoldingRangeImports
                        -- ^ Folding range for a imports or includes
                      | FoldingRangeRegion
                        -- ^ Folding range for a region (e.g. #region)
                      | FoldingRangeUnknown Text
                        -- ^ Folding range that haskell-lsp-types does
                        -- not yet support
  deriving (ReadPrec [FoldingRangeKind]
ReadPrec FoldingRangeKind
Int -> ReadS FoldingRangeKind
ReadS [FoldingRangeKind]
(Int -> ReadS FoldingRangeKind)
-> ReadS [FoldingRangeKind]
-> ReadPrec FoldingRangeKind
-> ReadPrec [FoldingRangeKind]
-> Read FoldingRangeKind
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS FoldingRangeKind
readsPrec :: Int -> ReadS FoldingRangeKind
$creadList :: ReadS [FoldingRangeKind]
readList :: ReadS [FoldingRangeKind]
$creadPrec :: ReadPrec FoldingRangeKind
readPrec :: ReadPrec FoldingRangeKind
$creadListPrec :: ReadPrec [FoldingRangeKind]
readListPrec :: ReadPrec [FoldingRangeKind]
Read, Int -> FoldingRangeKind -> ShowS
[FoldingRangeKind] -> ShowS
FoldingRangeKind -> String
(Int -> FoldingRangeKind -> ShowS)
-> (FoldingRangeKind -> String)
-> ([FoldingRangeKind] -> ShowS)
-> Show FoldingRangeKind
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FoldingRangeKind -> ShowS
showsPrec :: Int -> FoldingRangeKind -> ShowS
$cshow :: FoldingRangeKind -> String
show :: FoldingRangeKind -> String
$cshowList :: [FoldingRangeKind] -> ShowS
showList :: [FoldingRangeKind] -> ShowS
Show, FoldingRangeKind -> FoldingRangeKind -> Bool
(FoldingRangeKind -> FoldingRangeKind -> Bool)
-> (FoldingRangeKind -> FoldingRangeKind -> Bool)
-> Eq FoldingRangeKind
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FoldingRangeKind -> FoldingRangeKind -> Bool
== :: FoldingRangeKind -> FoldingRangeKind -> Bool
$c/= :: FoldingRangeKind -> FoldingRangeKind -> Bool
/= :: FoldingRangeKind -> FoldingRangeKind -> Bool
Eq)

instance A.ToJSON FoldingRangeKind where
  toJSON :: FoldingRangeKind -> Value
toJSON FoldingRangeKind
FoldingRangeComment     = Text -> Value
A.String Text
"comment"
  toJSON FoldingRangeKind
FoldingRangeImports     = Text -> Value
A.String Text
"imports"
  toJSON FoldingRangeKind
FoldingRangeRegion      = Text -> Value
A.String Text
"region"
  toJSON (FoldingRangeUnknown Text
x) = Text -> Value
A.String Text
x

instance A.FromJSON FoldingRangeKind where
  parseJSON :: Value -> Parser FoldingRangeKind
parseJSON (A.String Text
"comment") = FoldingRangeKind -> Parser FoldingRangeKind
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure FoldingRangeKind
FoldingRangeComment
  parseJSON (A.String Text
"imports") = FoldingRangeKind -> Parser FoldingRangeKind
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure FoldingRangeKind
FoldingRangeImports
  parseJSON (A.String Text
"region")  = FoldingRangeKind -> Parser FoldingRangeKind
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure FoldingRangeKind
FoldingRangeRegion
  parseJSON (A.String Text
x)         = FoldingRangeKind -> Parser FoldingRangeKind
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> FoldingRangeKind
FoldingRangeUnknown Text
x)
  parseJSON Value
_                    = String -> Parser FoldingRangeKind
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"FoldingRangeKind"

-- | Represents a folding range.
data FoldingRange =
  FoldingRange
  { -- | The zero-based line number from where the folded range starts.
    FoldingRange -> UInt
_startLine      :: UInt
    -- | The zero-based character offset from where the folded range
    -- starts. If not defined, defaults to the length of the start line.
  , FoldingRange -> Maybe UInt
_startCharacter :: Maybe UInt
    -- | The zero-based line number where the folded range ends.
  , FoldingRange -> UInt
_endLine        :: UInt
    -- | The zero-based character offset before the folded range ends.
    -- If not defined, defaults to the length of the end line.
  , FoldingRange -> Maybe UInt
_endCharacter   :: Maybe UInt
    -- | Describes the kind of the folding range such as 'comment' or
    -- 'region'. The kind is used to categorize folding ranges and used
    -- by commands like 'Fold all comments'. See 'FoldingRangeKind' for
    -- an enumeration of standardized kinds.
  , FoldingRange -> Maybe FoldingRangeKind
_kind           :: Maybe FoldingRangeKind
  }
  deriving (ReadPrec [FoldingRange]
ReadPrec FoldingRange
Int -> ReadS FoldingRange
ReadS [FoldingRange]
(Int -> ReadS FoldingRange)
-> ReadS [FoldingRange]
-> ReadPrec FoldingRange
-> ReadPrec [FoldingRange]
-> Read FoldingRange
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS FoldingRange
readsPrec :: Int -> ReadS FoldingRange
$creadList :: ReadS [FoldingRange]
readList :: ReadS [FoldingRange]
$creadPrec :: ReadPrec FoldingRange
readPrec :: ReadPrec FoldingRange
$creadListPrec :: ReadPrec [FoldingRange]
readListPrec :: ReadPrec [FoldingRange]
Read, Int -> FoldingRange -> ShowS
[FoldingRange] -> ShowS
FoldingRange -> String
(Int -> FoldingRange -> ShowS)
-> (FoldingRange -> String)
-> ([FoldingRange] -> ShowS)
-> Show FoldingRange
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FoldingRange -> ShowS
showsPrec :: Int -> FoldingRange -> ShowS
$cshow :: FoldingRange -> String
show :: FoldingRange -> String
$cshowList :: [FoldingRange] -> ShowS
showList :: [FoldingRange] -> ShowS
Show, FoldingRange -> FoldingRange -> Bool
(FoldingRange -> FoldingRange -> Bool)
-> (FoldingRange -> FoldingRange -> Bool) -> Eq FoldingRange
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FoldingRange -> FoldingRange -> Bool
== :: FoldingRange -> FoldingRange -> Bool
$c/= :: FoldingRange -> FoldingRange -> Bool
/= :: FoldingRange -> FoldingRange -> Bool
Eq)

deriveJSON lspOptions ''FoldingRange