{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Language.LSP.Types.Completion where
import Control.Applicative
import qualified Data.Aeson as A
import Data.Aeson.TH
import Data.Scientific ( Scientific )
import Data.Text ( Text )
import Language.LSP.Types.Command
import Language.LSP.Types.Common
import Language.LSP.Types.MarkupContent
import Language.LSP.Types.Progress
import Language.LSP.Types.TextDocument
import Language.LSP.Types.Utils
import Language.LSP.Types.WorkspaceEdit
data CompletionItemKind = CiText
| CiMethod
| CiFunction
| CiConstructor
| CiField
| CiVariable
| CiClass
| CiInterface
| CiModule
| CiProperty
| CiUnit
| CiValue
| CiEnum
| CiKeyword
| CiSnippet
| CiColor
| CiFile
| CiReference
| CiFolder
| CiEnumMember
| CiConstant
| CiStruct
| CiEvent
| CiOperator
| CiTypeParameter
deriving (Read,Show,Eq,Ord)
instance A.ToJSON CompletionItemKind where
toJSON CiText = A.Number 1
toJSON CiMethod = A.Number 2
toJSON CiFunction = A.Number 3
toJSON CiConstructor = A.Number 4
toJSON CiField = A.Number 5
toJSON CiVariable = A.Number 6
toJSON CiClass = A.Number 7
toJSON CiInterface = A.Number 8
toJSON CiModule = A.Number 9
toJSON CiProperty = A.Number 10
toJSON CiUnit = A.Number 11
toJSON CiValue = A.Number 12
toJSON CiEnum = A.Number 13
toJSON CiKeyword = A.Number 14
toJSON CiSnippet = A.Number 15
toJSON CiColor = A.Number 16
toJSON CiFile = A.Number 17
toJSON CiReference = A.Number 18
toJSON CiFolder = A.Number 19
toJSON CiEnumMember = A.Number 20
toJSON CiConstant = A.Number 21
toJSON CiStruct = A.Number 22
toJSON CiEvent = A.Number 23
toJSON CiOperator = A.Number 24
toJSON CiTypeParameter = A.Number 25
instance A.FromJSON CompletionItemKind where
parseJSON (A.Number 1) = pure CiText
parseJSON (A.Number 2) = pure CiMethod
parseJSON (A.Number 3) = pure CiFunction
parseJSON (A.Number 4) = pure CiConstructor
parseJSON (A.Number 5) = pure CiField
parseJSON (A.Number 6) = pure CiVariable
parseJSON (A.Number 7) = pure CiClass
parseJSON (A.Number 8) = pure CiInterface
parseJSON (A.Number 9) = pure CiModule
parseJSON (A.Number 10) = pure CiProperty
parseJSON (A.Number 11) = pure CiUnit
parseJSON (A.Number 12) = pure CiValue
parseJSON (A.Number 13) = pure CiEnum
parseJSON (A.Number 14) = pure CiKeyword
parseJSON (A.Number 15) = pure CiSnippet
parseJSON (A.Number 16) = pure CiColor
parseJSON (A.Number 17) = pure CiFile
parseJSON (A.Number 18) = pure CiReference
parseJSON (A.Number 19) = pure CiFolder
parseJSON (A.Number 20) = pure CiEnumMember
parseJSON (A.Number 21) = pure CiConstant
parseJSON (A.Number 22) = pure CiStruct
parseJSON (A.Number 23) = pure CiEvent
parseJSON (A.Number 24) = pure CiOperator
parseJSON (A.Number 25) = pure CiTypeParameter
parseJSON _ = mempty
data CompletionItemTag
= CtDeprecated
deriving (Eq, Ord, Show, Read)
instance A.ToJSON CompletionItemTag where
toJSON CtDeprecated = A.Number 1
instance A.FromJSON CompletionItemTag where
parseJSON (A.Number 1) = pure CtDeprecated
parseJSON _ = mempty
data CompletionItemTagsClientCapabilities =
CompletionItemTagsClientCapabilities
{
_valueSet :: List CompletionItemTag
} deriving (Show, Read, Eq)
deriveJSON lspOptions ''CompletionItemTagsClientCapabilities
data CompletionItemClientCapabilities =
CompletionItemClientCapabilities
{
_snippetSupport :: Maybe Bool
, _commitCharactersSupport :: Maybe Bool
, _documentationFormat :: Maybe (List MarkupKind)
, _deprecatedSupport :: Maybe Bool
, _preselectSupport :: Maybe Bool
, _tagSupport :: Maybe CompletionItemTagsClientCapabilities
} deriving (Show, Read, Eq)
deriveJSON lspOptions ''CompletionItemClientCapabilities
data CompletionItemKindClientCapabilities =
CompletionItemKindClientCapabilities
{
_valueSet :: Maybe (List CompletionItemKind)
}
deriving (Show, Read, Eq)
deriveJSON lspOptions ''CompletionItemKindClientCapabilities
data CompletionClientCapabilities =
CompletionClientCapabilities
{ _dynamicRegistration :: Maybe Bool
, _completionItem :: Maybe CompletionItemClientCapabilities
, _completionItemKind :: Maybe CompletionItemKindClientCapabilities
, _contextSupport :: Maybe Bool
} deriving (Show, Read, Eq)
deriveJSON lspOptions ''CompletionClientCapabilities
data InsertTextFormat
= PlainText
| Snippet
deriving (Show, Read, Eq)
instance A.ToJSON InsertTextFormat where
toJSON PlainText = A.Number 1
toJSON Snippet = A.Number 2
instance A.FromJSON InsertTextFormat where
parseJSON (A.Number 1) = pure PlainText
parseJSON (A.Number 2) = pure Snippet
parseJSON _ = mempty
data CompletionDoc = CompletionDocString Text
| CompletionDocMarkup MarkupContent
deriving (Show, Read, Eq)
instance A.ToJSON CompletionDoc where
toJSON (CompletionDocString x) = A.toJSON x
toJSON (CompletionDocMarkup x) = A.toJSON x
instance A.FromJSON CompletionDoc where
parseJSON x = CompletionDocString <$> A.parseJSON x <|> CompletionDocMarkup <$> A.parseJSON x
data CompletionItem =
CompletionItem
{ _label :: Text
, _kind :: Maybe CompletionItemKind
, _tags :: Maybe (List CompletionItemTag)
, _detail :: Maybe Text
, _documentation :: Maybe CompletionDoc
, _deprecated :: Maybe Bool
, _preselect :: Maybe Bool
, _sortText :: Maybe Text
, _filterText :: Maybe Text
, _insertText :: Maybe Text
, _insertTextFormat :: Maybe InsertTextFormat
, _textEdit :: Maybe TextEdit
, _additionalTextEdits :: Maybe (List TextEdit)
, _commitCharacters :: Maybe (List Text)
, _command :: Maybe Command
, _xdata :: Maybe A.Value
} deriving (Read,Show,Eq)
deriveJSON lspOptions ''CompletionItem
data CompletionList =
CompletionList
{ _isIncomplete :: Bool
, _items :: List CompletionItem
} deriving (Read,Show,Eq)
deriveJSON lspOptions ''CompletionList
data CompletionTriggerKind =
CtInvoked
| CtTriggerCharacter
| CtTriggerForIncompleteCompletions
| CtUnknown Scientific
deriving (Read, Show, Eq)
instance A.ToJSON CompletionTriggerKind where
toJSON CtInvoked = A.Number 1
toJSON CtTriggerCharacter = A.Number 2
toJSON CtTriggerForIncompleteCompletions = A.Number 3
toJSON (CtUnknown x) = A.Number x
instance A.FromJSON CompletionTriggerKind where
parseJSON (A.Number 1) = pure CtInvoked
parseJSON (A.Number 2) = pure CtTriggerCharacter
parseJSON (A.Number 3) = pure CtTriggerForIncompleteCompletions
parseJSON (A.Number x) = pure (CtUnknown x)
parseJSON _ = mempty
makeExtendingDatatype "CompletionOptions" [''WorkDoneProgressOptions]
[ ("_triggerCharacters", [t| Maybe [String] |])
, ("_allCommitCharacters", [t| Maybe [String] |])
, ("_resolveProvider", [t| Maybe Bool|])
]
deriveJSON lspOptions ''CompletionOptions
makeExtendingDatatype "CompletionRegistrationOptions"
[ ''TextDocumentRegistrationOptions
, ''CompletionOptions
]
[]
deriveJSON lspOptions ''CompletionRegistrationOptions
data CompletionContext =
CompletionContext
{ _triggerKind :: CompletionTriggerKind
, _triggerCharacter :: Maybe Text
}
deriving (Read, Show, Eq)
deriveJSON lspOptions ''CompletionContext
makeExtendingDatatype "CompletionParams"
[ ''TextDocumentPositionParams
, ''WorkDoneProgressParams
, ''PartialResultParams
]
[ ("_context", [t| Maybe CompletionContext |]) ]
deriveJSON lspOptions ''CompletionParams