{-# 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
$cshowsPrec :: Int -> DocumentHighlightClientCapabilities -> ShowS
showsPrec :: Int -> DocumentHighlightClientCapabilities -> ShowS
$cshow :: DocumentHighlightClientCapabilities -> String
show :: DocumentHighlightClientCapabilities -> String
$cshowList :: [DocumentHighlightClientCapabilities] -> ShowS
showList :: [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
$creadsPrec :: Int -> ReadS DocumentHighlightClientCapabilities
readsPrec :: Int -> ReadS DocumentHighlightClientCapabilities
$creadList :: ReadS [DocumentHighlightClientCapabilities]
readList :: ReadS [DocumentHighlightClientCapabilities]
$creadPrec :: ReadPrec DocumentHighlightClientCapabilities
readPrec :: ReadPrec DocumentHighlightClientCapabilities
$creadListPrec :: ReadPrec [DocumentHighlightClientCapabilities]
readListPrec :: ReadPrec [DocumentHighlightClientCapabilities]
Read, DocumentHighlightClientCapabilities
-> DocumentHighlightClientCapabilities -> Bool
(DocumentHighlightClientCapabilities
 -> DocumentHighlightClientCapabilities -> Bool)
-> (DocumentHighlightClientCapabilities
    -> DocumentHighlightClientCapabilities -> Bool)
-> Eq DocumentHighlightClientCapabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DocumentHighlightClientCapabilities
-> DocumentHighlightClientCapabilities -> Bool
== :: DocumentHighlightClientCapabilities
-> DocumentHighlightClientCapabilities -> Bool
$c/= :: DocumentHighlightClientCapabilities
-> DocumentHighlightClientCapabilities -> Bool
/= :: 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
$creadsPrec :: Int -> ReadS DocumentHighlightKind
readsPrec :: Int -> ReadS DocumentHighlightKind
$creadList :: ReadS [DocumentHighlightKind]
readList :: ReadS [DocumentHighlightKind]
$creadPrec :: ReadPrec DocumentHighlightKind
readPrec :: ReadPrec DocumentHighlightKind
$creadListPrec :: ReadPrec [DocumentHighlightKind]
readListPrec :: ReadPrec [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
$cshowsPrec :: Int -> DocumentHighlightKind -> ShowS
showsPrec :: Int -> DocumentHighlightKind -> ShowS
$cshow :: DocumentHighlightKind -> String
show :: DocumentHighlightKind -> String
$cshowList :: [DocumentHighlightKind] -> ShowS
showList :: [DocumentHighlightKind] -> ShowS
Show, DocumentHighlightKind -> DocumentHighlightKind -> Bool
(DocumentHighlightKind -> DocumentHighlightKind -> Bool)
-> (DocumentHighlightKind -> DocumentHighlightKind -> Bool)
-> Eq DocumentHighlightKind
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DocumentHighlightKind -> DocumentHighlightKind -> Bool
== :: DocumentHighlightKind -> DocumentHighlightKind -> Bool
$c/= :: DocumentHighlightKind -> DocumentHighlightKind -> Bool
/= :: 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 a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure DocumentHighlightKind
HkText
  parseJSON (Number Scientific
2) = DocumentHighlightKind -> Parser DocumentHighlightKind
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure DocumentHighlightKind
HkRead
  parseJSON (Number Scientific
3) = DocumentHighlightKind -> Parser DocumentHighlightKind
forall a. a -> Parser a
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
$creadsPrec :: Int -> ReadS DocumentHighlight
readsPrec :: Int -> ReadS DocumentHighlight
$creadList :: ReadS [DocumentHighlight]
readList :: ReadS [DocumentHighlight]
$creadPrec :: ReadPrec DocumentHighlight
readPrec :: ReadPrec DocumentHighlight
$creadListPrec :: ReadPrec [DocumentHighlight]
readListPrec :: ReadPrec [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
$cshowsPrec :: Int -> DocumentHighlight -> ShowS
showsPrec :: Int -> DocumentHighlight -> ShowS
$cshow :: DocumentHighlight -> String
show :: DocumentHighlight -> String
$cshowList :: [DocumentHighlight] -> ShowS
showList :: [DocumentHighlight] -> ShowS
Show,DocumentHighlight -> DocumentHighlight -> Bool
(DocumentHighlight -> DocumentHighlight -> Bool)
-> (DocumentHighlight -> DocumentHighlight -> Bool)
-> Eq DocumentHighlight
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DocumentHighlight -> DocumentHighlight -> Bool
== :: DocumentHighlight -> DocumentHighlight -> Bool
$c/= :: DocumentHighlight -> DocumentHighlight -> Bool
/= :: DocumentHighlight -> DocumentHighlight -> Bool
Eq)

deriveJSON lspOptions ''DocumentHighlight