{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
module Language.LSP.Types.TextDocument where
import Data.Aeson
import Data.Aeson.TH
import Data.Default
import Data.Text ( Text )
import Language.LSP.Types.Common
import Language.LSP.Types.DocumentFilter
import Language.LSP.Types.Location
import Language.LSP.Types.Uri
import Language.LSP.Types.Utils
data TextDocumentIdentifier =
TextDocumentIdentifier
{ _uri :: Uri
} deriving (Show, Read, Eq)
deriveJSON lspOptions ''TextDocumentIdentifier
type TextDocumentVersion = Maybe Int
makeExtendingDatatype "VersionedTextDocumentIdentifier" [''TextDocumentIdentifier]
[ ("_version", [t| TextDocumentVersion |])]
deriveJSON lspOptions ''VersionedTextDocumentIdentifier
data TextDocumentItem =
TextDocumentItem {
_uri :: Uri
, _languageId :: Text
, _version :: Int
, _text :: Text
} deriving (Show, Read, Eq)
deriveJSON lspOptions ''TextDocumentItem
data TextDocumentPositionParams =
TextDocumentPositionParams
{
_textDocument :: TextDocumentIdentifier
,
_position :: Position
} deriving (Show, Read, Eq)
deriveJSON lspOptions ''TextDocumentPositionParams
data TextDocumentSyncClientCapabilities =
TextDocumentSyncClientCapabilities
{
_dynamicRegistration :: Maybe Bool
, _willSave :: Maybe Bool
, _willSaveWaitUntil :: Maybe Bool
, _didSave :: Maybe Bool
} deriving (Show, Read, Eq)
deriveJSON lspOptions ''TextDocumentSyncClientCapabilities
instance Default TextDocumentSyncClientCapabilities where
def = TextDocumentSyncClientCapabilities def def def def
data SaveOptions =
SaveOptions
{
_includeText :: Maybe Bool
} deriving (Show, Read, Eq)
data TextDocumentSyncKind
=
TdSyncNone
|
TdSyncFull
|
TdSyncIncremental
deriving (Read, Eq, Show)
instance ToJSON TextDocumentSyncKind where
toJSON TdSyncNone = Number 0
toJSON TdSyncFull = Number 1
toJSON TdSyncIncremental = Number 2
instance FromJSON TextDocumentSyncKind where
parseJSON (Number 0) = pure TdSyncNone
parseJSON (Number 1) = pure TdSyncFull
parseJSON (Number 2) = pure TdSyncIncremental
parseJSON _ = mempty
data TextDocumentSyncOptions =
TextDocumentSyncOptions
{
_openClose :: Maybe Bool
,
_change :: Maybe TextDocumentSyncKind
, _willSave :: Maybe Bool
, _willSaveWaitUntil :: Maybe Bool
, _save :: Maybe (Bool |? SaveOptions)
} deriving (Show, Read, Eq)
deriveJSON lspOptions ''TextDocumentSyncOptions
data TextDocumentRegistrationOptions =
TextDocumentRegistrationOptions
{ _documentSelector :: Maybe DocumentSelector
} deriving (Show, Read, Eq)
deriveJSON lspOptions ''TextDocumentRegistrationOptions
data DidOpenTextDocumentParams =
DidOpenTextDocumentParams
{
_textDocument :: TextDocumentItem
} deriving (Show, Read, Eq)
deriveJSON lspOptions ''DidOpenTextDocumentParams
makeExtendingDatatype "TextDocumentChangeRegistrationOptions"
[''TextDocumentRegistrationOptions]
[("_syncKind", [t| TextDocumentSyncKind |])]
deriveJSON lspOptions ''TextDocumentChangeRegistrationOptions
{-# DEPRECATED _rangeLength "Use _range instead" #-}
data TextDocumentContentChangeEvent =
TextDocumentContentChangeEvent
{
_range :: Maybe Range
, _rangeLength :: Maybe Int
, _text :: Text
}
deriving (Read,Show,Eq)
deriveJSON lspOptions ''TextDocumentContentChangeEvent
data DidChangeTextDocumentParams =
DidChangeTextDocumentParams
{
_textDocument :: VersionedTextDocumentIdentifier
, _contentChanges :: List TextDocumentContentChangeEvent
} deriving (Show,Read,Eq)
deriveJSON lspOptions ''DidChangeTextDocumentParams
data TextDocumentSaveReason
= SaveManual
| SaveAfterDelay
| SaveFocusOut
deriving (Show, Read, Eq)
instance ToJSON TextDocumentSaveReason where
toJSON SaveManual = Number 1
toJSON SaveAfterDelay = Number 2
toJSON SaveFocusOut = Number 3
instance FromJSON TextDocumentSaveReason where
parseJSON (Number 1) = pure SaveManual
parseJSON (Number 2) = pure SaveAfterDelay
parseJSON (Number 3) = pure SaveFocusOut
parseJSON _ = mempty
data WillSaveTextDocumentParams =
WillSaveTextDocumentParams
{
_textDocument :: TextDocumentIdentifier
, _reason :: TextDocumentSaveReason
} deriving (Show, Read, Eq)
deriveJSON lspOptions ''WillSaveTextDocumentParams
deriveJSON lspOptions ''SaveOptions
makeExtendingDatatype "TextDocumentSaveRegistrationOptions"
[''TextDocumentRegistrationOptions]
[("_includeText", [t| Maybe Bool |])]
deriveJSON lspOptions ''TextDocumentSaveRegistrationOptions
data DidSaveTextDocumentParams =
DidSaveTextDocumentParams
{
_textDocument :: TextDocumentIdentifier
, _text :: Maybe Text
} deriving (Read,Show,Eq)
deriveJSON lspOptions ''DidSaveTextDocumentParams
data DidCloseTextDocumentParams =
DidCloseTextDocumentParams
{
_textDocument :: TextDocumentIdentifier
} deriving (Read,Show,Eq)
deriveJSON lspOptions ''DidCloseTextDocumentParams