{-# LANGUAGE DuplicateRecordFields      #-}
{-# LANGUAGE TemplateHaskell            #-}
{-# LANGUAGE TypeOperators              #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE RecordWildCards            #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module Language.LSP.Types.WorkspaceEdit where

import           Control.Monad                              (unless)
import           Data.Aeson
import           Data.Aeson.TH
import qualified Data.HashMap.Strict                        as H
import           Data.Maybe                                 (catMaybes)
import           Data.Text                                  (Text)
import qualified Data.Text                                  as T
import           Data.Hashable

import           Language.LSP.Types.Common
import           Language.LSP.Types.Location
import           Language.LSP.Types.TextDocument
import           Language.LSP.Types.Uri
import           Language.LSP.Types.Utils

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

data TextEdit =
  TextEdit
    { TextEdit -> Range
_range   :: Range
    , TextEdit -> Text
_newText :: Text
    } deriving (Int -> TextEdit -> ShowS
[TextEdit] -> ShowS
TextEdit -> String
(Int -> TextEdit -> ShowS)
-> (TextEdit -> String) -> ([TextEdit] -> ShowS) -> Show TextEdit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextEdit -> ShowS
showsPrec :: Int -> TextEdit -> ShowS
$cshow :: TextEdit -> String
show :: TextEdit -> String
$cshowList :: [TextEdit] -> ShowS
showList :: [TextEdit] -> ShowS
Show,ReadPrec [TextEdit]
ReadPrec TextEdit
Int -> ReadS TextEdit
ReadS [TextEdit]
(Int -> ReadS TextEdit)
-> ReadS [TextEdit]
-> ReadPrec TextEdit
-> ReadPrec [TextEdit]
-> Read TextEdit
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS TextEdit
readsPrec :: Int -> ReadS TextEdit
$creadList :: ReadS [TextEdit]
readList :: ReadS [TextEdit]
$creadPrec :: ReadPrec TextEdit
readPrec :: ReadPrec TextEdit
$creadListPrec :: ReadPrec [TextEdit]
readListPrec :: ReadPrec [TextEdit]
Read,TextEdit -> TextEdit -> Bool
(TextEdit -> TextEdit -> Bool)
-> (TextEdit -> TextEdit -> Bool) -> Eq TextEdit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextEdit -> TextEdit -> Bool
== :: TextEdit -> TextEdit -> Bool
$c/= :: TextEdit -> TextEdit -> Bool
/= :: TextEdit -> TextEdit -> Bool
Eq)

deriveJSON lspOptions ''TextEdit

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

{-|
Additional information that describes document changes.

@since 3.16.0
-}
data ChangeAnnotation =
  ChangeAnnotation
    { -- | A human-readable string describing the actual change. The string
      -- is rendered prominent in the user interface.
      ChangeAnnotation -> Text
_label             :: Text
      -- | A flag which indicates that user confirmation is needed
      -- before applying the change.
    , ChangeAnnotation -> Maybe Bool
_needsConfirmation :: Maybe Bool
      -- | A human-readable string which is rendered less prominent in
      -- the user interface.
    , ChangeAnnotation -> Maybe Text
_description       :: Maybe Text
    } deriving (Int -> ChangeAnnotation -> ShowS
[ChangeAnnotation] -> ShowS
ChangeAnnotation -> String
(Int -> ChangeAnnotation -> ShowS)
-> (ChangeAnnotation -> String)
-> ([ChangeAnnotation] -> ShowS)
-> Show ChangeAnnotation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChangeAnnotation -> ShowS
showsPrec :: Int -> ChangeAnnotation -> ShowS
$cshow :: ChangeAnnotation -> String
show :: ChangeAnnotation -> String
$cshowList :: [ChangeAnnotation] -> ShowS
showList :: [ChangeAnnotation] -> ShowS
Show, ReadPrec [ChangeAnnotation]
ReadPrec ChangeAnnotation
Int -> ReadS ChangeAnnotation
ReadS [ChangeAnnotation]
(Int -> ReadS ChangeAnnotation)
-> ReadS [ChangeAnnotation]
-> ReadPrec ChangeAnnotation
-> ReadPrec [ChangeAnnotation]
-> Read ChangeAnnotation
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS ChangeAnnotation
readsPrec :: Int -> ReadS ChangeAnnotation
$creadList :: ReadS [ChangeAnnotation]
readList :: ReadS [ChangeAnnotation]
$creadPrec :: ReadPrec ChangeAnnotation
readPrec :: ReadPrec ChangeAnnotation
$creadListPrec :: ReadPrec [ChangeAnnotation]
readListPrec :: ReadPrec [ChangeAnnotation]
Read, ChangeAnnotation -> ChangeAnnotation -> Bool
(ChangeAnnotation -> ChangeAnnotation -> Bool)
-> (ChangeAnnotation -> ChangeAnnotation -> Bool)
-> Eq ChangeAnnotation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChangeAnnotation -> ChangeAnnotation -> Bool
== :: ChangeAnnotation -> ChangeAnnotation -> Bool
$c/= :: ChangeAnnotation -> ChangeAnnotation -> Bool
/= :: ChangeAnnotation -> ChangeAnnotation -> Bool
Eq)

deriveJSON lspOptions ''ChangeAnnotation

{-|
An identifier referring to a change annotation managed by a workspace
edit.

@since 3.16.0
-}
newtype ChangeAnnotationIdentifier = ChangeAnnotationIdentifierId Text
  deriving (Int -> ChangeAnnotationIdentifier -> ShowS
[ChangeAnnotationIdentifier] -> ShowS
ChangeAnnotationIdentifier -> String
(Int -> ChangeAnnotationIdentifier -> ShowS)
-> (ChangeAnnotationIdentifier -> String)
-> ([ChangeAnnotationIdentifier] -> ShowS)
-> Show ChangeAnnotationIdentifier
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChangeAnnotationIdentifier -> ShowS
showsPrec :: Int -> ChangeAnnotationIdentifier -> ShowS
$cshow :: ChangeAnnotationIdentifier -> String
show :: ChangeAnnotationIdentifier -> String
$cshowList :: [ChangeAnnotationIdentifier] -> ShowS
showList :: [ChangeAnnotationIdentifier] -> ShowS
Show, ReadPrec [ChangeAnnotationIdentifier]
ReadPrec ChangeAnnotationIdentifier
Int -> ReadS ChangeAnnotationIdentifier
ReadS [ChangeAnnotationIdentifier]
(Int -> ReadS ChangeAnnotationIdentifier)
-> ReadS [ChangeAnnotationIdentifier]
-> ReadPrec ChangeAnnotationIdentifier
-> ReadPrec [ChangeAnnotationIdentifier]
-> Read ChangeAnnotationIdentifier
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS ChangeAnnotationIdentifier
readsPrec :: Int -> ReadS ChangeAnnotationIdentifier
$creadList :: ReadS [ChangeAnnotationIdentifier]
readList :: ReadS [ChangeAnnotationIdentifier]
$creadPrec :: ReadPrec ChangeAnnotationIdentifier
readPrec :: ReadPrec ChangeAnnotationIdentifier
$creadListPrec :: ReadPrec [ChangeAnnotationIdentifier]
readListPrec :: ReadPrec [ChangeAnnotationIdentifier]
Read, ChangeAnnotationIdentifier -> ChangeAnnotationIdentifier -> Bool
(ChangeAnnotationIdentifier -> ChangeAnnotationIdentifier -> Bool)
-> (ChangeAnnotationIdentifier
    -> ChangeAnnotationIdentifier -> Bool)
-> Eq ChangeAnnotationIdentifier
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChangeAnnotationIdentifier -> ChangeAnnotationIdentifier -> Bool
== :: ChangeAnnotationIdentifier -> ChangeAnnotationIdentifier -> Bool
$c/= :: ChangeAnnotationIdentifier -> ChangeAnnotationIdentifier -> Bool
/= :: ChangeAnnotationIdentifier -> ChangeAnnotationIdentifier -> Bool
Eq, Maybe ChangeAnnotationIdentifier
Value -> Parser [ChangeAnnotationIdentifier]
Value -> Parser ChangeAnnotationIdentifier
(Value -> Parser ChangeAnnotationIdentifier)
-> (Value -> Parser [ChangeAnnotationIdentifier])
-> Maybe ChangeAnnotationIdentifier
-> FromJSON ChangeAnnotationIdentifier
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser ChangeAnnotationIdentifier
parseJSON :: Value -> Parser ChangeAnnotationIdentifier
$cparseJSONList :: Value -> Parser [ChangeAnnotationIdentifier]
parseJSONList :: Value -> Parser [ChangeAnnotationIdentifier]
$comittedField :: Maybe ChangeAnnotationIdentifier
omittedField :: Maybe ChangeAnnotationIdentifier
FromJSON, [ChangeAnnotationIdentifier] -> Encoding
[ChangeAnnotationIdentifier] -> Value
ChangeAnnotationIdentifier -> Bool
ChangeAnnotationIdentifier -> Encoding
ChangeAnnotationIdentifier -> Value
(ChangeAnnotationIdentifier -> Value)
-> (ChangeAnnotationIdentifier -> Encoding)
-> ([ChangeAnnotationIdentifier] -> Value)
-> ([ChangeAnnotationIdentifier] -> Encoding)
-> (ChangeAnnotationIdentifier -> Bool)
-> ToJSON ChangeAnnotationIdentifier
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: ChangeAnnotationIdentifier -> Value
toJSON :: ChangeAnnotationIdentifier -> Value
$ctoEncoding :: ChangeAnnotationIdentifier -> Encoding
toEncoding :: ChangeAnnotationIdentifier -> Encoding
$ctoJSONList :: [ChangeAnnotationIdentifier] -> Value
toJSONList :: [ChangeAnnotationIdentifier] -> Value
$ctoEncodingList :: [ChangeAnnotationIdentifier] -> Encoding
toEncodingList :: [ChangeAnnotationIdentifier] -> Encoding
$comitField :: ChangeAnnotationIdentifier -> Bool
omitField :: ChangeAnnotationIdentifier -> Bool
ToJSON, ToJSONKeyFunction [ChangeAnnotationIdentifier]
ToJSONKeyFunction ChangeAnnotationIdentifier
ToJSONKeyFunction ChangeAnnotationIdentifier
-> ToJSONKeyFunction [ChangeAnnotationIdentifier]
-> ToJSONKey ChangeAnnotationIdentifier
forall a.
ToJSONKeyFunction a -> ToJSONKeyFunction [a] -> ToJSONKey a
$ctoJSONKey :: ToJSONKeyFunction ChangeAnnotationIdentifier
toJSONKey :: ToJSONKeyFunction ChangeAnnotationIdentifier
$ctoJSONKeyList :: ToJSONKeyFunction [ChangeAnnotationIdentifier]
toJSONKeyList :: ToJSONKeyFunction [ChangeAnnotationIdentifier]
ToJSONKey, FromJSONKeyFunction [ChangeAnnotationIdentifier]
FromJSONKeyFunction ChangeAnnotationIdentifier
FromJSONKeyFunction ChangeAnnotationIdentifier
-> FromJSONKeyFunction [ChangeAnnotationIdentifier]
-> FromJSONKey ChangeAnnotationIdentifier
forall a.
FromJSONKeyFunction a -> FromJSONKeyFunction [a] -> FromJSONKey a
$cfromJSONKey :: FromJSONKeyFunction ChangeAnnotationIdentifier
fromJSONKey :: FromJSONKeyFunction ChangeAnnotationIdentifier
$cfromJSONKeyList :: FromJSONKeyFunction [ChangeAnnotationIdentifier]
fromJSONKeyList :: FromJSONKeyFunction [ChangeAnnotationIdentifier]
FromJSONKey, Eq ChangeAnnotationIdentifier
Eq ChangeAnnotationIdentifier =>
(Int -> ChangeAnnotationIdentifier -> Int)
-> (ChangeAnnotationIdentifier -> Int)
-> Hashable ChangeAnnotationIdentifier
Int -> ChangeAnnotationIdentifier -> Int
ChangeAnnotationIdentifier -> Int
forall a. Eq a => (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> ChangeAnnotationIdentifier -> Int
hashWithSalt :: Int -> ChangeAnnotationIdentifier -> Int
$chash :: ChangeAnnotationIdentifier -> Int
hash :: ChangeAnnotationIdentifier -> Int
Hashable)

makeExtendingDatatype "AnnotatedTextEdit" [''TextEdit]
  [("_annotationId", [t| ChangeAnnotationIdentifier |]) ]
deriveJSON lspOptions ''AnnotatedTextEdit

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

data TextDocumentEdit =
  TextDocumentEdit
    { TextDocumentEdit -> VersionedTextDocumentIdentifier
_textDocument :: VersionedTextDocumentIdentifier
    , TextDocumentEdit -> List (TextEdit |? AnnotatedTextEdit)
_edits        :: List (TextEdit |? AnnotatedTextEdit)
    } deriving (Int -> TextDocumentEdit -> ShowS
[TextDocumentEdit] -> ShowS
TextDocumentEdit -> String
(Int -> TextDocumentEdit -> ShowS)
-> (TextDocumentEdit -> String)
-> ([TextDocumentEdit] -> ShowS)
-> Show TextDocumentEdit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextDocumentEdit -> ShowS
showsPrec :: Int -> TextDocumentEdit -> ShowS
$cshow :: TextDocumentEdit -> String
show :: TextDocumentEdit -> String
$cshowList :: [TextDocumentEdit] -> ShowS
showList :: [TextDocumentEdit] -> ShowS
Show, ReadPrec [TextDocumentEdit]
ReadPrec TextDocumentEdit
Int -> ReadS TextDocumentEdit
ReadS [TextDocumentEdit]
(Int -> ReadS TextDocumentEdit)
-> ReadS [TextDocumentEdit]
-> ReadPrec TextDocumentEdit
-> ReadPrec [TextDocumentEdit]
-> Read TextDocumentEdit
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS TextDocumentEdit
readsPrec :: Int -> ReadS TextDocumentEdit
$creadList :: ReadS [TextDocumentEdit]
readList :: ReadS [TextDocumentEdit]
$creadPrec :: ReadPrec TextDocumentEdit
readPrec :: ReadPrec TextDocumentEdit
$creadListPrec :: ReadPrec [TextDocumentEdit]
readListPrec :: ReadPrec [TextDocumentEdit]
Read, TextDocumentEdit -> TextDocumentEdit -> Bool
(TextDocumentEdit -> TextDocumentEdit -> Bool)
-> (TextDocumentEdit -> TextDocumentEdit -> Bool)
-> Eq TextDocumentEdit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextDocumentEdit -> TextDocumentEdit -> Bool
== :: TextDocumentEdit -> TextDocumentEdit -> Bool
$c/= :: TextDocumentEdit -> TextDocumentEdit -> Bool
/= :: TextDocumentEdit -> TextDocumentEdit -> Bool
Eq)

deriveJSON lspOptions ''TextDocumentEdit

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

-- | Options to create a file.
data CreateFileOptions =
  CreateFileOptions
    { -- | Overwrite existing file. Overwrite wins over `ignoreIfExists`
      CreateFileOptions -> Maybe Bool
_overwrite      :: Maybe Bool
      -- | Ignore if exists.
    , CreateFileOptions -> Maybe Bool
_ignoreIfExists :: Maybe Bool
    } deriving (Int -> CreateFileOptions -> ShowS
[CreateFileOptions] -> ShowS
CreateFileOptions -> String
(Int -> CreateFileOptions -> ShowS)
-> (CreateFileOptions -> String)
-> ([CreateFileOptions] -> ShowS)
-> Show CreateFileOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CreateFileOptions -> ShowS
showsPrec :: Int -> CreateFileOptions -> ShowS
$cshow :: CreateFileOptions -> String
show :: CreateFileOptions -> String
$cshowList :: [CreateFileOptions] -> ShowS
showList :: [CreateFileOptions] -> ShowS
Show, ReadPrec [CreateFileOptions]
ReadPrec CreateFileOptions
Int -> ReadS CreateFileOptions
ReadS [CreateFileOptions]
(Int -> ReadS CreateFileOptions)
-> ReadS [CreateFileOptions]
-> ReadPrec CreateFileOptions
-> ReadPrec [CreateFileOptions]
-> Read CreateFileOptions
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS CreateFileOptions
readsPrec :: Int -> ReadS CreateFileOptions
$creadList :: ReadS [CreateFileOptions]
readList :: ReadS [CreateFileOptions]
$creadPrec :: ReadPrec CreateFileOptions
readPrec :: ReadPrec CreateFileOptions
$creadListPrec :: ReadPrec [CreateFileOptions]
readListPrec :: ReadPrec [CreateFileOptions]
Read, CreateFileOptions -> CreateFileOptions -> Bool
(CreateFileOptions -> CreateFileOptions -> Bool)
-> (CreateFileOptions -> CreateFileOptions -> Bool)
-> Eq CreateFileOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CreateFileOptions -> CreateFileOptions -> Bool
== :: CreateFileOptions -> CreateFileOptions -> Bool
$c/= :: CreateFileOptions -> CreateFileOptions -> Bool
/= :: CreateFileOptions -> CreateFileOptions -> Bool
Eq)

deriveJSON lspOptions ''CreateFileOptions

-- | Create file operation
data CreateFile =
  CreateFile
    { -- | The resource to create.
      CreateFile -> Uri
_uri      :: Uri
      -- | Additional options
    , CreateFile -> Maybe CreateFileOptions
_options  :: Maybe CreateFileOptions
      -- | An optional annotation identifer describing the operation.
      --
      -- @since 3.16.0
    , CreateFile -> Maybe ChangeAnnotationIdentifier
_annotationId  :: Maybe ChangeAnnotationIdentifier
    } deriving (Int -> CreateFile -> ShowS
[CreateFile] -> ShowS
CreateFile -> String
(Int -> CreateFile -> ShowS)
-> (CreateFile -> String)
-> ([CreateFile] -> ShowS)
-> Show CreateFile
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CreateFile -> ShowS
showsPrec :: Int -> CreateFile -> ShowS
$cshow :: CreateFile -> String
show :: CreateFile -> String
$cshowList :: [CreateFile] -> ShowS
showList :: [CreateFile] -> ShowS
Show, ReadPrec [CreateFile]
ReadPrec CreateFile
Int -> ReadS CreateFile
ReadS [CreateFile]
(Int -> ReadS CreateFile)
-> ReadS [CreateFile]
-> ReadPrec CreateFile
-> ReadPrec [CreateFile]
-> Read CreateFile
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS CreateFile
readsPrec :: Int -> ReadS CreateFile
$creadList :: ReadS [CreateFile]
readList :: ReadS [CreateFile]
$creadPrec :: ReadPrec CreateFile
readPrec :: ReadPrec CreateFile
$creadListPrec :: ReadPrec [CreateFile]
readListPrec :: ReadPrec [CreateFile]
Read, CreateFile -> CreateFile -> Bool
(CreateFile -> CreateFile -> Bool)
-> (CreateFile -> CreateFile -> Bool) -> Eq CreateFile
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CreateFile -> CreateFile -> Bool
== :: CreateFile -> CreateFile -> Bool
$c/= :: CreateFile -> CreateFile -> Bool
/= :: CreateFile -> CreateFile -> Bool
Eq)

instance ToJSON CreateFile where
    toJSON :: CreateFile -> Value
toJSON CreateFile{Maybe ChangeAnnotationIdentifier
Maybe CreateFileOptions
Uri
_uri :: CreateFile -> Uri
_options :: CreateFile -> Maybe CreateFileOptions
_annotationId :: CreateFile -> Maybe ChangeAnnotationIdentifier
_uri :: Uri
_options :: Maybe CreateFileOptions
_annotationId :: Maybe ChangeAnnotationIdentifier
..} =
      [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$ [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
catMaybes
        [ Pair -> Maybe Pair
forall a. a -> Maybe a
Just (Pair -> Maybe Pair) -> Pair -> Maybe Pair
forall a b. (a -> b) -> a -> b
$ Key
"kind" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"create" :: Text)
        , Pair -> Maybe Pair
forall a. a -> Maybe a
Just (Pair -> Maybe Pair) -> Pair -> Maybe Pair
forall a b. (a -> b) -> a -> b
$ Key
"uri" Key -> Uri -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Uri
_uri
        , (Key
"options" Key -> CreateFileOptions -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (CreateFileOptions -> Pair)
-> Maybe CreateFileOptions -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe CreateFileOptions
_options
        , (Key
"annotationId" Key -> ChangeAnnotationIdentifier -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (ChangeAnnotationIdentifier -> Pair)
-> Maybe ChangeAnnotationIdentifier -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe ChangeAnnotationIdentifier
_annotationId
        ]

instance FromJSON CreateFile where
    parseJSON :: Value -> Parser CreateFile
parseJSON = String
-> (Object -> Parser CreateFile) -> Value -> Parser CreateFile
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"CreateFile" ((Object -> Parser CreateFile) -> Value -> Parser CreateFile)
-> (Object -> Parser CreateFile) -> Value -> Parser CreateFile
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Text
kind <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"kind"
        Bool -> Parser () -> Parser ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text
kind Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== (Text
"create" :: Text)) 
          (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser ()) -> String -> Parser ()
forall a b. (a -> b) -> a -> b
$ String
"Expected kind \"create\" but got " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
forall a. Show a => a -> String
show Text
kind
        Uri
_uri <- Object
o Object -> Key -> Parser Uri
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"uri"
        Maybe CreateFileOptions
_options <- Object
o Object -> Key -> Parser (Maybe CreateFileOptions)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"options"
        Maybe ChangeAnnotationIdentifier
_annotationId <- Object
o Object -> Key -> Parser (Maybe ChangeAnnotationIdentifier)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"annotationId"
        CreateFile -> Parser CreateFile
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CreateFile{Maybe ChangeAnnotationIdentifier
Maybe CreateFileOptions
Uri
_uri :: Uri
_options :: Maybe CreateFileOptions
_annotationId :: Maybe ChangeAnnotationIdentifier
_uri :: Uri
_options :: Maybe CreateFileOptions
_annotationId :: Maybe ChangeAnnotationIdentifier
..}

-- Rename file options
data RenameFileOptions =
  RenameFileOptions
    { -- | Overwrite target if existing. Overwrite wins over `ignoreIfExists`
      RenameFileOptions -> Maybe Bool
_overwrite      :: Maybe Bool
      -- | Ignores if target exists.
    , RenameFileOptions -> Maybe Bool
_ignoreIfExists :: Maybe Bool
    } deriving (Int -> RenameFileOptions -> ShowS
[RenameFileOptions] -> ShowS
RenameFileOptions -> String
(Int -> RenameFileOptions -> ShowS)
-> (RenameFileOptions -> String)
-> ([RenameFileOptions] -> ShowS)
-> Show RenameFileOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RenameFileOptions -> ShowS
showsPrec :: Int -> RenameFileOptions -> ShowS
$cshow :: RenameFileOptions -> String
show :: RenameFileOptions -> String
$cshowList :: [RenameFileOptions] -> ShowS
showList :: [RenameFileOptions] -> ShowS
Show, ReadPrec [RenameFileOptions]
ReadPrec RenameFileOptions
Int -> ReadS RenameFileOptions
ReadS [RenameFileOptions]
(Int -> ReadS RenameFileOptions)
-> ReadS [RenameFileOptions]
-> ReadPrec RenameFileOptions
-> ReadPrec [RenameFileOptions]
-> Read RenameFileOptions
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS RenameFileOptions
readsPrec :: Int -> ReadS RenameFileOptions
$creadList :: ReadS [RenameFileOptions]
readList :: ReadS [RenameFileOptions]
$creadPrec :: ReadPrec RenameFileOptions
readPrec :: ReadPrec RenameFileOptions
$creadListPrec :: ReadPrec [RenameFileOptions]
readListPrec :: ReadPrec [RenameFileOptions]
Read, RenameFileOptions -> RenameFileOptions -> Bool
(RenameFileOptions -> RenameFileOptions -> Bool)
-> (RenameFileOptions -> RenameFileOptions -> Bool)
-> Eq RenameFileOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RenameFileOptions -> RenameFileOptions -> Bool
== :: RenameFileOptions -> RenameFileOptions -> Bool
$c/= :: RenameFileOptions -> RenameFileOptions -> Bool
/= :: RenameFileOptions -> RenameFileOptions -> Bool
Eq)

deriveJSON lspOptions ''RenameFileOptions

-- | Rename file operation
data RenameFile =
  RenameFile
    { -- | The old (existing) location.
      RenameFile -> Uri
_oldUri   :: Uri
      -- | The new location.
    , RenameFile -> Uri
_newUri   :: Uri
      -- | Rename options.
    , RenameFile -> Maybe RenameFileOptions
_options  :: Maybe RenameFileOptions
      -- | An optional annotation identifer describing the operation.
      --
      -- @since 3.16.0
    , RenameFile -> Maybe ChangeAnnotationIdentifier
_annotationId  :: Maybe ChangeAnnotationIdentifier
    } deriving (Int -> RenameFile -> ShowS
[RenameFile] -> ShowS
RenameFile -> String
(Int -> RenameFile -> ShowS)
-> (RenameFile -> String)
-> ([RenameFile] -> ShowS)
-> Show RenameFile
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RenameFile -> ShowS
showsPrec :: Int -> RenameFile -> ShowS
$cshow :: RenameFile -> String
show :: RenameFile -> String
$cshowList :: [RenameFile] -> ShowS
showList :: [RenameFile] -> ShowS
Show, ReadPrec [RenameFile]
ReadPrec RenameFile
Int -> ReadS RenameFile
ReadS [RenameFile]
(Int -> ReadS RenameFile)
-> ReadS [RenameFile]
-> ReadPrec RenameFile
-> ReadPrec [RenameFile]
-> Read RenameFile
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS RenameFile
readsPrec :: Int -> ReadS RenameFile
$creadList :: ReadS [RenameFile]
readList :: ReadS [RenameFile]
$creadPrec :: ReadPrec RenameFile
readPrec :: ReadPrec RenameFile
$creadListPrec :: ReadPrec [RenameFile]
readListPrec :: ReadPrec [RenameFile]
Read, RenameFile -> RenameFile -> Bool
(RenameFile -> RenameFile -> Bool)
-> (RenameFile -> RenameFile -> Bool) -> Eq RenameFile
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RenameFile -> RenameFile -> Bool
== :: RenameFile -> RenameFile -> Bool
$c/= :: RenameFile -> RenameFile -> Bool
/= :: RenameFile -> RenameFile -> Bool
Eq)

instance ToJSON RenameFile where
    toJSON :: RenameFile -> Value
toJSON RenameFile{Maybe ChangeAnnotationIdentifier
Maybe RenameFileOptions
Uri
_oldUri :: RenameFile -> Uri
_newUri :: RenameFile -> Uri
_options :: RenameFile -> Maybe RenameFileOptions
_annotationId :: RenameFile -> Maybe ChangeAnnotationIdentifier
_oldUri :: Uri
_newUri :: Uri
_options :: Maybe RenameFileOptions
_annotationId :: Maybe ChangeAnnotationIdentifier
..} =
      [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$ [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
catMaybes
        [ Pair -> Maybe Pair
forall a. a -> Maybe a
Just (Pair -> Maybe Pair) -> Pair -> Maybe Pair
forall a b. (a -> b) -> a -> b
$ Key
"kind" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"rename" :: Text)
        , Pair -> Maybe Pair
forall a. a -> Maybe a
Just (Pair -> Maybe Pair) -> Pair -> Maybe Pair
forall a b. (a -> b) -> a -> b
$ Key
"oldUri" Key -> Uri -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Uri
_oldUri
        , Pair -> Maybe Pair
forall a. a -> Maybe a
Just (Pair -> Maybe Pair) -> Pair -> Maybe Pair
forall a b. (a -> b) -> a -> b
$ Key
"newUri" Key -> Uri -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Uri
_newUri
        , (Key
"options" Key -> RenameFileOptions -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (RenameFileOptions -> Pair)
-> Maybe RenameFileOptions -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe RenameFileOptions
_options
        , (Key
"annotationId" Key -> ChangeAnnotationIdentifier -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (ChangeAnnotationIdentifier -> Pair)
-> Maybe ChangeAnnotationIdentifier -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe ChangeAnnotationIdentifier
_annotationId
        ]

instance FromJSON RenameFile where
    parseJSON :: Value -> Parser RenameFile
parseJSON = String
-> (Object -> Parser RenameFile) -> Value -> Parser RenameFile
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"RenameFile" ((Object -> Parser RenameFile) -> Value -> Parser RenameFile)
-> (Object -> Parser RenameFile) -> Value -> Parser RenameFile
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Text
kind <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"kind"
        Bool -> Parser () -> Parser ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text
kind Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== (Text
"rename" :: Text)) 
          (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser ()) -> String -> Parser ()
forall a b. (a -> b) -> a -> b
$ String
"Expected kind \"rename\" but got " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
forall a. Show a => a -> String
show Text
kind
        Uri
_oldUri <- Object
o Object -> Key -> Parser Uri
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"oldUri"
        Uri
_newUri <- Object
o Object -> Key -> Parser Uri
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"newUri"
        Maybe RenameFileOptions
_options <- Object
o Object -> Key -> Parser (Maybe RenameFileOptions)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"options"
        Maybe ChangeAnnotationIdentifier
_annotationId <- Object
o Object -> Key -> Parser (Maybe ChangeAnnotationIdentifier)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"annotationId"
        RenameFile -> Parser RenameFile
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure RenameFile{Maybe ChangeAnnotationIdentifier
Maybe RenameFileOptions
Uri
_oldUri :: Uri
_newUri :: Uri
_options :: Maybe RenameFileOptions
_annotationId :: Maybe ChangeAnnotationIdentifier
_oldUri :: Uri
_newUri :: Uri
_options :: Maybe RenameFileOptions
_annotationId :: Maybe ChangeAnnotationIdentifier
..}

-- Delete file options
data DeleteFileOptions =
  DeleteFileOptions
    { -- | Delete the content recursively if a folder is denoted.
      DeleteFileOptions -> Maybe Bool
_recursive          :: Maybe Bool
      -- | Ignore the operation if the file doesn't exist.
    , DeleteFileOptions -> Maybe Bool
_ignoreIfNotExists  :: Maybe Bool
    } deriving (Int -> DeleteFileOptions -> ShowS
[DeleteFileOptions] -> ShowS
DeleteFileOptions -> String
(Int -> DeleteFileOptions -> ShowS)
-> (DeleteFileOptions -> String)
-> ([DeleteFileOptions] -> ShowS)
-> Show DeleteFileOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DeleteFileOptions -> ShowS
showsPrec :: Int -> DeleteFileOptions -> ShowS
$cshow :: DeleteFileOptions -> String
show :: DeleteFileOptions -> String
$cshowList :: [DeleteFileOptions] -> ShowS
showList :: [DeleteFileOptions] -> ShowS
Show, ReadPrec [DeleteFileOptions]
ReadPrec DeleteFileOptions
Int -> ReadS DeleteFileOptions
ReadS [DeleteFileOptions]
(Int -> ReadS DeleteFileOptions)
-> ReadS [DeleteFileOptions]
-> ReadPrec DeleteFileOptions
-> ReadPrec [DeleteFileOptions]
-> Read DeleteFileOptions
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS DeleteFileOptions
readsPrec :: Int -> ReadS DeleteFileOptions
$creadList :: ReadS [DeleteFileOptions]
readList :: ReadS [DeleteFileOptions]
$creadPrec :: ReadPrec DeleteFileOptions
readPrec :: ReadPrec DeleteFileOptions
$creadListPrec :: ReadPrec [DeleteFileOptions]
readListPrec :: ReadPrec [DeleteFileOptions]
Read, DeleteFileOptions -> DeleteFileOptions -> Bool
(DeleteFileOptions -> DeleteFileOptions -> Bool)
-> (DeleteFileOptions -> DeleteFileOptions -> Bool)
-> Eq DeleteFileOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DeleteFileOptions -> DeleteFileOptions -> Bool
== :: DeleteFileOptions -> DeleteFileOptions -> Bool
$c/= :: DeleteFileOptions -> DeleteFileOptions -> Bool
/= :: DeleteFileOptions -> DeleteFileOptions -> Bool
Eq)

deriveJSON lspOptions ''DeleteFileOptions

-- | Delete file operation
data DeleteFile =
  DeleteFile
    { -- | The file to delete.
      DeleteFile -> Uri
_uri      :: Uri
      -- | Delete options.
    , DeleteFile -> Maybe DeleteFileOptions
_options  :: Maybe DeleteFileOptions
      -- | An optional annotation identifer describing the operation.
      --
      -- @since 3.16.0
    , DeleteFile -> Maybe ChangeAnnotationIdentifier
_annotationId  :: Maybe ChangeAnnotationIdentifier
    } deriving (Int -> DeleteFile -> ShowS
[DeleteFile] -> ShowS
DeleteFile -> String
(Int -> DeleteFile -> ShowS)
-> (DeleteFile -> String)
-> ([DeleteFile] -> ShowS)
-> Show DeleteFile
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DeleteFile -> ShowS
showsPrec :: Int -> DeleteFile -> ShowS
$cshow :: DeleteFile -> String
show :: DeleteFile -> String
$cshowList :: [DeleteFile] -> ShowS
showList :: [DeleteFile] -> ShowS
Show, ReadPrec [DeleteFile]
ReadPrec DeleteFile
Int -> ReadS DeleteFile
ReadS [DeleteFile]
(Int -> ReadS DeleteFile)
-> ReadS [DeleteFile]
-> ReadPrec DeleteFile
-> ReadPrec [DeleteFile]
-> Read DeleteFile
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS DeleteFile
readsPrec :: Int -> ReadS DeleteFile
$creadList :: ReadS [DeleteFile]
readList :: ReadS [DeleteFile]
$creadPrec :: ReadPrec DeleteFile
readPrec :: ReadPrec DeleteFile
$creadListPrec :: ReadPrec [DeleteFile]
readListPrec :: ReadPrec [DeleteFile]
Read, DeleteFile -> DeleteFile -> Bool
(DeleteFile -> DeleteFile -> Bool)
-> (DeleteFile -> DeleteFile -> Bool) -> Eq DeleteFile
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DeleteFile -> DeleteFile -> Bool
== :: DeleteFile -> DeleteFile -> Bool
$c/= :: DeleteFile -> DeleteFile -> Bool
/= :: DeleteFile -> DeleteFile -> Bool
Eq)

instance ToJSON DeleteFile where
    toJSON :: DeleteFile -> Value
toJSON DeleteFile{Maybe ChangeAnnotationIdentifier
Maybe DeleteFileOptions
Uri
_uri :: DeleteFile -> Uri
_options :: DeleteFile -> Maybe DeleteFileOptions
_annotationId :: DeleteFile -> Maybe ChangeAnnotationIdentifier
_uri :: Uri
_options :: Maybe DeleteFileOptions
_annotationId :: Maybe ChangeAnnotationIdentifier
..} =
      [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$ [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
catMaybes
        [ Pair -> Maybe Pair
forall a. a -> Maybe a
Just (Pair -> Maybe Pair) -> Pair -> Maybe Pair
forall a b. (a -> b) -> a -> b
$ Key
"kind" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= (Text
"delete" :: Text)
        , Pair -> Maybe Pair
forall a. a -> Maybe a
Just (Pair -> Maybe Pair) -> Pair -> Maybe Pair
forall a b. (a -> b) -> a -> b
$ Key
"uri" Key -> Uri -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.= Uri
_uri
        , (Key
"options" Key -> DeleteFileOptions -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (DeleteFileOptions -> Pair)
-> Maybe DeleteFileOptions -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe DeleteFileOptions
_options
        , (Key
"annotationId" Key -> ChangeAnnotationIdentifier -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
.=) (ChangeAnnotationIdentifier -> Pair)
-> Maybe ChangeAnnotationIdentifier -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe ChangeAnnotationIdentifier
_annotationId
        ]

instance FromJSON DeleteFile where
    parseJSON :: Value -> Parser DeleteFile
parseJSON = String
-> (Object -> Parser DeleteFile) -> Value -> Parser DeleteFile
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"DeleteFile" ((Object -> Parser DeleteFile) -> Value -> Parser DeleteFile)
-> (Object -> Parser DeleteFile) -> Value -> Parser DeleteFile
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Text
kind <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"kind"
        Bool -> Parser () -> Parser ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text
kind Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== (Text
"delete" :: Text)) 
          (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ String -> Parser ()
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser ()) -> String -> Parser ()
forall a b. (a -> b) -> a -> b
$ String
"Expected kind \"delete\" but got " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
forall a. Show a => a -> String
show Text
kind
        Uri
_uri <- Object
o Object -> Key -> Parser Uri
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"uri"
        Maybe DeleteFileOptions
_options <- Object
o Object -> Key -> Parser (Maybe DeleteFileOptions)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"options"
        Maybe ChangeAnnotationIdentifier
_annotationId <- Object
o Object -> Key -> Parser (Maybe ChangeAnnotationIdentifier)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"annotationId"
        DeleteFile -> Parser DeleteFile
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure DeleteFile{Maybe ChangeAnnotationIdentifier
Maybe DeleteFileOptions
Uri
_uri :: Uri
_options :: Maybe DeleteFileOptions
_annotationId :: Maybe ChangeAnnotationIdentifier
_uri :: Uri
_options :: Maybe DeleteFileOptions
_annotationId :: Maybe ChangeAnnotationIdentifier
..}

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

-- | `TextDocumentEdit |? CreateFile |? RenameFile |? DeleteFile` is a bit mouthful, here's the synonym
type DocumentChange = TextDocumentEdit |? CreateFile |? RenameFile |? DeleteFile

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

type WorkspaceEditMap = H.HashMap Uri (List TextEdit)
type ChangeAnnotationMap = H.HashMap ChangeAnnotationIdentifier ChangeAnnotation

data WorkspaceEdit =
  WorkspaceEdit
    {
      -- | Holds changes to existing resources.
      WorkspaceEdit -> Maybe WorkspaceEditMap
_changes           :: Maybe WorkspaceEditMap
      -- | Depending on the client capability
      -- `workspace.workspaceEdit.resourceOperations` document changes are either
      -- an array of `TextDocumentEdit`s to express changes to n different text
      -- documents where each text document edit addresses a specific version of
      -- a text document. Or it can contain above `TextDocumentEdit`s mixed with
      -- create, rename and delete file / folder operations.
      --
      -- Whether a client supports versioned document edits is expressed via
      -- `workspace.workspaceEdit.documentChanges` client capability.
      --
      -- If a client neither supports `documentChanges` nor
      -- `workspace.workspaceEdit.resourceOperations` then only plain `TextEdit`s
      -- using the `changes` property are supported.
    , WorkspaceEdit -> Maybe (List DocumentChange)
_documentChanges   :: Maybe (List DocumentChange)
      -- | A map of change annotations that can be referenced in
      -- `AnnotatedTextEdit`s or create, rename and delete file / folder
      -- operations.
      --
      -- Whether clients honor this property depends on the client capability
      -- `workspace.changeAnnotationSupport`.
      --
      -- @since 3.16.0
    , WorkspaceEdit -> Maybe ChangeAnnotationMap
_changeAnnotations :: Maybe ChangeAnnotationMap
    } deriving (Int -> WorkspaceEdit -> ShowS
[WorkspaceEdit] -> ShowS
WorkspaceEdit -> String
(Int -> WorkspaceEdit -> ShowS)
-> (WorkspaceEdit -> String)
-> ([WorkspaceEdit] -> ShowS)
-> Show WorkspaceEdit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> WorkspaceEdit -> ShowS
showsPrec :: Int -> WorkspaceEdit -> ShowS
$cshow :: WorkspaceEdit -> String
show :: WorkspaceEdit -> String
$cshowList :: [WorkspaceEdit] -> ShowS
showList :: [WorkspaceEdit] -> ShowS
Show, ReadPrec [WorkspaceEdit]
ReadPrec WorkspaceEdit
Int -> ReadS WorkspaceEdit
ReadS [WorkspaceEdit]
(Int -> ReadS WorkspaceEdit)
-> ReadS [WorkspaceEdit]
-> ReadPrec WorkspaceEdit
-> ReadPrec [WorkspaceEdit]
-> Read WorkspaceEdit
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS WorkspaceEdit
readsPrec :: Int -> ReadS WorkspaceEdit
$creadList :: ReadS [WorkspaceEdit]
readList :: ReadS [WorkspaceEdit]
$creadPrec :: ReadPrec WorkspaceEdit
readPrec :: ReadPrec WorkspaceEdit
$creadListPrec :: ReadPrec [WorkspaceEdit]
readListPrec :: ReadPrec [WorkspaceEdit]
Read, WorkspaceEdit -> WorkspaceEdit -> Bool
(WorkspaceEdit -> WorkspaceEdit -> Bool)
-> (WorkspaceEdit -> WorkspaceEdit -> Bool) -> Eq WorkspaceEdit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: WorkspaceEdit -> WorkspaceEdit -> Bool
== :: WorkspaceEdit -> WorkspaceEdit -> Bool
$c/= :: WorkspaceEdit -> WorkspaceEdit -> Bool
/= :: WorkspaceEdit -> WorkspaceEdit -> Bool
Eq)

instance Semigroup WorkspaceEdit where
  (WorkspaceEdit Maybe WorkspaceEditMap
a Maybe (List DocumentChange)
b Maybe ChangeAnnotationMap
c) <> :: WorkspaceEdit -> WorkspaceEdit -> WorkspaceEdit
<> (WorkspaceEdit Maybe WorkspaceEditMap
a' Maybe (List DocumentChange)
b' Maybe ChangeAnnotationMap
c') = Maybe WorkspaceEditMap
-> Maybe (List DocumentChange)
-> Maybe ChangeAnnotationMap
-> WorkspaceEdit
WorkspaceEdit (Maybe WorkspaceEditMap
a Maybe WorkspaceEditMap
-> Maybe WorkspaceEditMap -> Maybe WorkspaceEditMap
forall a. Semigroup a => a -> a -> a
<> Maybe WorkspaceEditMap
a') (Maybe (List DocumentChange)
b Maybe (List DocumentChange)
-> Maybe (List DocumentChange) -> Maybe (List DocumentChange)
forall a. Semigroup a => a -> a -> a
<> Maybe (List DocumentChange)
b') (Maybe ChangeAnnotationMap
c Maybe ChangeAnnotationMap
-> Maybe ChangeAnnotationMap -> Maybe ChangeAnnotationMap
forall a. Semigroup a => a -> a -> a
<> Maybe ChangeAnnotationMap
c')
instance Monoid WorkspaceEdit where
  mempty :: WorkspaceEdit
mempty = Maybe WorkspaceEditMap
-> Maybe (List DocumentChange)
-> Maybe ChangeAnnotationMap
-> WorkspaceEdit
WorkspaceEdit Maybe WorkspaceEditMap
forall a. Maybe a
Nothing Maybe (List DocumentChange)
forall a. Maybe a
Nothing Maybe ChangeAnnotationMap
forall a. Maybe a
Nothing

deriveJSON lspOptions ''WorkspaceEdit

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

data ResourceOperationKind
  = ResourceOperationCreate -- ^ Supports creating new files and folders.
  | ResourceOperationRename -- ^ Supports renaming existing files and folders.
  | ResourceOperationDelete -- ^ Supports deleting existing files and folders.
  deriving (ReadPrec [ResourceOperationKind]
ReadPrec ResourceOperationKind
Int -> ReadS ResourceOperationKind
ReadS [ResourceOperationKind]
(Int -> ReadS ResourceOperationKind)
-> ReadS [ResourceOperationKind]
-> ReadPrec ResourceOperationKind
-> ReadPrec [ResourceOperationKind]
-> Read ResourceOperationKind
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS ResourceOperationKind
readsPrec :: Int -> ReadS ResourceOperationKind
$creadList :: ReadS [ResourceOperationKind]
readList :: ReadS [ResourceOperationKind]
$creadPrec :: ReadPrec ResourceOperationKind
readPrec :: ReadPrec ResourceOperationKind
$creadListPrec :: ReadPrec [ResourceOperationKind]
readListPrec :: ReadPrec [ResourceOperationKind]
Read, Int -> ResourceOperationKind -> ShowS
[ResourceOperationKind] -> ShowS
ResourceOperationKind -> String
(Int -> ResourceOperationKind -> ShowS)
-> (ResourceOperationKind -> String)
-> ([ResourceOperationKind] -> ShowS)
-> Show ResourceOperationKind
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ResourceOperationKind -> ShowS
showsPrec :: Int -> ResourceOperationKind -> ShowS
$cshow :: ResourceOperationKind -> String
show :: ResourceOperationKind -> String
$cshowList :: [ResourceOperationKind] -> ShowS
showList :: [ResourceOperationKind] -> ShowS
Show, ResourceOperationKind -> ResourceOperationKind -> Bool
(ResourceOperationKind -> ResourceOperationKind -> Bool)
-> (ResourceOperationKind -> ResourceOperationKind -> Bool)
-> Eq ResourceOperationKind
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ResourceOperationKind -> ResourceOperationKind -> Bool
== :: ResourceOperationKind -> ResourceOperationKind -> Bool
$c/= :: ResourceOperationKind -> ResourceOperationKind -> Bool
/= :: ResourceOperationKind -> ResourceOperationKind -> Bool
Eq)
  
instance ToJSON ResourceOperationKind where
  toJSON :: ResourceOperationKind -> Value
toJSON ResourceOperationKind
ResourceOperationCreate = Text -> Value
String Text
"create"
  toJSON ResourceOperationKind
ResourceOperationRename = Text -> Value
String Text
"rename"
  toJSON ResourceOperationKind
ResourceOperationDelete = Text -> Value
String Text
"delete"

instance FromJSON ResourceOperationKind where
  parseJSON :: Value -> Parser ResourceOperationKind
parseJSON (String Text
"create") = ResourceOperationKind -> Parser ResourceOperationKind
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ResourceOperationKind
ResourceOperationCreate
  parseJSON (String Text
"rename") = ResourceOperationKind -> Parser ResourceOperationKind
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ResourceOperationKind
ResourceOperationRename
  parseJSON (String Text
"delete") = ResourceOperationKind -> Parser ResourceOperationKind
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ResourceOperationKind
ResourceOperationDelete
  parseJSON Value
_                 = String -> Parser ResourceOperationKind
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"ResourceOperationKind"

data FailureHandlingKind
  = FailureHandlingAbort -- ^ Applying the workspace change is simply aborted if one of the changes provided fails. All operations executed before the failing operation stay executed.
  | FailureHandlingTransactional -- ^ All operations are executed transactional. That means they either all succeed or no changes at all are applied to the workspace.
  | FailureHandlingTextOnlyTransactional -- ^ If the workspace edit contains only textual file changes they are executed transactional. If resource changes (create, rename or delete file) are part of the change the failure handling strategy is abort.
  | FailureHandlingUndo -- ^ The client tries to undo the operations already executed. But there is no guarantee that this is succeeding.
  deriving (ReadPrec [FailureHandlingKind]
ReadPrec FailureHandlingKind
Int -> ReadS FailureHandlingKind
ReadS [FailureHandlingKind]
(Int -> ReadS FailureHandlingKind)
-> ReadS [FailureHandlingKind]
-> ReadPrec FailureHandlingKind
-> ReadPrec [FailureHandlingKind]
-> Read FailureHandlingKind
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS FailureHandlingKind
readsPrec :: Int -> ReadS FailureHandlingKind
$creadList :: ReadS [FailureHandlingKind]
readList :: ReadS [FailureHandlingKind]
$creadPrec :: ReadPrec FailureHandlingKind
readPrec :: ReadPrec FailureHandlingKind
$creadListPrec :: ReadPrec [FailureHandlingKind]
readListPrec :: ReadPrec [FailureHandlingKind]
Read, Int -> FailureHandlingKind -> ShowS
[FailureHandlingKind] -> ShowS
FailureHandlingKind -> String
(Int -> FailureHandlingKind -> ShowS)
-> (FailureHandlingKind -> String)
-> ([FailureHandlingKind] -> ShowS)
-> Show FailureHandlingKind
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FailureHandlingKind -> ShowS
showsPrec :: Int -> FailureHandlingKind -> ShowS
$cshow :: FailureHandlingKind -> String
show :: FailureHandlingKind -> String
$cshowList :: [FailureHandlingKind] -> ShowS
showList :: [FailureHandlingKind] -> ShowS
Show, FailureHandlingKind -> FailureHandlingKind -> Bool
(FailureHandlingKind -> FailureHandlingKind -> Bool)
-> (FailureHandlingKind -> FailureHandlingKind -> Bool)
-> Eq FailureHandlingKind
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FailureHandlingKind -> FailureHandlingKind -> Bool
== :: FailureHandlingKind -> FailureHandlingKind -> Bool
$c/= :: FailureHandlingKind -> FailureHandlingKind -> Bool
/= :: FailureHandlingKind -> FailureHandlingKind -> Bool
Eq)
  
instance ToJSON FailureHandlingKind where
  toJSON :: FailureHandlingKind -> Value
toJSON FailureHandlingKind
FailureHandlingAbort                 = Text -> Value
String Text
"abort"
  toJSON FailureHandlingKind
FailureHandlingTransactional         = Text -> Value
String Text
"transactional"
  toJSON FailureHandlingKind
FailureHandlingTextOnlyTransactional = Text -> Value
String Text
"textOnlyTransactional"
  toJSON FailureHandlingKind
FailureHandlingUndo                  = Text -> Value
String Text
"undo"

instance FromJSON FailureHandlingKind where
  parseJSON :: Value -> Parser FailureHandlingKind
parseJSON (String Text
"abort")                 = FailureHandlingKind -> Parser FailureHandlingKind
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure FailureHandlingKind
FailureHandlingAbort
  parseJSON (String Text
"transactional")         = FailureHandlingKind -> Parser FailureHandlingKind
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure FailureHandlingKind
FailureHandlingTransactional
  parseJSON (String Text
"textOnlyTransactional") = FailureHandlingKind -> Parser FailureHandlingKind
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure FailureHandlingKind
FailureHandlingTextOnlyTransactional
  parseJSON (String Text
"undo")                  = FailureHandlingKind -> Parser FailureHandlingKind
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure FailureHandlingKind
FailureHandlingUndo
  parseJSON Value
_                                = String -> Parser FailureHandlingKind
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"FailureHandlingKind"

data WorkspaceEditChangeAnnotationClientCapabilities =
  WorkspaceEditChangeAnnotationClientCapabilities
  {
    -- | Whether the client groups edits with equal labels into tree nodes,
    -- for instance all edits labelled with "Changes in Strings" would
    -- be a tree node.
    WorkspaceEditChangeAnnotationClientCapabilities -> Maybe Bool
groupsOnLabel :: Maybe Bool
  } deriving (Int -> WorkspaceEditChangeAnnotationClientCapabilities -> ShowS
[WorkspaceEditChangeAnnotationClientCapabilities] -> ShowS
WorkspaceEditChangeAnnotationClientCapabilities -> String
(Int -> WorkspaceEditChangeAnnotationClientCapabilities -> ShowS)
-> (WorkspaceEditChangeAnnotationClientCapabilities -> String)
-> ([WorkspaceEditChangeAnnotationClientCapabilities] -> ShowS)
-> Show WorkspaceEditChangeAnnotationClientCapabilities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> WorkspaceEditChangeAnnotationClientCapabilities -> ShowS
showsPrec :: Int -> WorkspaceEditChangeAnnotationClientCapabilities -> ShowS
$cshow :: WorkspaceEditChangeAnnotationClientCapabilities -> String
show :: WorkspaceEditChangeAnnotationClientCapabilities -> String
$cshowList :: [WorkspaceEditChangeAnnotationClientCapabilities] -> ShowS
showList :: [WorkspaceEditChangeAnnotationClientCapabilities] -> ShowS
Show, ReadPrec [WorkspaceEditChangeAnnotationClientCapabilities]
ReadPrec WorkspaceEditChangeAnnotationClientCapabilities
Int -> ReadS WorkspaceEditChangeAnnotationClientCapabilities
ReadS [WorkspaceEditChangeAnnotationClientCapabilities]
(Int -> ReadS WorkspaceEditChangeAnnotationClientCapabilities)
-> ReadS [WorkspaceEditChangeAnnotationClientCapabilities]
-> ReadPrec WorkspaceEditChangeAnnotationClientCapabilities
-> ReadPrec [WorkspaceEditChangeAnnotationClientCapabilities]
-> Read WorkspaceEditChangeAnnotationClientCapabilities
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS WorkspaceEditChangeAnnotationClientCapabilities
readsPrec :: Int -> ReadS WorkspaceEditChangeAnnotationClientCapabilities
$creadList :: ReadS [WorkspaceEditChangeAnnotationClientCapabilities]
readList :: ReadS [WorkspaceEditChangeAnnotationClientCapabilities]
$creadPrec :: ReadPrec WorkspaceEditChangeAnnotationClientCapabilities
readPrec :: ReadPrec WorkspaceEditChangeAnnotationClientCapabilities
$creadListPrec :: ReadPrec [WorkspaceEditChangeAnnotationClientCapabilities]
readListPrec :: ReadPrec [WorkspaceEditChangeAnnotationClientCapabilities]
Read, WorkspaceEditChangeAnnotationClientCapabilities
-> WorkspaceEditChangeAnnotationClientCapabilities -> Bool
(WorkspaceEditChangeAnnotationClientCapabilities
 -> WorkspaceEditChangeAnnotationClientCapabilities -> Bool)
-> (WorkspaceEditChangeAnnotationClientCapabilities
    -> WorkspaceEditChangeAnnotationClientCapabilities -> Bool)
-> Eq WorkspaceEditChangeAnnotationClientCapabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: WorkspaceEditChangeAnnotationClientCapabilities
-> WorkspaceEditChangeAnnotationClientCapabilities -> Bool
== :: WorkspaceEditChangeAnnotationClientCapabilities
-> WorkspaceEditChangeAnnotationClientCapabilities -> Bool
$c/= :: WorkspaceEditChangeAnnotationClientCapabilities
-> WorkspaceEditChangeAnnotationClientCapabilities -> Bool
/= :: WorkspaceEditChangeAnnotationClientCapabilities
-> WorkspaceEditChangeAnnotationClientCapabilities -> Bool
Eq)

deriveJSON lspOptions ''WorkspaceEditChangeAnnotationClientCapabilities

data WorkspaceEditClientCapabilities =
  WorkspaceEditClientCapabilities
  { WorkspaceEditClientCapabilities -> Maybe Bool
_documentChanges :: Maybe Bool -- ^The client supports versioned document
                                   -- changes in 'WorkspaceEdit's
    -- | The resource operations the client supports. Clients should at least
    -- support @create@, @rename@ and @delete@ files and folders.
  , WorkspaceEditClientCapabilities
-> Maybe (List ResourceOperationKind)
_resourceOperations :: Maybe (List ResourceOperationKind)
    -- | The failure handling strategy of a client if applying the workspace edit
    -- fails.
  , WorkspaceEditClientCapabilities -> Maybe FailureHandlingKind
_failureHandling :: Maybe FailureHandlingKind
    -- | Whether the client normalizes line endings to the client specific
    -- setting.
    --
    -- If set to `true` the client will normalize line ending characters
    -- in a workspace edit to the client specific new line character(s).
    --
    -- @since 3.16.0
  , WorkspaceEditClientCapabilities -> Maybe Bool
_normalizesLineEndings :: Maybe Bool
    -- | Whether the client in general supports change annotations on text edits,
    -- create file, rename file and delete file changes.
    --
    -- @since 3.16.0
  , WorkspaceEditClientCapabilities
-> Maybe WorkspaceEditChangeAnnotationClientCapabilities
_changeAnnotationSupport :: Maybe WorkspaceEditChangeAnnotationClientCapabilities
  } deriving (Int -> WorkspaceEditClientCapabilities -> ShowS
[WorkspaceEditClientCapabilities] -> ShowS
WorkspaceEditClientCapabilities -> String
(Int -> WorkspaceEditClientCapabilities -> ShowS)
-> (WorkspaceEditClientCapabilities -> String)
-> ([WorkspaceEditClientCapabilities] -> ShowS)
-> Show WorkspaceEditClientCapabilities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> WorkspaceEditClientCapabilities -> ShowS
showsPrec :: Int -> WorkspaceEditClientCapabilities -> ShowS
$cshow :: WorkspaceEditClientCapabilities -> String
show :: WorkspaceEditClientCapabilities -> String
$cshowList :: [WorkspaceEditClientCapabilities] -> ShowS
showList :: [WorkspaceEditClientCapabilities] -> ShowS
Show, ReadPrec [WorkspaceEditClientCapabilities]
ReadPrec WorkspaceEditClientCapabilities
Int -> ReadS WorkspaceEditClientCapabilities
ReadS [WorkspaceEditClientCapabilities]
(Int -> ReadS WorkspaceEditClientCapabilities)
-> ReadS [WorkspaceEditClientCapabilities]
-> ReadPrec WorkspaceEditClientCapabilities
-> ReadPrec [WorkspaceEditClientCapabilities]
-> Read WorkspaceEditClientCapabilities
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS WorkspaceEditClientCapabilities
readsPrec :: Int -> ReadS WorkspaceEditClientCapabilities
$creadList :: ReadS [WorkspaceEditClientCapabilities]
readList :: ReadS [WorkspaceEditClientCapabilities]
$creadPrec :: ReadPrec WorkspaceEditClientCapabilities
readPrec :: ReadPrec WorkspaceEditClientCapabilities
$creadListPrec :: ReadPrec [WorkspaceEditClientCapabilities]
readListPrec :: ReadPrec [WorkspaceEditClientCapabilities]
Read, WorkspaceEditClientCapabilities
-> WorkspaceEditClientCapabilities -> Bool
(WorkspaceEditClientCapabilities
 -> WorkspaceEditClientCapabilities -> Bool)
-> (WorkspaceEditClientCapabilities
    -> WorkspaceEditClientCapabilities -> Bool)
-> Eq WorkspaceEditClientCapabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: WorkspaceEditClientCapabilities
-> WorkspaceEditClientCapabilities -> Bool
== :: WorkspaceEditClientCapabilities
-> WorkspaceEditClientCapabilities -> Bool
$c/= :: WorkspaceEditClientCapabilities
-> WorkspaceEditClientCapabilities -> Bool
/= :: WorkspaceEditClientCapabilities
-> WorkspaceEditClientCapabilities -> Bool
Eq)

deriveJSON lspOptions ''WorkspaceEditClientCapabilities

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

data ApplyWorkspaceEditParams =
  ApplyWorkspaceEditParams
    { -- | An optional label of the workspace edit. This label is
      -- presented in the user interface for example on an undo
      -- stack to undo the workspace edit.
      ApplyWorkspaceEditParams -> Maybe Text
_label :: Maybe Text
      -- | The edits to apply
    , ApplyWorkspaceEditParams -> WorkspaceEdit
_edit :: WorkspaceEdit
    } deriving (Int -> ApplyWorkspaceEditParams -> ShowS
[ApplyWorkspaceEditParams] -> ShowS
ApplyWorkspaceEditParams -> String
(Int -> ApplyWorkspaceEditParams -> ShowS)
-> (ApplyWorkspaceEditParams -> String)
-> ([ApplyWorkspaceEditParams] -> ShowS)
-> Show ApplyWorkspaceEditParams
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ApplyWorkspaceEditParams -> ShowS
showsPrec :: Int -> ApplyWorkspaceEditParams -> ShowS
$cshow :: ApplyWorkspaceEditParams -> String
show :: ApplyWorkspaceEditParams -> String
$cshowList :: [ApplyWorkspaceEditParams] -> ShowS
showList :: [ApplyWorkspaceEditParams] -> ShowS
Show, ReadPrec [ApplyWorkspaceEditParams]
ReadPrec ApplyWorkspaceEditParams
Int -> ReadS ApplyWorkspaceEditParams
ReadS [ApplyWorkspaceEditParams]
(Int -> ReadS ApplyWorkspaceEditParams)
-> ReadS [ApplyWorkspaceEditParams]
-> ReadPrec ApplyWorkspaceEditParams
-> ReadPrec [ApplyWorkspaceEditParams]
-> Read ApplyWorkspaceEditParams
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS ApplyWorkspaceEditParams
readsPrec :: Int -> ReadS ApplyWorkspaceEditParams
$creadList :: ReadS [ApplyWorkspaceEditParams]
readList :: ReadS [ApplyWorkspaceEditParams]
$creadPrec :: ReadPrec ApplyWorkspaceEditParams
readPrec :: ReadPrec ApplyWorkspaceEditParams
$creadListPrec :: ReadPrec [ApplyWorkspaceEditParams]
readListPrec :: ReadPrec [ApplyWorkspaceEditParams]
Read, ApplyWorkspaceEditParams -> ApplyWorkspaceEditParams -> Bool
(ApplyWorkspaceEditParams -> ApplyWorkspaceEditParams -> Bool)
-> (ApplyWorkspaceEditParams -> ApplyWorkspaceEditParams -> Bool)
-> Eq ApplyWorkspaceEditParams
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ApplyWorkspaceEditParams -> ApplyWorkspaceEditParams -> Bool
== :: ApplyWorkspaceEditParams -> ApplyWorkspaceEditParams -> Bool
$c/= :: ApplyWorkspaceEditParams -> ApplyWorkspaceEditParams -> Bool
/= :: ApplyWorkspaceEditParams -> ApplyWorkspaceEditParams -> Bool
Eq)

deriveJSON lspOptions ''ApplyWorkspaceEditParams

data ApplyWorkspaceEditResponseBody =
  ApplyWorkspaceEditResponseBody
    { -- | Indicates whether the edit was applied or not.
      ApplyWorkspaceEditResponseBody -> Bool
_applied :: Bool
      -- | An optional textual description for why the edit was not applied.
      -- This may be used may be used by the server for diagnostic
      -- logging or to provide a suitable error for a request that
      -- triggered the edit.
    , ApplyWorkspaceEditResponseBody -> Maybe Text
_failureReason :: Maybe Text
      -- | Depending on the client's failure handling strategy `failedChange`
      -- might contain the index of the change that failed. This property is
      -- only available if the client signals a `failureHandling` strategy
      -- in its client capabilities.
    , ApplyWorkspaceEditResponseBody -> Maybe UInt
_failedChange :: Maybe UInt
    } deriving (Int -> ApplyWorkspaceEditResponseBody -> ShowS
[ApplyWorkspaceEditResponseBody] -> ShowS
ApplyWorkspaceEditResponseBody -> String
(Int -> ApplyWorkspaceEditResponseBody -> ShowS)
-> (ApplyWorkspaceEditResponseBody -> String)
-> ([ApplyWorkspaceEditResponseBody] -> ShowS)
-> Show ApplyWorkspaceEditResponseBody
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ApplyWorkspaceEditResponseBody -> ShowS
showsPrec :: Int -> ApplyWorkspaceEditResponseBody -> ShowS
$cshow :: ApplyWorkspaceEditResponseBody -> String
show :: ApplyWorkspaceEditResponseBody -> String
$cshowList :: [ApplyWorkspaceEditResponseBody] -> ShowS
showList :: [ApplyWorkspaceEditResponseBody] -> ShowS
Show, ReadPrec [ApplyWorkspaceEditResponseBody]
ReadPrec ApplyWorkspaceEditResponseBody
Int -> ReadS ApplyWorkspaceEditResponseBody
ReadS [ApplyWorkspaceEditResponseBody]
(Int -> ReadS ApplyWorkspaceEditResponseBody)
-> ReadS [ApplyWorkspaceEditResponseBody]
-> ReadPrec ApplyWorkspaceEditResponseBody
-> ReadPrec [ApplyWorkspaceEditResponseBody]
-> Read ApplyWorkspaceEditResponseBody
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS ApplyWorkspaceEditResponseBody
readsPrec :: Int -> ReadS ApplyWorkspaceEditResponseBody
$creadList :: ReadS [ApplyWorkspaceEditResponseBody]
readList :: ReadS [ApplyWorkspaceEditResponseBody]
$creadPrec :: ReadPrec ApplyWorkspaceEditResponseBody
readPrec :: ReadPrec ApplyWorkspaceEditResponseBody
$creadListPrec :: ReadPrec [ApplyWorkspaceEditResponseBody]
readListPrec :: ReadPrec [ApplyWorkspaceEditResponseBody]
Read, ApplyWorkspaceEditResponseBody
-> ApplyWorkspaceEditResponseBody -> Bool
(ApplyWorkspaceEditResponseBody
 -> ApplyWorkspaceEditResponseBody -> Bool)
-> (ApplyWorkspaceEditResponseBody
    -> ApplyWorkspaceEditResponseBody -> Bool)
-> Eq ApplyWorkspaceEditResponseBody
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ApplyWorkspaceEditResponseBody
-> ApplyWorkspaceEditResponseBody -> Bool
== :: ApplyWorkspaceEditResponseBody
-> ApplyWorkspaceEditResponseBody -> Bool
$c/= :: ApplyWorkspaceEditResponseBody
-> ApplyWorkspaceEditResponseBody -> Bool
/= :: ApplyWorkspaceEditResponseBody
-> ApplyWorkspaceEditResponseBody -> Bool
Eq)

deriveJSON lspOptions ''ApplyWorkspaceEditResponseBody

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

-- | Applies a 'TextEdit' to some 'Text'.
-- >>> applyTextEdit (TextEdit (Range (Position 0 1) (Position 0 2)) "i") "foo"
-- "fio"
applyTextEdit :: TextEdit -> Text -> Text
applyTextEdit :: TextEdit -> Text -> Text
applyTextEdit (TextEdit (Range Position
sp Position
ep) Text
newText) Text
oldText =
  let (Text
_, Text
afterEnd) = Position -> Text -> (Text, Text)
splitAtPos Position
ep Text
oldText
      (Text
beforeStart, Text
_) = Position -> Text -> (Text, Text)
splitAtPos Position
sp Text
oldText
    in [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat [Text
beforeStart, Text
newText, Text
afterEnd]
  where
    splitAtPos :: Position -> Text -> (Text, Text)
    splitAtPos :: Position -> Text -> (Text, Text)
splitAtPos (Position UInt
sl UInt
sc) Text
t =
      -- If we are looking for a line beyond the end of the text, this will give us an index
      -- past the end. Fortunately, T.splitAt is fine with this, and just gives us the whole
      -- string and an empty string, which is what we want.
      let index :: UInt
index = UInt
sc UInt -> UInt -> UInt
forall a. Num a => a -> a -> a
+ UInt -> Text -> UInt
startLineIndex UInt
sl Text
t
        in Int -> Text -> (Text, Text)
T.splitAt (UInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral UInt
index) Text
t

    -- The index of the first character of line 'line'
    startLineIndex :: UInt -> Text -> UInt
    startLineIndex :: UInt -> Text -> UInt
startLineIndex UInt
0 Text
_ = UInt
0
    startLineIndex UInt
line Text
t' =
      case (Char -> Bool) -> Text -> Maybe Int
T.findIndex (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\n') Text
t' of
        Just Int
i -> Int -> UInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
i UInt -> UInt -> UInt
forall a. Num a => a -> a -> a
+ UInt
1 UInt -> UInt -> UInt
forall a. Num a => a -> a -> a
+ UInt -> Text -> UInt
startLineIndex (UInt
line UInt -> UInt -> UInt
forall a. Num a => a -> a -> a
- UInt
1) (Int -> Text -> Text
T.drop (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Text
t')
        -- i != 0, and there are no newlines, so this is a line beyond the end of the text.
        -- In this case give the "start index" as the end, so we will at least append the text.
        Maybe Int
Nothing -> Int -> UInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> UInt) -> Int -> UInt
forall a b. (a -> b) -> a -> b
$ Text -> Int
T.length Text
t'

-- | 'editTextEdit' @outer@ @inner@ applies @inner@ to the text inside @outer@.
editTextEdit :: TextEdit -> TextEdit -> TextEdit
editTextEdit :: TextEdit -> TextEdit -> TextEdit
editTextEdit (TextEdit Range
origRange Text
origText) TextEdit
innerEdit =
  let newText :: Text
newText = TextEdit -> Text -> Text
applyTextEdit TextEdit
innerEdit Text
origText
    in Range -> Text -> TextEdit
TextEdit Range
origRange Text
newText