{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DuplicateRecordFields #-}
module Language.LSP.Types.WatchedFiles where
import Data.Aeson
import Data.Aeson.TH
import Data.Bits
import Data.Scientific
import Language.LSP.Types.Common
import Language.LSP.Types.Uri
import Language.LSP.Types.Utils
data DidChangeWatchedFilesClientCapabilities = DidChangeWatchedFilesClientCapabilities
{
_dynamicRegistration :: Maybe Bool
}
deriving (Show, Read, Eq)
deriveJSON lspOptions ''DidChangeWatchedFilesClientCapabilities
data DidChangeWatchedFilesRegistrationOptions =
DidChangeWatchedFilesRegistrationOptions
{
_watchers :: List FileSystemWatcher
} deriving (Show, Read, Eq)
data FileSystemWatcher =
FileSystemWatcher
{
_globPattern :: String,
_kind :: Maybe WatchKind
} deriving (Show, Read, Eq)
data WatchKind =
WatchKind {
_watchCreate :: Bool,
_watchChange :: Bool,
_watchDelete :: Bool
} deriving (Show, Read, Eq)
instance ToJSON WatchKind where
toJSON wk = Number (createNum + changeNum + deleteNum)
where
createNum = if _watchCreate wk then 0x1 else 0x0
changeNum = if _watchChange wk then 0x2 else 0x0
deleteNum = if _watchDelete wk then 0x4 else 0x0
instance FromJSON WatchKind where
parseJSON (Number n)
| Right i <- floatingOrInteger n :: Either Double Int
, 0 <= i && i <= 7 =
pure $ WatchKind (testBit i 0x0) (testBit i 0x1) (testBit i 0x2)
| otherwise = mempty
parseJSON _ = mempty
deriveJSON lspOptions ''DidChangeWatchedFilesRegistrationOptions
deriveJSON lspOptions ''FileSystemWatcher
data FileChangeType = FcCreated
| FcChanged
| FcDeleted
deriving (Read,Show,Eq)
instance ToJSON FileChangeType where
toJSON FcCreated = Number 1
toJSON FcChanged = Number 2
toJSON FcDeleted = Number 3
instance FromJSON FileChangeType where
parseJSON (Number 1) = pure FcCreated
parseJSON (Number 2) = pure FcChanged
parseJSON (Number 3) = pure FcDeleted
parseJSON _ = mempty
data FileEvent =
FileEvent
{
_uri :: Uri
, _xtype :: FileChangeType
} deriving (Read,Show,Eq)
deriveJSON lspOptions ''FileEvent
data DidChangeWatchedFilesParams =
DidChangeWatchedFilesParams
{
_changes :: List FileEvent
} deriving (Read,Show,Eq)
deriveJSON lspOptions ''DidChangeWatchedFilesParams