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

import Data.Aeson
import Data.Aeson.TH
import Language.LSP.Types.Location
import Language.LSP.Types.Progress
import Language.LSP.Types.TextDocument
import Language.LSP.Types.Utils

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

data DocumentHighlightClientCapabilities =
  DocumentHighlightClientCapabilities
    { -- | Whether document highlight supports dynamic registration.
      DocumentHighlightClientCapabilities -> Maybe Bool
_dynamicRegistration :: Maybe Bool
    } deriving (Int -> DocumentHighlightClientCapabilities -> ShowS
[DocumentHighlightClientCapabilities] -> ShowS
DocumentHighlightClientCapabilities -> String
(Int -> DocumentHighlightClientCapabilities -> ShowS)
-> (DocumentHighlightClientCapabilities -> String)
-> ([DocumentHighlightClientCapabilities] -> ShowS)
-> Show DocumentHighlightClientCapabilities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DocumentHighlightClientCapabilities] -> ShowS
$cshowList :: [DocumentHighlightClientCapabilities] -> ShowS
show :: DocumentHighlightClientCapabilities -> String
$cshow :: DocumentHighlightClientCapabilities -> String
showsPrec :: Int -> DocumentHighlightClientCapabilities -> ShowS
$cshowsPrec :: Int -> DocumentHighlightClientCapabilities -> ShowS
Show, ReadPrec [DocumentHighlightClientCapabilities]
ReadPrec DocumentHighlightClientCapabilities
Int -> ReadS DocumentHighlightClientCapabilities
ReadS [DocumentHighlightClientCapabilities]
(Int -> ReadS DocumentHighlightClientCapabilities)
-> ReadS [DocumentHighlightClientCapabilities]
-> ReadPrec DocumentHighlightClientCapabilities
-> ReadPrec [DocumentHighlightClientCapabilities]
-> Read DocumentHighlightClientCapabilities
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DocumentHighlightClientCapabilities]
$creadListPrec :: ReadPrec [DocumentHighlightClientCapabilities]
readPrec :: ReadPrec DocumentHighlightClientCapabilities
$creadPrec :: ReadPrec DocumentHighlightClientCapabilities
readList :: ReadS [DocumentHighlightClientCapabilities]
$creadList :: ReadS [DocumentHighlightClientCapabilities]
readsPrec :: Int -> ReadS DocumentHighlightClientCapabilities
$creadsPrec :: Int -> ReadS DocumentHighlightClientCapabilities
Read, DocumentHighlightClientCapabilities
-> DocumentHighlightClientCapabilities -> Bool
(DocumentHighlightClientCapabilities
 -> DocumentHighlightClientCapabilities -> Bool)
-> (DocumentHighlightClientCapabilities
    -> DocumentHighlightClientCapabilities -> Bool)
-> Eq DocumentHighlightClientCapabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DocumentHighlightClientCapabilities
-> DocumentHighlightClientCapabilities -> Bool
$c/= :: DocumentHighlightClientCapabilities
-> DocumentHighlightClientCapabilities -> Bool
== :: DocumentHighlightClientCapabilities
-> DocumentHighlightClientCapabilities -> Bool
$c== :: DocumentHighlightClientCapabilities
-> DocumentHighlightClientCapabilities -> Bool
Eq)

deriveJSON lspOptions ''DocumentHighlightClientCapabilities

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

makeExtendingDatatype "DocumentHighlightRegistrationOptions"
  [ ''TextDocumentRegistrationOptions
  , ''DocumentHighlightOptions
  ] []
deriveJSON lspOptions ''DocumentHighlightRegistrationOptions

makeExtendingDatatype "DocumentHighlightParams"
  [ ''TextDocumentPositionParams
  , ''WorkDoneProgressParams
  , ''PartialResultParams
  ] []
deriveJSON lspOptions ''DocumentHighlightParams

data DocumentHighlightKind
  = -- | A textual occurrence.
    HkText
  | -- | Read-access of a symbol, like reading a variable.
    HkRead
  | -- | Write-access of a symbol, like writing to a variable.
    HkWrite
  deriving (ReadPrec [DocumentHighlightKind]
ReadPrec DocumentHighlightKind
Int -> ReadS DocumentHighlightKind
ReadS [DocumentHighlightKind]
(Int -> ReadS DocumentHighlightKind)
-> ReadS [DocumentHighlightKind]
-> ReadPrec DocumentHighlightKind
-> ReadPrec [DocumentHighlightKind]
-> Read DocumentHighlightKind
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DocumentHighlightKind]
$creadListPrec :: ReadPrec [DocumentHighlightKind]
readPrec :: ReadPrec DocumentHighlightKind
$creadPrec :: ReadPrec DocumentHighlightKind
readList :: ReadS [DocumentHighlightKind]
$creadList :: ReadS [DocumentHighlightKind]
readsPrec :: Int -> ReadS DocumentHighlightKind
$creadsPrec :: Int -> ReadS DocumentHighlightKind
Read, Int -> DocumentHighlightKind -> ShowS
[DocumentHighlightKind] -> ShowS
DocumentHighlightKind -> String
(Int -> DocumentHighlightKind -> ShowS)
-> (DocumentHighlightKind -> String)
-> ([DocumentHighlightKind] -> ShowS)
-> Show DocumentHighlightKind
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DocumentHighlightKind] -> ShowS
$cshowList :: [DocumentHighlightKind] -> ShowS
show :: DocumentHighlightKind -> String
$cshow :: DocumentHighlightKind -> String
showsPrec :: Int -> DocumentHighlightKind -> ShowS
$cshowsPrec :: Int -> DocumentHighlightKind -> ShowS
Show, DocumentHighlightKind -> DocumentHighlightKind -> Bool
(DocumentHighlightKind -> DocumentHighlightKind -> Bool)
-> (DocumentHighlightKind -> DocumentHighlightKind -> Bool)
-> Eq DocumentHighlightKind
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DocumentHighlightKind -> DocumentHighlightKind -> Bool
$c/= :: DocumentHighlightKind -> DocumentHighlightKind -> Bool
== :: DocumentHighlightKind -> DocumentHighlightKind -> Bool
$c== :: DocumentHighlightKind -> DocumentHighlightKind -> Bool
Eq)

instance ToJSON DocumentHighlightKind where
  toJSON :: DocumentHighlightKind -> Value
toJSON DocumentHighlightKind
HkText  = Scientific -> Value
Number Scientific
1
  toJSON DocumentHighlightKind
HkRead  = Scientific -> Value
Number Scientific
2
  toJSON DocumentHighlightKind
HkWrite = Scientific -> Value
Number Scientific
3

instance FromJSON DocumentHighlightKind where
  parseJSON :: Value -> Parser DocumentHighlightKind
parseJSON (Number Scientific
1) = DocumentHighlightKind -> Parser DocumentHighlightKind
forall (f :: * -> *) a. Applicative f => a -> f a
pure DocumentHighlightKind
HkText
  parseJSON (Number Scientific
2) = DocumentHighlightKind -> Parser DocumentHighlightKind
forall (f :: * -> *) a. Applicative f => a -> f a
pure DocumentHighlightKind
HkRead
  parseJSON (Number Scientific
3) = DocumentHighlightKind -> Parser DocumentHighlightKind
forall (f :: * -> *) a. Applicative f => a -> f a
pure DocumentHighlightKind
HkWrite
  parseJSON Value
_          = String -> Parser DocumentHighlightKind
forall a. Monoid a => a
mempty String
"DocumentHighlightKind"

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

-- | A document highlight is a range inside a text document which deserves
-- special attention. Usually a document highlight is visualized by changing the
-- background color of its range.
data DocumentHighlight =
  DocumentHighlight
    { -- | The range this highlight applies to.
      DocumentHighlight -> Range
_range :: Range
      -- | The highlight kind, default is 'HkText'.
    , DocumentHighlight -> Maybe DocumentHighlightKind
_kind  :: Maybe DocumentHighlightKind
    } deriving (ReadPrec [DocumentHighlight]
ReadPrec DocumentHighlight
Int -> ReadS DocumentHighlight
ReadS [DocumentHighlight]
(Int -> ReadS DocumentHighlight)
-> ReadS [DocumentHighlight]
-> ReadPrec DocumentHighlight
-> ReadPrec [DocumentHighlight]
-> Read DocumentHighlight
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DocumentHighlight]
$creadListPrec :: ReadPrec [DocumentHighlight]
readPrec :: ReadPrec DocumentHighlight
$creadPrec :: ReadPrec DocumentHighlight
readList :: ReadS [DocumentHighlight]
$creadList :: ReadS [DocumentHighlight]
readsPrec :: Int -> ReadS DocumentHighlight
$creadsPrec :: Int -> ReadS DocumentHighlight
Read,Int -> DocumentHighlight -> ShowS
[DocumentHighlight] -> ShowS
DocumentHighlight -> String
(Int -> DocumentHighlight -> ShowS)
-> (DocumentHighlight -> String)
-> ([DocumentHighlight] -> ShowS)
-> Show DocumentHighlight
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DocumentHighlight] -> ShowS
$cshowList :: [DocumentHighlight] -> ShowS
show :: DocumentHighlight -> String
$cshow :: DocumentHighlight -> String
showsPrec :: Int -> DocumentHighlight -> ShowS
$cshowsPrec :: Int -> DocumentHighlight -> ShowS
Show,DocumentHighlight -> DocumentHighlight -> Bool
(DocumentHighlight -> DocumentHighlight -> Bool)
-> (DocumentHighlight -> DocumentHighlight -> Bool)
-> Eq DocumentHighlight
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DocumentHighlight -> DocumentHighlight -> Bool
$c/= :: DocumentHighlight -> DocumentHighlight -> Bool
== :: DocumentHighlight -> DocumentHighlight -> Bool
$c== :: DocumentHighlight -> DocumentHighlight -> Bool
Eq)

deriveJSON lspOptions ''DocumentHighlight