{-# 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.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 Int
_rangeLimit          :: Maybe Int
      -- | 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
showList :: [FoldingRangeClientCapabilities] -> ShowS
$cshowList :: [FoldingRangeClientCapabilities] -> ShowS
show :: FoldingRangeClientCapabilities -> String
$cshow :: FoldingRangeClientCapabilities -> String
showsPrec :: Int -> FoldingRangeClientCapabilities -> ShowS
$cshowsPrec :: Int -> 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
readListPrec :: ReadPrec [FoldingRangeClientCapabilities]
$creadListPrec :: ReadPrec [FoldingRangeClientCapabilities]
readPrec :: ReadPrec FoldingRangeClientCapabilities
$creadPrec :: ReadPrec FoldingRangeClientCapabilities
readList :: ReadS [FoldingRangeClientCapabilities]
$creadList :: ReadS [FoldingRangeClientCapabilities]
readsPrec :: Int -> ReadS FoldingRangeClientCapabilities
$creadsPrec :: Int -> ReadS FoldingRangeClientCapabilities
Read, FoldingRangeClientCapabilities
-> FoldingRangeClientCapabilities -> Bool
(FoldingRangeClientCapabilities
 -> FoldingRangeClientCapabilities -> Bool)
-> (FoldingRangeClientCapabilities
    -> FoldingRangeClientCapabilities -> Bool)
-> Eq FoldingRangeClientCapabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FoldingRangeClientCapabilities
-> FoldingRangeClientCapabilities -> Bool
$c/= :: FoldingRangeClientCapabilities
-> FoldingRangeClientCapabilities -> Bool
== :: FoldingRangeClientCapabilities
-> FoldingRangeClientCapabilities -> Bool
$c== :: 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
readListPrec :: ReadPrec [FoldingRangeKind]
$creadListPrec :: ReadPrec [FoldingRangeKind]
readPrec :: ReadPrec FoldingRangeKind
$creadPrec :: ReadPrec FoldingRangeKind
readList :: ReadS [FoldingRangeKind]
$creadList :: ReadS [FoldingRangeKind]
readsPrec :: Int -> ReadS FoldingRangeKind
$creadsPrec :: Int -> ReadS 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
showList :: [FoldingRangeKind] -> ShowS
$cshowList :: [FoldingRangeKind] -> ShowS
show :: FoldingRangeKind -> String
$cshow :: FoldingRangeKind -> String
showsPrec :: Int -> FoldingRangeKind -> ShowS
$cshowsPrec :: Int -> FoldingRangeKind -> ShowS
Show, FoldingRangeKind -> FoldingRangeKind -> Bool
(FoldingRangeKind -> FoldingRangeKind -> Bool)
-> (FoldingRangeKind -> FoldingRangeKind -> Bool)
-> Eq FoldingRangeKind
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FoldingRangeKind -> FoldingRangeKind -> Bool
$c/= :: FoldingRangeKind -> FoldingRangeKind -> Bool
== :: FoldingRangeKind -> FoldingRangeKind -> Bool
$c== :: 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 (f :: * -> *) a. Applicative f => a -> f a
pure FoldingRangeKind
FoldingRangeComment
  parseJSON (A.String Text
"imports") = FoldingRangeKind -> Parser FoldingRangeKind
forall (f :: * -> *) a. Applicative f => a -> f a
pure FoldingRangeKind
FoldingRangeImports
  parseJSON (A.String Text
"region")  = FoldingRangeKind -> Parser FoldingRangeKind
forall (f :: * -> *) a. Applicative f => a -> f a
pure FoldingRangeKind
FoldingRangeRegion
  parseJSON (A.String Text
x)         = FoldingRangeKind -> Parser FoldingRangeKind
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> FoldingRangeKind
FoldingRangeUnknown Text
x)
  parseJSON Value
_                    = Parser FoldingRangeKind
forall a. Monoid a => a
mempty

-- | Represents a folding range.
data FoldingRange =
  FoldingRange
  { -- | The zero-based line number from where the folded range starts.
    FoldingRange -> Int
_startLine      :: Int
    -- | The zero-based character offset from where the folded range
    -- starts. If not defined, defaults to the length of the start line.
  , FoldingRange -> Maybe Int
_startCharacter :: Maybe Int
    -- | The zero-based line number where the folded range ends.
  , FoldingRange -> Int
_endLine        :: Int
    -- | The zero-based character offset before the folded range ends.
    -- If not defined, defaults to the length of the end line.
  , FoldingRange -> Maybe Int
_endCharacter   :: Maybe Int
    -- | 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
readListPrec :: ReadPrec [FoldingRange]
$creadListPrec :: ReadPrec [FoldingRange]
readPrec :: ReadPrec FoldingRange
$creadPrec :: ReadPrec FoldingRange
readList :: ReadS [FoldingRange]
$creadList :: ReadS [FoldingRange]
readsPrec :: Int -> ReadS FoldingRange
$creadsPrec :: Int -> ReadS 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
showList :: [FoldingRange] -> ShowS
$cshowList :: [FoldingRange] -> ShowS
show :: FoldingRange -> String
$cshow :: FoldingRange -> String
showsPrec :: Int -> FoldingRange -> ShowS
$cshowsPrec :: Int -> FoldingRange -> ShowS
Show, FoldingRange -> FoldingRange -> Bool
(FoldingRange -> FoldingRange -> Bool)
-> (FoldingRange -> FoldingRange -> Bool) -> Eq FoldingRange
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FoldingRange -> FoldingRange -> Bool
$c/= :: FoldingRange -> FoldingRange -> Bool
== :: FoldingRange -> FoldingRange -> Bool
$c== :: FoldingRange -> FoldingRange -> Bool
Eq)

deriveJSON lspOptions ''FoldingRange