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

import qualified Data.Aeson                    as A
import           Data.Aeson.TH
import           Data.Text                    (Text)
import           Language.Haskell.LSP.Types.Constants
import           Language.Haskell.LSP.Types.List
import           Language.Haskell.LSP.Types.Progress
import           Language.Haskell.LSP.Types.TextDocument
import           Language.Haskell.LSP.Types.Message

data FoldingRangeParams =
  FoldingRangeParams
  { FoldingRangeParams -> TextDocumentIdentifier
_textDocument :: TextDocumentIdentifier -- ^ The text document.
  , FoldingRangeParams -> Maybe ProgressToken
_workDoneToken :: Maybe ProgressToken -- ^ An optional token that a server can use to report work done progress.
  }
  deriving (ReadPrec [FoldingRangeParams]
ReadPrec FoldingRangeParams
Int -> ReadS FoldingRangeParams
ReadS [FoldingRangeParams]
(Int -> ReadS FoldingRangeParams)
-> ReadS [FoldingRangeParams]
-> ReadPrec FoldingRangeParams
-> ReadPrec [FoldingRangeParams]
-> Read FoldingRangeParams
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FoldingRangeParams]
$creadListPrec :: ReadPrec [FoldingRangeParams]
readPrec :: ReadPrec FoldingRangeParams
$creadPrec :: ReadPrec FoldingRangeParams
readList :: ReadS [FoldingRangeParams]
$creadList :: ReadS [FoldingRangeParams]
readsPrec :: Int -> ReadS FoldingRangeParams
$creadsPrec :: Int -> ReadS FoldingRangeParams
Read, Int -> FoldingRangeParams -> ShowS
[FoldingRangeParams] -> ShowS
FoldingRangeParams -> String
(Int -> FoldingRangeParams -> ShowS)
-> (FoldingRangeParams -> String)
-> ([FoldingRangeParams] -> ShowS)
-> Show FoldingRangeParams
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FoldingRangeParams] -> ShowS
$cshowList :: [FoldingRangeParams] -> ShowS
show :: FoldingRangeParams -> String
$cshow :: FoldingRangeParams -> String
showsPrec :: Int -> FoldingRangeParams -> ShowS
$cshowsPrec :: Int -> FoldingRangeParams -> ShowS
Show, FoldingRangeParams -> FoldingRangeParams -> Bool
(FoldingRangeParams -> FoldingRangeParams -> Bool)
-> (FoldingRangeParams -> FoldingRangeParams -> Bool)
-> Eq FoldingRangeParams
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FoldingRangeParams -> FoldingRangeParams -> Bool
$c/= :: FoldingRangeParams -> FoldingRangeParams -> Bool
== :: FoldingRangeParams -> FoldingRangeParams -> Bool
$c== :: FoldingRangeParams -> FoldingRangeParams -> Bool
Eq)

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

type FoldingRangeRequest = RequestMessage ClientMethod FoldingRangeParams (List FoldingRange)
type FoldingRangeResponse = ResponseMessage (List FoldingRange)