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

import           Data.Aeson.TH
import           Data.Aeson.Types
import           Data.Default
import           Data.String
import           Data.Text                      ( Text )
import qualified Data.Text as T
import           Language.LSP.Types.Command
import           Language.LSP.Types.Diagnostic
import           Language.LSP.Types.Common
import           Language.LSP.Types.Location
import           Language.LSP.Types.Progress
import           Language.LSP.Types.TextDocument
import           Language.LSP.Types.Utils
import           Language.LSP.Types.WorkspaceEdit


data CodeActionKind
  = -- | Empty kind.
    CodeActionEmpty
  | -- | Base kind for quickfix actions: @quickfix@.
    CodeActionQuickFix
  | -- | Base kind for refactoring actions: @refactor@.
    CodeActionRefactor
  | -- | Base kind for refactoring extraction actions: @refactor.extract@.
    -- Example extract actions:
    --
    -- - Extract method
    -- - Extract function
    -- - Extract variable
    -- - Extract interface from class
    -- - ...
    CodeActionRefactorExtract
  | -- | Base kind for refactoring inline actions: @refactor.inline@.
    --
    -- Example inline actions:
    --
    -- - Inline function
    -- - Inline variable
    -- - Inline constant
    -- - ...
    CodeActionRefactorInline
  | -- | Base kind for refactoring rewrite actions: @refactor.rewrite@.
    --
    -- Example rewrite actions:
    --
    -- - Convert JavaScript function to class
    -- - Add or remove parameter
    -- - Encapsulate field
    -- - Make method static
    -- - Move method to base class
    -- - ...
    CodeActionRefactorRewrite
  | -- | Base kind for source actions: @source@.
    --
    -- Source code actions apply to the entire file.
    CodeActionSource
  | -- | Base kind for an organize imports source action: @source.organizeImports@.
    CodeActionSourceOrganizeImports
  | CodeActionUnknown Text
  deriving (ReadPrec [CodeActionKind]
ReadPrec CodeActionKind
Int -> ReadS CodeActionKind
ReadS [CodeActionKind]
(Int -> ReadS CodeActionKind)
-> ReadS [CodeActionKind]
-> ReadPrec CodeActionKind
-> ReadPrec [CodeActionKind]
-> Read CodeActionKind
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS CodeActionKind
readsPrec :: Int -> ReadS CodeActionKind
$creadList :: ReadS [CodeActionKind]
readList :: ReadS [CodeActionKind]
$creadPrec :: ReadPrec CodeActionKind
readPrec :: ReadPrec CodeActionKind
$creadListPrec :: ReadPrec [CodeActionKind]
readListPrec :: ReadPrec [CodeActionKind]
Read, Int -> CodeActionKind -> ShowS
[CodeActionKind] -> ShowS
CodeActionKind -> String
(Int -> CodeActionKind -> ShowS)
-> (CodeActionKind -> String)
-> ([CodeActionKind] -> ShowS)
-> Show CodeActionKind
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CodeActionKind -> ShowS
showsPrec :: Int -> CodeActionKind -> ShowS
$cshow :: CodeActionKind -> String
show :: CodeActionKind -> String
$cshowList :: [CodeActionKind] -> ShowS
showList :: [CodeActionKind] -> ShowS
Show, CodeActionKind -> CodeActionKind -> Bool
(CodeActionKind -> CodeActionKind -> Bool)
-> (CodeActionKind -> CodeActionKind -> Bool) -> Eq CodeActionKind
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CodeActionKind -> CodeActionKind -> Bool
== :: CodeActionKind -> CodeActionKind -> Bool
$c/= :: CodeActionKind -> CodeActionKind -> Bool
/= :: CodeActionKind -> CodeActionKind -> Bool
Eq)

fromHierarchicalString :: Text -> CodeActionKind
fromHierarchicalString :: Text -> CodeActionKind
fromHierarchicalString Text
t = case Text
t of
  Text
""                       -> CodeActionKind
CodeActionEmpty
  Text
"quickfix"               -> CodeActionKind
CodeActionQuickFix
  Text
"refactor"               -> CodeActionKind
CodeActionRefactor
  Text
"refactor.extract"       -> CodeActionKind
CodeActionRefactorExtract
  Text
"refactor.inline"        -> CodeActionKind
CodeActionRefactorInline
  Text
"refactor.rewrite"       -> CodeActionKind
CodeActionRefactorRewrite
  Text
"source"                 -> CodeActionKind
CodeActionSource
  Text
"source.organizeImports" -> CodeActionKind
CodeActionSourceOrganizeImports
  Text
s                        -> Text -> CodeActionKind
CodeActionUnknown Text
s

toHierarchicalString :: CodeActionKind -> Text
toHierarchicalString :: CodeActionKind -> Text
toHierarchicalString CodeActionKind
k = case CodeActionKind
k of
  CodeActionKind
CodeActionEmpty                 -> Text
""
  CodeActionKind
CodeActionQuickFix              -> Text
"quickfix"
  CodeActionKind
CodeActionRefactor              -> Text
"refactor"
  CodeActionKind
CodeActionRefactorExtract       -> Text
"refactor.extract"
  CodeActionKind
CodeActionRefactorInline        -> Text
"refactor.inline"
  CodeActionKind
CodeActionRefactorRewrite       -> Text
"refactor.rewrite"
  CodeActionKind
CodeActionSource                -> Text
"source"
  CodeActionKind
CodeActionSourceOrganizeImports -> Text
"source.organizeImports"
  (CodeActionUnknown Text
s)           -> Text
s

instance IsString CodeActionKind where
  fromString :: String -> CodeActionKind
fromString = Text -> CodeActionKind
fromHierarchicalString (Text -> CodeActionKind)
-> (String -> Text) -> String -> CodeActionKind
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack

instance ToJSON CodeActionKind where
  toJSON :: CodeActionKind -> Value
toJSON = Text -> Value
String (Text -> Value)
-> (CodeActionKind -> Text) -> CodeActionKind -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CodeActionKind -> Text
toHierarchicalString

instance FromJSON CodeActionKind where
  parseJSON :: Value -> Parser CodeActionKind
parseJSON (String Text
s) = CodeActionKind -> Parser CodeActionKind
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CodeActionKind -> Parser CodeActionKind)
-> CodeActionKind -> Parser CodeActionKind
forall a b. (a -> b) -> a -> b
$ Text -> CodeActionKind
fromHierarchicalString Text
s
  parseJSON Value
_          = String -> Parser CodeActionKind
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"CodeActionKind"

-- | Does the first 'CodeActionKind' subsume the other one, hierarchically. Reflexive.
codeActionKindSubsumes :: CodeActionKind -> CodeActionKind -> Bool
-- Simple but ugly implementation: prefix on the string representation
codeActionKindSubsumes :: CodeActionKind -> CodeActionKind -> Bool
codeActionKindSubsumes CodeActionKind
parent CodeActionKind
child = CodeActionKind -> Text
toHierarchicalString CodeActionKind
parent Text -> Text -> Bool
`T.isPrefixOf` CodeActionKind -> Text
toHierarchicalString CodeActionKind
child

-- | The 'CodeActionKind's listed in the LSP spec specifically.
specCodeActionKinds :: [CodeActionKind]
specCodeActionKinds :: [CodeActionKind]
specCodeActionKinds = [
  CodeActionKind
CodeActionQuickFix
  , CodeActionKind
CodeActionRefactor
  , CodeActionKind
CodeActionRefactorExtract
  , CodeActionKind
CodeActionRefactorInline
  , CodeActionKind
CodeActionRefactorRewrite
  , CodeActionKind
CodeActionSource
  , CodeActionKind
CodeActionSourceOrganizeImports
  ]

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

data CodeActionKindClientCapabilities =
  CodeActionKindClientCapabilities
   { -- | The code action kind values the client supports. When this
     -- property exists the client also guarantees that it will
     -- handle values outside its set gracefully and falls back
     -- to a default value when unknown.
      CodeActionKindClientCapabilities -> List CodeActionKind
_valueSet :: List CodeActionKind
   } deriving (Int -> CodeActionKindClientCapabilities -> ShowS
[CodeActionKindClientCapabilities] -> ShowS
CodeActionKindClientCapabilities -> String
(Int -> CodeActionKindClientCapabilities -> ShowS)
-> (CodeActionKindClientCapabilities -> String)
-> ([CodeActionKindClientCapabilities] -> ShowS)
-> Show CodeActionKindClientCapabilities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CodeActionKindClientCapabilities -> ShowS
showsPrec :: Int -> CodeActionKindClientCapabilities -> ShowS
$cshow :: CodeActionKindClientCapabilities -> String
show :: CodeActionKindClientCapabilities -> String
$cshowList :: [CodeActionKindClientCapabilities] -> ShowS
showList :: [CodeActionKindClientCapabilities] -> ShowS
Show, ReadPrec [CodeActionKindClientCapabilities]
ReadPrec CodeActionKindClientCapabilities
Int -> ReadS CodeActionKindClientCapabilities
ReadS [CodeActionKindClientCapabilities]
(Int -> ReadS CodeActionKindClientCapabilities)
-> ReadS [CodeActionKindClientCapabilities]
-> ReadPrec CodeActionKindClientCapabilities
-> ReadPrec [CodeActionKindClientCapabilities]
-> Read CodeActionKindClientCapabilities
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS CodeActionKindClientCapabilities
readsPrec :: Int -> ReadS CodeActionKindClientCapabilities
$creadList :: ReadS [CodeActionKindClientCapabilities]
readList :: ReadS [CodeActionKindClientCapabilities]
$creadPrec :: ReadPrec CodeActionKindClientCapabilities
readPrec :: ReadPrec CodeActionKindClientCapabilities
$creadListPrec :: ReadPrec [CodeActionKindClientCapabilities]
readListPrec :: ReadPrec [CodeActionKindClientCapabilities]
Read, CodeActionKindClientCapabilities
-> CodeActionKindClientCapabilities -> Bool
(CodeActionKindClientCapabilities
 -> CodeActionKindClientCapabilities -> Bool)
-> (CodeActionKindClientCapabilities
    -> CodeActionKindClientCapabilities -> Bool)
-> Eq CodeActionKindClientCapabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CodeActionKindClientCapabilities
-> CodeActionKindClientCapabilities -> Bool
== :: CodeActionKindClientCapabilities
-> CodeActionKindClientCapabilities -> Bool
$c/= :: CodeActionKindClientCapabilities
-> CodeActionKindClientCapabilities -> Bool
/= :: CodeActionKindClientCapabilities
-> CodeActionKindClientCapabilities -> Bool
Eq)

deriveJSON lspOptions ''CodeActionKindClientCapabilities

instance Default CodeActionKindClientCapabilities where
  def :: CodeActionKindClientCapabilities
def = List CodeActionKind -> CodeActionKindClientCapabilities
CodeActionKindClientCapabilities ([CodeActionKind] -> List CodeActionKind
forall a. [a] -> List a
List [CodeActionKind]
specCodeActionKinds)

data CodeActionLiteralSupport =
  CodeActionLiteralSupport
    { CodeActionLiteralSupport -> CodeActionKindClientCapabilities
_codeActionKind :: CodeActionKindClientCapabilities -- ^ The code action kind is support with the following value set.
    } deriving (Int -> CodeActionLiteralSupport -> ShowS
[CodeActionLiteralSupport] -> ShowS
CodeActionLiteralSupport -> String
(Int -> CodeActionLiteralSupport -> ShowS)
-> (CodeActionLiteralSupport -> String)
-> ([CodeActionLiteralSupport] -> ShowS)
-> Show CodeActionLiteralSupport
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CodeActionLiteralSupport -> ShowS
showsPrec :: Int -> CodeActionLiteralSupport -> ShowS
$cshow :: CodeActionLiteralSupport -> String
show :: CodeActionLiteralSupport -> String
$cshowList :: [CodeActionLiteralSupport] -> ShowS
showList :: [CodeActionLiteralSupport] -> ShowS
Show, ReadPrec [CodeActionLiteralSupport]
ReadPrec CodeActionLiteralSupport
Int -> ReadS CodeActionLiteralSupport
ReadS [CodeActionLiteralSupport]
(Int -> ReadS CodeActionLiteralSupport)
-> ReadS [CodeActionLiteralSupport]
-> ReadPrec CodeActionLiteralSupport
-> ReadPrec [CodeActionLiteralSupport]
-> Read CodeActionLiteralSupport
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS CodeActionLiteralSupport
readsPrec :: Int -> ReadS CodeActionLiteralSupport
$creadList :: ReadS [CodeActionLiteralSupport]
readList :: ReadS [CodeActionLiteralSupport]
$creadPrec :: ReadPrec CodeActionLiteralSupport
readPrec :: ReadPrec CodeActionLiteralSupport
$creadListPrec :: ReadPrec [CodeActionLiteralSupport]
readListPrec :: ReadPrec [CodeActionLiteralSupport]
Read, CodeActionLiteralSupport -> CodeActionLiteralSupport -> Bool
(CodeActionLiteralSupport -> CodeActionLiteralSupport -> Bool)
-> (CodeActionLiteralSupport -> CodeActionLiteralSupport -> Bool)
-> Eq CodeActionLiteralSupport
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CodeActionLiteralSupport -> CodeActionLiteralSupport -> Bool
== :: CodeActionLiteralSupport -> CodeActionLiteralSupport -> Bool
$c/= :: CodeActionLiteralSupport -> CodeActionLiteralSupport -> Bool
/= :: CodeActionLiteralSupport -> CodeActionLiteralSupport -> Bool
Eq)

deriveJSON lspOptions ''CodeActionLiteralSupport

data CodeActionResolveClientCapabilities =
  CodeActionResolveClientCapabilities
    { CodeActionResolveClientCapabilities -> List Text
_properties :: List Text -- ^ The properties that a client can resolve lazily.
    } deriving (Int -> CodeActionResolveClientCapabilities -> ShowS
[CodeActionResolveClientCapabilities] -> ShowS
CodeActionResolveClientCapabilities -> String
(Int -> CodeActionResolveClientCapabilities -> ShowS)
-> (CodeActionResolveClientCapabilities -> String)
-> ([CodeActionResolveClientCapabilities] -> ShowS)
-> Show CodeActionResolveClientCapabilities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CodeActionResolveClientCapabilities -> ShowS
showsPrec :: Int -> CodeActionResolveClientCapabilities -> ShowS
$cshow :: CodeActionResolveClientCapabilities -> String
show :: CodeActionResolveClientCapabilities -> String
$cshowList :: [CodeActionResolveClientCapabilities] -> ShowS
showList :: [CodeActionResolveClientCapabilities] -> ShowS
Show, ReadPrec [CodeActionResolveClientCapabilities]
ReadPrec CodeActionResolveClientCapabilities
Int -> ReadS CodeActionResolveClientCapabilities
ReadS [CodeActionResolveClientCapabilities]
(Int -> ReadS CodeActionResolveClientCapabilities)
-> ReadS [CodeActionResolveClientCapabilities]
-> ReadPrec CodeActionResolveClientCapabilities
-> ReadPrec [CodeActionResolveClientCapabilities]
-> Read CodeActionResolveClientCapabilities
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS CodeActionResolveClientCapabilities
readsPrec :: Int -> ReadS CodeActionResolveClientCapabilities
$creadList :: ReadS [CodeActionResolveClientCapabilities]
readList :: ReadS [CodeActionResolveClientCapabilities]
$creadPrec :: ReadPrec CodeActionResolveClientCapabilities
readPrec :: ReadPrec CodeActionResolveClientCapabilities
$creadListPrec :: ReadPrec [CodeActionResolveClientCapabilities]
readListPrec :: ReadPrec [CodeActionResolveClientCapabilities]
Read, CodeActionResolveClientCapabilities
-> CodeActionResolveClientCapabilities -> Bool
(CodeActionResolveClientCapabilities
 -> CodeActionResolveClientCapabilities -> Bool)
-> (CodeActionResolveClientCapabilities
    -> CodeActionResolveClientCapabilities -> Bool)
-> Eq CodeActionResolveClientCapabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CodeActionResolveClientCapabilities
-> CodeActionResolveClientCapabilities -> Bool
== :: CodeActionResolveClientCapabilities
-> CodeActionResolveClientCapabilities -> Bool
$c/= :: CodeActionResolveClientCapabilities
-> CodeActionResolveClientCapabilities -> Bool
/= :: CodeActionResolveClientCapabilities
-> CodeActionResolveClientCapabilities -> Bool
Eq)

deriveJSON lspOptions ''CodeActionResolveClientCapabilities

data CodeActionClientCapabilities = CodeActionClientCapabilities
  { -- | Whether code action supports dynamic registration.
    CodeActionClientCapabilities -> Maybe Bool
_dynamicRegistration :: Maybe Bool,
    -- | The client support code action literals as a valid response
    -- of the `textDocument/codeAction` request.
    -- Since 3.8.0
    CodeActionClientCapabilities -> Maybe CodeActionLiteralSupport
_codeActionLiteralSupport :: Maybe CodeActionLiteralSupport,
    -- | Whether code action supports the `isPreferred` property. Since LSP 3.15.0
    CodeActionClientCapabilities -> Maybe Bool
_isPreferredSupport :: Maybe Bool,
    -- | Whether code action supports the `disabled` property.
    --
    -- @since 3.16.0
    CodeActionClientCapabilities -> Maybe Bool
_disabledSupport :: Maybe Bool,
    -- | Whether code action supports the `data` property which is
    -- preserved between a `textDocument/codeAction` and a
    -- `codeAction/resolve` request.
    --
    -- @since 3.16.0
    CodeActionClientCapabilities -> Maybe Bool
_dataSupport :: Maybe Bool,
    -- | Whether the client supports resolving additional code action
    -- properties via a separate `codeAction/resolve` request.
    --
    -- @since 3.16.0
    CodeActionClientCapabilities
-> Maybe CodeActionResolveClientCapabilities
_resolveSupport :: Maybe CodeActionResolveClientCapabilities,
    -- | Whether the client honors the change annotations in
    -- text edits and resource operations returned via the
    -- `CodeAction#edit` property by for example presenting
    -- the workspace edit in the user interface and asking
    -- for confirmation.
    --
    -- @since 3.16.0
    CodeActionClientCapabilities -> Maybe Bool
_honorsChangeAnnotations :: Maybe Bool
  }
  deriving (Int -> CodeActionClientCapabilities -> ShowS
[CodeActionClientCapabilities] -> ShowS
CodeActionClientCapabilities -> String
(Int -> CodeActionClientCapabilities -> ShowS)
-> (CodeActionClientCapabilities -> String)
-> ([CodeActionClientCapabilities] -> ShowS)
-> Show CodeActionClientCapabilities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CodeActionClientCapabilities -> ShowS
showsPrec :: Int -> CodeActionClientCapabilities -> ShowS
$cshow :: CodeActionClientCapabilities -> String
show :: CodeActionClientCapabilities -> String
$cshowList :: [CodeActionClientCapabilities] -> ShowS
showList :: [CodeActionClientCapabilities] -> ShowS
Show, ReadPrec [CodeActionClientCapabilities]
ReadPrec CodeActionClientCapabilities
Int -> ReadS CodeActionClientCapabilities
ReadS [CodeActionClientCapabilities]
(Int -> ReadS CodeActionClientCapabilities)
-> ReadS [CodeActionClientCapabilities]
-> ReadPrec CodeActionClientCapabilities
-> ReadPrec [CodeActionClientCapabilities]
-> Read CodeActionClientCapabilities
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS CodeActionClientCapabilities
readsPrec :: Int -> ReadS CodeActionClientCapabilities
$creadList :: ReadS [CodeActionClientCapabilities]
readList :: ReadS [CodeActionClientCapabilities]
$creadPrec :: ReadPrec CodeActionClientCapabilities
readPrec :: ReadPrec CodeActionClientCapabilities
$creadListPrec :: ReadPrec [CodeActionClientCapabilities]
readListPrec :: ReadPrec [CodeActionClientCapabilities]
Read, CodeActionClientCapabilities
-> CodeActionClientCapabilities -> Bool
(CodeActionClientCapabilities
 -> CodeActionClientCapabilities -> Bool)
-> (CodeActionClientCapabilities
    -> CodeActionClientCapabilities -> Bool)
-> Eq CodeActionClientCapabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CodeActionClientCapabilities
-> CodeActionClientCapabilities -> Bool
== :: CodeActionClientCapabilities
-> CodeActionClientCapabilities -> Bool
$c/= :: CodeActionClientCapabilities
-> CodeActionClientCapabilities -> Bool
/= :: CodeActionClientCapabilities
-> CodeActionClientCapabilities -> Bool
Eq)

deriveJSON lspOptions ''CodeActionClientCapabilities

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

makeExtendingDatatype "CodeActionOptions" [''WorkDoneProgressOptions]
  [("_codeActionKinds", [t| Maybe (List CodeActionKind) |]), ("_resolveProvider", [t| Maybe Bool |]) ]
deriveJSON lspOptions ''CodeActionOptions

makeExtendingDatatype "CodeActionRegistrationOptions"
  [ ''TextDocumentRegistrationOptions
  , ''CodeActionOptions
  ] []
deriveJSON lspOptions ''CodeActionRegistrationOptions

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

-- | Contains additional diagnostic information about the context in which a
-- code action is run.
data CodeActionContext = CodeActionContext
  { -- | An array of diagnostics known on the client side overlapping the range provided to the
    -- @textDocument/codeAction@ request. They are provided so that the server knows which
    -- errors are currently presented to the user for the given range. There is no guarantee
    -- that these accurately reflect the error state of the resource. The primary parameter
    -- to compute code actions is the provided range.
    CodeActionContext -> List Diagnostic
_diagnostics :: List Diagnostic
    -- | Requested kind of actions to return.
    --
    -- Actions not of this kind are filtered out by the client before being shown. So servers
    -- can omit computing them.
  , CodeActionContext -> Maybe (List CodeActionKind)
_only :: Maybe (List CodeActionKind)
  }
  deriving (ReadPrec [CodeActionContext]
ReadPrec CodeActionContext
Int -> ReadS CodeActionContext
ReadS [CodeActionContext]
(Int -> ReadS CodeActionContext)
-> ReadS [CodeActionContext]
-> ReadPrec CodeActionContext
-> ReadPrec [CodeActionContext]
-> Read CodeActionContext
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS CodeActionContext
readsPrec :: Int -> ReadS CodeActionContext
$creadList :: ReadS [CodeActionContext]
readList :: ReadS [CodeActionContext]
$creadPrec :: ReadPrec CodeActionContext
readPrec :: ReadPrec CodeActionContext
$creadListPrec :: ReadPrec [CodeActionContext]
readListPrec :: ReadPrec [CodeActionContext]
Read, Int -> CodeActionContext -> ShowS
[CodeActionContext] -> ShowS
CodeActionContext -> String
(Int -> CodeActionContext -> ShowS)
-> (CodeActionContext -> String)
-> ([CodeActionContext] -> ShowS)
-> Show CodeActionContext
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CodeActionContext -> ShowS
showsPrec :: Int -> CodeActionContext -> ShowS
$cshow :: CodeActionContext -> String
show :: CodeActionContext -> String
$cshowList :: [CodeActionContext] -> ShowS
showList :: [CodeActionContext] -> ShowS
Show, CodeActionContext -> CodeActionContext -> Bool
(CodeActionContext -> CodeActionContext -> Bool)
-> (CodeActionContext -> CodeActionContext -> Bool)
-> Eq CodeActionContext
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CodeActionContext -> CodeActionContext -> Bool
== :: CodeActionContext -> CodeActionContext -> Bool
$c/= :: CodeActionContext -> CodeActionContext -> Bool
/= :: CodeActionContext -> CodeActionContext -> Bool
Eq)

deriveJSON lspOptions ''CodeActionContext

makeExtendingDatatype "CodeActionParams"
  [ ''WorkDoneProgressParams
  , ''PartialResultParams
  ]
  [ ("_textDocument", [t|TextDocumentIdentifier|]),
    ("_range", [t|Range|]),
    ("_context", [t|CodeActionContext|])
  ]
deriveJSON lspOptions ''CodeActionParams

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

deriveJSON lspOptions ''Reason

-- | A code action represents a change that can be performed in code, e.g. to fix a problem or
-- to refactor code.
--
-- A CodeAction must set either '_edit' and/or a '_command'. If both are supplied,
-- the '_edit' is applied first, then the '_command' is executed.
data CodeAction =
  CodeAction
  { -- | A short, human-readable, title for this code action.
    CodeAction -> Text
_title :: Text,
    -- | The kind of the code action. Used to filter code actions.
    CodeAction -> Maybe CodeActionKind
_kind :: Maybe CodeActionKind,
    -- | The diagnostics that this code action resolves.
    CodeAction -> Maybe (List Diagnostic)
_diagnostics :: Maybe (List Diagnostic),
    -- | Marks this as a preferred action. Preferred actions are used by the `auto fix` command and can be targeted
    -- by keybindings.
    --
    -- A quick fix should be marked preferred if it properly addresses the underlying error.
    -- A refactoring should be marked preferred if it is the most reasonable choice of actions to take.
    --
    -- Since LSP 3.15.0
    CodeAction -> Maybe Bool
_isPreferred :: Maybe Bool,
    CodeAction -> Maybe Reason
_disabled    :: Maybe Reason, -- ^ Marks that the code action cannot currently be applied.
    -- | The workspace edit this code action performs.
    CodeAction -> Maybe WorkspaceEdit
_edit :: Maybe WorkspaceEdit,
    -- | A command this code action executes. If a code action
    -- provides an edit and a command, first the edit is
    -- executed and then the command.
    CodeAction -> Maybe Command
_command :: Maybe Command,
    -- | A data entry field that is preserved on a code action between
    -- a `textDocument/codeAction` and a `codeAction/resolve` request.
    --
    -- @since 3.16.0
    CodeAction -> Maybe Value
_xdata :: Maybe Value
  }
  deriving (ReadPrec [CodeAction]
ReadPrec CodeAction
Int -> ReadS CodeAction
ReadS [CodeAction]
(Int -> ReadS CodeAction)
-> ReadS [CodeAction]
-> ReadPrec CodeAction
-> ReadPrec [CodeAction]
-> Read CodeAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS CodeAction
readsPrec :: Int -> ReadS CodeAction
$creadList :: ReadS [CodeAction]
readList :: ReadS [CodeAction]
$creadPrec :: ReadPrec CodeAction
readPrec :: ReadPrec CodeAction
$creadListPrec :: ReadPrec [CodeAction]
readListPrec :: ReadPrec [CodeAction]
Read, Int -> CodeAction -> ShowS
[CodeAction] -> ShowS
CodeAction -> String
(Int -> CodeAction -> ShowS)
-> (CodeAction -> String)
-> ([CodeAction] -> ShowS)
-> Show CodeAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CodeAction -> ShowS
showsPrec :: Int -> CodeAction -> ShowS
$cshow :: CodeAction -> String
show :: CodeAction -> String
$cshowList :: [CodeAction] -> ShowS
showList :: [CodeAction] -> ShowS
Show, CodeAction -> CodeAction -> Bool
(CodeAction -> CodeAction -> Bool)
-> (CodeAction -> CodeAction -> Bool) -> Eq CodeAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CodeAction -> CodeAction -> Bool
== :: CodeAction -> CodeAction -> Bool
$c/= :: CodeAction -> CodeAction -> Bool
/= :: CodeAction -> CodeAction -> Bool
Eq)
deriveJSON lspOptions ''CodeAction