{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeOperators #-}
module Language.LSP.Types.Diagnostic where
import Control.DeepSeq
import qualified Data.Aeson as A
import Data.Aeson.TH
import Data.Text
import GHC.Generics
import Language.LSP.Types.Common
import Language.LSP.Types.Location
import Language.LSP.Types.Uri
import Language.LSP.Types.Utils
data DiagnosticSeverity
= DsError
| DsWarning
| DsInfo
| DsHint
deriving (Eq,Ord,Show,Read, Generic)
instance NFData DiagnosticSeverity
instance A.ToJSON DiagnosticSeverity where
toJSON DsError = A.Number 1
toJSON DsWarning = A.Number 2
toJSON DsInfo = A.Number 3
toJSON DsHint = A.Number 4
instance A.FromJSON DiagnosticSeverity where
parseJSON (A.Number 1) = pure DsError
parseJSON (A.Number 2) = pure DsWarning
parseJSON (A.Number 3) = pure DsInfo
parseJSON (A.Number 4) = pure DsHint
parseJSON _ = mempty
data DiagnosticTag
= DtUnnecessary
| DtDeprecated
deriving (Eq, Ord, Show, Read, Generic)
instance NFData DiagnosticTag
instance A.ToJSON DiagnosticTag where
toJSON DtUnnecessary = A.Number 1
toJSON DtDeprecated = A.Number 2
instance A.FromJSON DiagnosticTag where
parseJSON (A.Number 1) = pure DtUnnecessary
parseJSON (A.Number 2) = pure DtDeprecated
parseJSON _ = mempty
data DiagnosticRelatedInformation =
DiagnosticRelatedInformation
{ _location :: Location
, _message :: Text
} deriving (Show, Read, Eq, Ord, Generic)
instance NFData DiagnosticRelatedInformation
deriveJSON lspOptions ''DiagnosticRelatedInformation
type DiagnosticSource = Text
data Diagnostic =
Diagnostic
{ _range :: Range
, _severity :: Maybe DiagnosticSeverity
, _code :: Maybe (Int |? String)
, _source :: Maybe DiagnosticSource
, _message :: Text
, _tags :: Maybe (List DiagnosticTag)
, _relatedInformation :: Maybe (List DiagnosticRelatedInformation)
} deriving (Show, Read, Eq, Ord, Generic)
instance NFData Diagnostic
deriveJSON lspOptions ''Diagnostic
data PublishDiagnosticsTagsClientCapabilities =
PublishDiagnosticsTagsClientCapabilities
{
_valueSet :: List DiagnosticTag
} deriving (Show, Read, Eq)
deriveJSON lspOptions ''PublishDiagnosticsTagsClientCapabilities
data PublishDiagnosticsClientCapabilities =
PublishDiagnosticsClientCapabilities
{
_relatedInformation :: Maybe Bool
, _tagSupport :: Maybe PublishDiagnosticsTagsClientCapabilities
, _versionSupport :: Maybe Bool
} deriving (Show, Read, Eq)
deriveJSON lspOptions ''PublishDiagnosticsClientCapabilities
data PublishDiagnosticsParams =
PublishDiagnosticsParams
{
_uri :: Uri
, _version :: Maybe Int
, _diagnostics :: List Diagnostic
} deriving (Read,Show,Eq)
deriveJSON lspOptions ''PublishDiagnosticsParams