{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DuplicateRecordFields #-}
module Language.Haskell.LSP.Types.Symbol where
import Control.Applicative
import Data.Aeson
import Data.Aeson.TH
import Data.Scientific
import Data.Text (Text)
import Language.Haskell.LSP.Types.Constants
import Language.Haskell.LSP.Types.TextDocument
import Language.Haskell.LSP.Types.List
import Language.Haskell.LSP.Types.Location
import Language.Haskell.LSP.Types.Message
data DocumentSymbolParams =
DocumentSymbolParams
{ _textDocument :: TextDocumentIdentifier
} deriving (Read,Show,Eq)
deriveJSON lspOptions ''DocumentSymbolParams
data SymbolKind
= SkFile
| SkModule
| SkNamespace
| SkPackage
| SkClass
| SkMethod
| SkProperty
| SkField
| SkConstructor
| SkEnum
| SkInterface
| SkFunction
| SkVariable
| SkConstant
| SkString
| SkNumber
| SkBoolean
| SkArray
| SkObject
| SkKey
| SkNull
| SkEnumMember
| SkStruct
| SkEvent
| SkOperator
| SkTypeParameter
| SkUnknown Scientific
deriving (Read,Show,Eq)
instance ToJSON SymbolKind where
toJSON SkFile = Number 1
toJSON SkModule = Number 2
toJSON SkNamespace = Number 3
toJSON SkPackage = Number 4
toJSON SkClass = Number 5
toJSON SkMethod = Number 6
toJSON SkProperty = Number 7
toJSON SkField = Number 8
toJSON SkConstructor = Number 9
toJSON SkEnum = Number 10
toJSON SkInterface = Number 11
toJSON SkFunction = Number 12
toJSON SkVariable = Number 13
toJSON SkConstant = Number 14
toJSON SkString = Number 15
toJSON SkNumber = Number 16
toJSON SkBoolean = Number 17
toJSON SkArray = Number 18
toJSON SkObject = Number 19
toJSON SkKey = Number 20
toJSON SkNull = Number 21
toJSON SkEnumMember = Number 22
toJSON SkStruct = Number 23
toJSON SkEvent = Number 24
toJSON SkOperator = Number 25
toJSON SkTypeParameter = Number 26
toJSON (SkUnknown x) = Number x
instance FromJSON SymbolKind where
parseJSON (Number 1) = pure SkFile
parseJSON (Number 2) = pure SkModule
parseJSON (Number 3) = pure SkNamespace
parseJSON (Number 4) = pure SkPackage
parseJSON (Number 5) = pure SkClass
parseJSON (Number 6) = pure SkMethod
parseJSON (Number 7) = pure SkProperty
parseJSON (Number 8) = pure SkField
parseJSON (Number 9) = pure SkConstructor
parseJSON (Number 10) = pure SkEnum
parseJSON (Number 11) = pure SkInterface
parseJSON (Number 12) = pure SkFunction
parseJSON (Number 13) = pure SkVariable
parseJSON (Number 14) = pure SkConstant
parseJSON (Number 15) = pure SkString
parseJSON (Number 16) = pure SkNumber
parseJSON (Number 17) = pure SkBoolean
parseJSON (Number 18) = pure SkArray
parseJSON (Number 19) = pure SkObject
parseJSON (Number 20) = pure SkKey
parseJSON (Number 21) = pure SkNull
parseJSON (Number 22) = pure SkEnumMember
parseJSON (Number 23) = pure SkStruct
parseJSON (Number 24) = pure SkEvent
parseJSON (Number 25) = pure SkOperator
parseJSON (Number 26) = pure SkTypeParameter
parseJSON (Number x) = pure (SkUnknown x)
parseJSON _ = mempty
data DocumentSymbol =
DocumentSymbol
{ _name :: Text
, _detail :: Maybe Text
, _kind :: SymbolKind
, _deprecated :: Maybe Bool
, _range :: Range
, _selectionRange :: Range
, _children :: Maybe (List DocumentSymbol)
} deriving (Read,Show,Eq)
deriveJSON lspOptions ''DocumentSymbol
data SymbolInformation =
SymbolInformation
{ _name :: Text
, _kind :: SymbolKind
, _deprecated :: Maybe Bool
, _location :: Location
, _containerName :: Maybe Text
} deriving (Read,Show,Eq)
deriveJSON lspOptions ''SymbolInformation
data DSResult = DSDocumentSymbols (List DocumentSymbol)
| DSSymbolInformation (List SymbolInformation)
deriving (Read,Show,Eq)
instance FromJSON DSResult where
parseJSON x = DSDocumentSymbols <$> parseJSON x <|> DSSymbolInformation <$> parseJSON x
instance ToJSON DSResult where
toJSON (DSDocumentSymbols x) = toJSON x
toJSON (DSSymbolInformation x) = toJSON x
type DocumentSymbolRequest = RequestMessage ClientMethod DocumentSymbolParams DSResult
type DocumentSymbolsResponse = ResponseMessage DSResult