{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedLists       #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE ScopedTypeVariables   #-}
{-# LANGUAGE TemplateHaskell       #-}
module Language.LSP.Types.SemanticTokens where

import qualified Data.Aeson                                   as A
import           Data.Aeson.TH
import           Data.Text                                    (Text)

import           Control.Monad.Except

import           Language.LSP.Types.Common
import           Language.LSP.Types.Location
import           Language.LSP.Types.Progress
import           Language.LSP.Types.StaticRegistrationOptions
import           Language.LSP.Types.TextDocument
import           Language.LSP.Types.Utils

import qualified Data.Algorithm.Diff                          as Diff
import qualified Data.Bits                                    as Bits
import qualified Data.DList                                   as DList
import           Data.Default
import           Data.Foldable                                hiding (length)
import qualified Data.Map                                     as Map
import           Data.Maybe                                   (fromMaybe,
                                                               maybeToList)
import           Data.String

data SemanticTokenTypes =
  SttNamespace
  | SttType
  | SttClass
  | SttEnum
  | SttInterface
  | SttStruct
  | SttTypeParameter
  | SttParameter
  | SttVariable
  | SttProperty
  | SttEnumMember
  | SttEvent
  | SttFunction
  | SttMethod
  | SttMacro
  | SttKeyword
  | SttModifier
  | SttComment
  | SttString
  | SttNumber
  | SttRegexp
  | SttOperator
  | SttUnknown Text
  deriving (Int -> SemanticTokenTypes -> ShowS
[SemanticTokenTypes] -> ShowS
SemanticTokenTypes -> String
(Int -> SemanticTokenTypes -> ShowS)
-> (SemanticTokenTypes -> String)
-> ([SemanticTokenTypes] -> ShowS)
-> Show SemanticTokenTypes
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SemanticTokenTypes -> ShowS
showsPrec :: Int -> SemanticTokenTypes -> ShowS
$cshow :: SemanticTokenTypes -> String
show :: SemanticTokenTypes -> String
$cshowList :: [SemanticTokenTypes] -> ShowS
showList :: [SemanticTokenTypes] -> ShowS
Show, ReadPrec [SemanticTokenTypes]
ReadPrec SemanticTokenTypes
Int -> ReadS SemanticTokenTypes
ReadS [SemanticTokenTypes]
(Int -> ReadS SemanticTokenTypes)
-> ReadS [SemanticTokenTypes]
-> ReadPrec SemanticTokenTypes
-> ReadPrec [SemanticTokenTypes]
-> Read SemanticTokenTypes
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SemanticTokenTypes
readsPrec :: Int -> ReadS SemanticTokenTypes
$creadList :: ReadS [SemanticTokenTypes]
readList :: ReadS [SemanticTokenTypes]
$creadPrec :: ReadPrec SemanticTokenTypes
readPrec :: ReadPrec SemanticTokenTypes
$creadListPrec :: ReadPrec [SemanticTokenTypes]
readListPrec :: ReadPrec [SemanticTokenTypes]
Read, SemanticTokenTypes -> SemanticTokenTypes -> Bool
(SemanticTokenTypes -> SemanticTokenTypes -> Bool)
-> (SemanticTokenTypes -> SemanticTokenTypes -> Bool)
-> Eq SemanticTokenTypes
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SemanticTokenTypes -> SemanticTokenTypes -> Bool
== :: SemanticTokenTypes -> SemanticTokenTypes -> Bool
$c/= :: SemanticTokenTypes -> SemanticTokenTypes -> Bool
/= :: SemanticTokenTypes -> SemanticTokenTypes -> Bool
Eq, Eq SemanticTokenTypes
Eq SemanticTokenTypes =>
(SemanticTokenTypes -> SemanticTokenTypes -> Ordering)
-> (SemanticTokenTypes -> SemanticTokenTypes -> Bool)
-> (SemanticTokenTypes -> SemanticTokenTypes -> Bool)
-> (SemanticTokenTypes -> SemanticTokenTypes -> Bool)
-> (SemanticTokenTypes -> SemanticTokenTypes -> Bool)
-> (SemanticTokenTypes -> SemanticTokenTypes -> SemanticTokenTypes)
-> (SemanticTokenTypes -> SemanticTokenTypes -> SemanticTokenTypes)
-> Ord SemanticTokenTypes
SemanticTokenTypes -> SemanticTokenTypes -> Bool
SemanticTokenTypes -> SemanticTokenTypes -> Ordering
SemanticTokenTypes -> SemanticTokenTypes -> SemanticTokenTypes
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SemanticTokenTypes -> SemanticTokenTypes -> Ordering
compare :: SemanticTokenTypes -> SemanticTokenTypes -> Ordering
$c< :: SemanticTokenTypes -> SemanticTokenTypes -> Bool
< :: SemanticTokenTypes -> SemanticTokenTypes -> Bool
$c<= :: SemanticTokenTypes -> SemanticTokenTypes -> Bool
<= :: SemanticTokenTypes -> SemanticTokenTypes -> Bool
$c> :: SemanticTokenTypes -> SemanticTokenTypes -> Bool
> :: SemanticTokenTypes -> SemanticTokenTypes -> Bool
$c>= :: SemanticTokenTypes -> SemanticTokenTypes -> Bool
>= :: SemanticTokenTypes -> SemanticTokenTypes -> Bool
$cmax :: SemanticTokenTypes -> SemanticTokenTypes -> SemanticTokenTypes
max :: SemanticTokenTypes -> SemanticTokenTypes -> SemanticTokenTypes
$cmin :: SemanticTokenTypes -> SemanticTokenTypes -> SemanticTokenTypes
min :: SemanticTokenTypes -> SemanticTokenTypes -> SemanticTokenTypes
Ord)

instance A.ToJSON SemanticTokenTypes where
  toJSON :: SemanticTokenTypes -> Value
toJSON SemanticTokenTypes
SttNamespace     = Text -> Value
A.String Text
"namespace"
  toJSON SemanticTokenTypes
SttType          = Text -> Value
A.String Text
"type"
  toJSON SemanticTokenTypes
SttClass         = Text -> Value
A.String Text
"class"
  toJSON SemanticTokenTypes
SttEnum          = Text -> Value
A.String Text
"enum"
  toJSON SemanticTokenTypes
SttInterface     = Text -> Value
A.String Text
"interface"
  toJSON SemanticTokenTypes
SttStruct        = Text -> Value
A.String Text
"struct"
  toJSON SemanticTokenTypes
SttTypeParameter = Text -> Value
A.String Text
"typeParameter"
  toJSON SemanticTokenTypes
SttParameter     = Text -> Value
A.String Text
"parameter"
  toJSON SemanticTokenTypes
SttVariable      = Text -> Value
A.String Text
"variable"
  toJSON SemanticTokenTypes
SttProperty      = Text -> Value
A.String Text
"property"
  toJSON SemanticTokenTypes
SttEnumMember    = Text -> Value
A.String Text
"enumMember"
  toJSON SemanticTokenTypes
SttEvent         = Text -> Value
A.String Text
"event"
  toJSON SemanticTokenTypes
SttFunction      = Text -> Value
A.String Text
"function"
  toJSON SemanticTokenTypes
SttMethod        = Text -> Value
A.String Text
"method"
  toJSON SemanticTokenTypes
SttMacro         = Text -> Value
A.String Text
"macro"
  toJSON SemanticTokenTypes
SttKeyword       = Text -> Value
A.String Text
"keyword"
  toJSON SemanticTokenTypes
SttModifier      = Text -> Value
A.String Text
"modifier"
  toJSON SemanticTokenTypes
SttComment       = Text -> Value
A.String Text
"comment"
  toJSON SemanticTokenTypes
SttString        = Text -> Value
A.String Text
"string"
  toJSON SemanticTokenTypes
SttNumber        = Text -> Value
A.String Text
"number"
  toJSON SemanticTokenTypes
SttRegexp        = Text -> Value
A.String Text
"regexp"
  toJSON SemanticTokenTypes
SttOperator      = Text -> Value
A.String Text
"operator"
  toJSON (SttUnknown Text
t)   = Text -> Value
A.String Text
t

instance A.FromJSON SemanticTokenTypes where
  parseJSON :: Value -> Parser SemanticTokenTypes
parseJSON (A.String Text
"namespace")     = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttNamespace
  parseJSON (A.String Text
"type")          = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttType
  parseJSON (A.String Text
"class")         = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttClass
  parseJSON (A.String Text
"enum")          = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttEnum
  parseJSON (A.String Text
"interface")     = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttInterface
  parseJSON (A.String Text
"struct")        = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttStruct
  parseJSON (A.String Text
"typeParameter") = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttTypeParameter
  parseJSON (A.String Text
"parameter")     = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttParameter
  parseJSON (A.String Text
"variable")      = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttVariable
  parseJSON (A.String Text
"property")      = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttProperty
  parseJSON (A.String Text
"enumMember")    = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttEnumMember
  parseJSON (A.String Text
"event")         = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttEvent
  parseJSON (A.String Text
"function")      = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttFunction
  parseJSON (A.String Text
"method")        = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttMethod
  parseJSON (A.String Text
"macro")         = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttMacro
  parseJSON (A.String Text
"keyword")       = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttKeyword
  parseJSON (A.String Text
"modifier")      = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttModifier
  parseJSON (A.String Text
"comment")       = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttComment
  parseJSON (A.String Text
"string")        = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttString
  parseJSON (A.String Text
"number")        = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttNumber
  parseJSON (A.String Text
"regexp")        = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttRegexp
  parseJSON (A.String Text
"operator")      = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenTypes
SttOperator
  parseJSON (A.String Text
t)               = SemanticTokenTypes -> Parser SemanticTokenTypes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SemanticTokenTypes -> Parser SemanticTokenTypes)
-> SemanticTokenTypes -> Parser SemanticTokenTypes
forall a b. (a -> b) -> a -> b
$ Text -> SemanticTokenTypes
SttUnknown Text
t
  parseJSON Value
_                          = Parser SemanticTokenTypes
forall a. Monoid a => a
mempty

-- | The set of semantic token types which are "known" (i.e. listed in the LSP spec).
knownSemanticTokenTypes :: [SemanticTokenTypes]
knownSemanticTokenTypes :: [SemanticTokenTypes]
knownSemanticTokenTypes = [
  Item [SemanticTokenTypes]
SemanticTokenTypes
SttNamespace
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttType
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttClass
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttEnum
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttInterface
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttStruct
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttTypeParameter
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttParameter
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttVariable
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttProperty
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttEnumMember
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttEvent
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttFunction
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttMethod
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttMacro
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttKeyword
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttModifier
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttComment
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttString
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttNumber
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttRegexp
  , Item [SemanticTokenTypes]
SemanticTokenTypes
SttOperator
  ]

data SemanticTokenModifiers =
  StmDeclaration
  | StmDefinition
  | StmReadonly
  | StmStatic
  | StmDeprecated
  | StmAbstract
  | StmAsync
  | StmModification
  | StmDocumentation
  | StmDefaultLibrary
  | StmUnknown Text
  deriving (Int -> SemanticTokenModifiers -> ShowS
[SemanticTokenModifiers] -> ShowS
SemanticTokenModifiers -> String
(Int -> SemanticTokenModifiers -> ShowS)
-> (SemanticTokenModifiers -> String)
-> ([SemanticTokenModifiers] -> ShowS)
-> Show SemanticTokenModifiers
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SemanticTokenModifiers -> ShowS
showsPrec :: Int -> SemanticTokenModifiers -> ShowS
$cshow :: SemanticTokenModifiers -> String
show :: SemanticTokenModifiers -> String
$cshowList :: [SemanticTokenModifiers] -> ShowS
showList :: [SemanticTokenModifiers] -> ShowS
Show, ReadPrec [SemanticTokenModifiers]
ReadPrec SemanticTokenModifiers
Int -> ReadS SemanticTokenModifiers
ReadS [SemanticTokenModifiers]
(Int -> ReadS SemanticTokenModifiers)
-> ReadS [SemanticTokenModifiers]
-> ReadPrec SemanticTokenModifiers
-> ReadPrec [SemanticTokenModifiers]
-> Read SemanticTokenModifiers
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SemanticTokenModifiers
readsPrec :: Int -> ReadS SemanticTokenModifiers
$creadList :: ReadS [SemanticTokenModifiers]
readList :: ReadS [SemanticTokenModifiers]
$creadPrec :: ReadPrec SemanticTokenModifiers
readPrec :: ReadPrec SemanticTokenModifiers
$creadListPrec :: ReadPrec [SemanticTokenModifiers]
readListPrec :: ReadPrec [SemanticTokenModifiers]
Read, SemanticTokenModifiers -> SemanticTokenModifiers -> Bool
(SemanticTokenModifiers -> SemanticTokenModifiers -> Bool)
-> (SemanticTokenModifiers -> SemanticTokenModifiers -> Bool)
-> Eq SemanticTokenModifiers
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SemanticTokenModifiers -> SemanticTokenModifiers -> Bool
== :: SemanticTokenModifiers -> SemanticTokenModifiers -> Bool
$c/= :: SemanticTokenModifiers -> SemanticTokenModifiers -> Bool
/= :: SemanticTokenModifiers -> SemanticTokenModifiers -> Bool
Eq, Eq SemanticTokenModifiers
Eq SemanticTokenModifiers =>
(SemanticTokenModifiers -> SemanticTokenModifiers -> Ordering)
-> (SemanticTokenModifiers -> SemanticTokenModifiers -> Bool)
-> (SemanticTokenModifiers -> SemanticTokenModifiers -> Bool)
-> (SemanticTokenModifiers -> SemanticTokenModifiers -> Bool)
-> (SemanticTokenModifiers -> SemanticTokenModifiers -> Bool)
-> (SemanticTokenModifiers
    -> SemanticTokenModifiers -> SemanticTokenModifiers)
-> (SemanticTokenModifiers
    -> SemanticTokenModifiers -> SemanticTokenModifiers)
-> Ord SemanticTokenModifiers
SemanticTokenModifiers -> SemanticTokenModifiers -> Bool
SemanticTokenModifiers -> SemanticTokenModifiers -> Ordering
SemanticTokenModifiers
-> SemanticTokenModifiers -> SemanticTokenModifiers
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SemanticTokenModifiers -> SemanticTokenModifiers -> Ordering
compare :: SemanticTokenModifiers -> SemanticTokenModifiers -> Ordering
$c< :: SemanticTokenModifiers -> SemanticTokenModifiers -> Bool
< :: SemanticTokenModifiers -> SemanticTokenModifiers -> Bool
$c<= :: SemanticTokenModifiers -> SemanticTokenModifiers -> Bool
<= :: SemanticTokenModifiers -> SemanticTokenModifiers -> Bool
$c> :: SemanticTokenModifiers -> SemanticTokenModifiers -> Bool
> :: SemanticTokenModifiers -> SemanticTokenModifiers -> Bool
$c>= :: SemanticTokenModifiers -> SemanticTokenModifiers -> Bool
>= :: SemanticTokenModifiers -> SemanticTokenModifiers -> Bool
$cmax :: SemanticTokenModifiers
-> SemanticTokenModifiers -> SemanticTokenModifiers
max :: SemanticTokenModifiers
-> SemanticTokenModifiers -> SemanticTokenModifiers
$cmin :: SemanticTokenModifiers
-> SemanticTokenModifiers -> SemanticTokenModifiers
min :: SemanticTokenModifiers
-> SemanticTokenModifiers -> SemanticTokenModifiers
Ord)

instance A.ToJSON SemanticTokenModifiers where
  toJSON :: SemanticTokenModifiers -> Value
toJSON SemanticTokenModifiers
StmDeclaration    = Text -> Value
A.String Text
"declaration"
  toJSON SemanticTokenModifiers
StmDefinition     = Text -> Value
A.String Text
"definition"
  toJSON SemanticTokenModifiers
StmReadonly       = Text -> Value
A.String Text
"readonly"
  toJSON SemanticTokenModifiers
StmStatic         = Text -> Value
A.String Text
"static"
  toJSON SemanticTokenModifiers
StmDeprecated     = Text -> Value
A.String Text
"deprecated"
  toJSON SemanticTokenModifiers
StmAbstract       = Text -> Value
A.String Text
"abstract"
  toJSON SemanticTokenModifiers
StmAsync          = Text -> Value
A.String Text
"async"
  toJSON SemanticTokenModifiers
StmModification   = Text -> Value
A.String Text
"modification"
  toJSON SemanticTokenModifiers
StmDocumentation  = Text -> Value
A.String Text
"documentation"
  toJSON SemanticTokenModifiers
StmDefaultLibrary = Text -> Value
A.String Text
"defaultLibrary"
  toJSON (StmUnknown Text
t)    = Text -> Value
A.String Text
t

instance A.FromJSON SemanticTokenModifiers where
  parseJSON :: Value -> Parser SemanticTokenModifiers
parseJSON (A.String Text
"declaration")    = SemanticTokenModifiers -> Parser SemanticTokenModifiers
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenModifiers
StmDeclaration
  parseJSON (A.String Text
"definition")     = SemanticTokenModifiers -> Parser SemanticTokenModifiers
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenModifiers
StmDefinition
  parseJSON (A.String Text
"readonly")       = SemanticTokenModifiers -> Parser SemanticTokenModifiers
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenModifiers
StmReadonly
  parseJSON (A.String Text
"static")         = SemanticTokenModifiers -> Parser SemanticTokenModifiers
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenModifiers
StmStatic
  parseJSON (A.String Text
"deprecated")     = SemanticTokenModifiers -> Parser SemanticTokenModifiers
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenModifiers
StmDeprecated
  parseJSON (A.String Text
"abstract")       = SemanticTokenModifiers -> Parser SemanticTokenModifiers
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenModifiers
StmAbstract
  parseJSON (A.String Text
"async")          = SemanticTokenModifiers -> Parser SemanticTokenModifiers
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenModifiers
StmAsync
  parseJSON (A.String Text
"modification")   = SemanticTokenModifiers -> Parser SemanticTokenModifiers
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenModifiers
StmModification
  parseJSON (A.String Text
"documentation")  = SemanticTokenModifiers -> Parser SemanticTokenModifiers
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenModifiers
StmDocumentation
  parseJSON (A.String Text
"defaultLibrary") = SemanticTokenModifiers -> Parser SemanticTokenModifiers
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SemanticTokenModifiers
StmDefaultLibrary
  parseJSON (A.String Text
t)                = SemanticTokenModifiers -> Parser SemanticTokenModifiers
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SemanticTokenModifiers -> Parser SemanticTokenModifiers)
-> SemanticTokenModifiers -> Parser SemanticTokenModifiers
forall a b. (a -> b) -> a -> b
$ Text -> SemanticTokenModifiers
StmUnknown Text
t
  parseJSON Value
_                           = Parser SemanticTokenModifiers
forall a. Monoid a => a
mempty

-- | The set of semantic token modifiers which are "known" (i.e. listed in the LSP spec).
knownSemanticTokenModifiers :: [SemanticTokenModifiers]
knownSemanticTokenModifiers :: [SemanticTokenModifiers]
knownSemanticTokenModifiers = [
  Item [SemanticTokenModifiers]
SemanticTokenModifiers
StmDeclaration
  , Item [SemanticTokenModifiers]
SemanticTokenModifiers
StmDefinition
  , Item [SemanticTokenModifiers]
SemanticTokenModifiers
StmReadonly
  , Item [SemanticTokenModifiers]
SemanticTokenModifiers
StmStatic
  , Item [SemanticTokenModifiers]
SemanticTokenModifiers
StmDeprecated
  , Item [SemanticTokenModifiers]
SemanticTokenModifiers
StmAbstract
  , Item [SemanticTokenModifiers]
SemanticTokenModifiers
StmAsync
  , Item [SemanticTokenModifiers]
SemanticTokenModifiers
StmModification
  , Item [SemanticTokenModifiers]
SemanticTokenModifiers
StmDocumentation
  , Item [SemanticTokenModifiers]
SemanticTokenModifiers
StmDefaultLibrary
  ]

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

instance A.ToJSON TokenFormat where
  toJSON :: TokenFormat -> Value
toJSON TokenFormat
TokenFormatRelative = Text -> Value
A.String Text
"relative"

instance A.FromJSON TokenFormat where
  parseJSON :: Value -> Parser TokenFormat
parseJSON (A.String Text
"relative") = TokenFormat -> Parser TokenFormat
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure TokenFormat
TokenFormatRelative
  parseJSON Value
_                     = Parser TokenFormat
forall a. Monoid a => a
mempty

data SemanticTokensLegend = SemanticTokensLegend {
  -- | The token types a server uses.
  SemanticTokensLegend -> List SemanticTokenTypes
_tokenTypes     :: List SemanticTokenTypes,
  -- | The token modifiers a server uses.
  SemanticTokensLegend -> List SemanticTokenModifiers
_tokenModifiers :: List SemanticTokenModifiers
} deriving (Int -> SemanticTokensLegend -> ShowS
[SemanticTokensLegend] -> ShowS
SemanticTokensLegend -> String
(Int -> SemanticTokensLegend -> ShowS)
-> (SemanticTokensLegend -> String)
-> ([SemanticTokensLegend] -> ShowS)
-> Show SemanticTokensLegend
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SemanticTokensLegend -> ShowS
showsPrec :: Int -> SemanticTokensLegend -> ShowS
$cshow :: SemanticTokensLegend -> String
show :: SemanticTokensLegend -> String
$cshowList :: [SemanticTokensLegend] -> ShowS
showList :: [SemanticTokensLegend] -> ShowS
Show, ReadPrec [SemanticTokensLegend]
ReadPrec SemanticTokensLegend
Int -> ReadS SemanticTokensLegend
ReadS [SemanticTokensLegend]
(Int -> ReadS SemanticTokensLegend)
-> ReadS [SemanticTokensLegend]
-> ReadPrec SemanticTokensLegend
-> ReadPrec [SemanticTokensLegend]
-> Read SemanticTokensLegend
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SemanticTokensLegend
readsPrec :: Int -> ReadS SemanticTokensLegend
$creadList :: ReadS [SemanticTokensLegend]
readList :: ReadS [SemanticTokensLegend]
$creadPrec :: ReadPrec SemanticTokensLegend
readPrec :: ReadPrec SemanticTokensLegend
$creadListPrec :: ReadPrec [SemanticTokensLegend]
readListPrec :: ReadPrec [SemanticTokensLegend]
Read, SemanticTokensLegend -> SemanticTokensLegend -> Bool
(SemanticTokensLegend -> SemanticTokensLegend -> Bool)
-> (SemanticTokensLegend -> SemanticTokensLegend -> Bool)
-> Eq SemanticTokensLegend
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SemanticTokensLegend -> SemanticTokensLegend -> Bool
== :: SemanticTokensLegend -> SemanticTokensLegend -> Bool
$c/= :: SemanticTokensLegend -> SemanticTokensLegend -> Bool
/= :: SemanticTokensLegend -> SemanticTokensLegend -> Bool
Eq)
deriveJSON lspOptions ''SemanticTokensLegend

-- We give a default legend which just lists the "known" types and modifiers in the order they're listed.
instance Default SemanticTokensLegend where
  def :: SemanticTokensLegend
def = List SemanticTokenTypes
-> List SemanticTokenModifiers -> SemanticTokensLegend
SemanticTokensLegend ([SemanticTokenTypes] -> List SemanticTokenTypes
forall a. [a] -> List a
List [SemanticTokenTypes]
knownSemanticTokenTypes) ([SemanticTokenModifiers] -> List SemanticTokenModifiers
forall a. [a] -> List a
List [SemanticTokenModifiers]
knownSemanticTokenModifiers)

data SemanticTokensRangeClientCapabilities = SemanticTokensRangeBool Bool | SemanticTokensRangeObj A.Value
  deriving (Int -> SemanticTokensRangeClientCapabilities -> ShowS
[SemanticTokensRangeClientCapabilities] -> ShowS
SemanticTokensRangeClientCapabilities -> String
(Int -> SemanticTokensRangeClientCapabilities -> ShowS)
-> (SemanticTokensRangeClientCapabilities -> String)
-> ([SemanticTokensRangeClientCapabilities] -> ShowS)
-> Show SemanticTokensRangeClientCapabilities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SemanticTokensRangeClientCapabilities -> ShowS
showsPrec :: Int -> SemanticTokensRangeClientCapabilities -> ShowS
$cshow :: SemanticTokensRangeClientCapabilities -> String
show :: SemanticTokensRangeClientCapabilities -> String
$cshowList :: [SemanticTokensRangeClientCapabilities] -> ShowS
showList :: [SemanticTokensRangeClientCapabilities] -> ShowS
Show, ReadPrec [SemanticTokensRangeClientCapabilities]
ReadPrec SemanticTokensRangeClientCapabilities
Int -> ReadS SemanticTokensRangeClientCapabilities
ReadS [SemanticTokensRangeClientCapabilities]
(Int -> ReadS SemanticTokensRangeClientCapabilities)
-> ReadS [SemanticTokensRangeClientCapabilities]
-> ReadPrec SemanticTokensRangeClientCapabilities
-> ReadPrec [SemanticTokensRangeClientCapabilities]
-> Read SemanticTokensRangeClientCapabilities
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SemanticTokensRangeClientCapabilities
readsPrec :: Int -> ReadS SemanticTokensRangeClientCapabilities
$creadList :: ReadS [SemanticTokensRangeClientCapabilities]
readList :: ReadS [SemanticTokensRangeClientCapabilities]
$creadPrec :: ReadPrec SemanticTokensRangeClientCapabilities
readPrec :: ReadPrec SemanticTokensRangeClientCapabilities
$creadListPrec :: ReadPrec [SemanticTokensRangeClientCapabilities]
readListPrec :: ReadPrec [SemanticTokensRangeClientCapabilities]
Read, SemanticTokensRangeClientCapabilities
-> SemanticTokensRangeClientCapabilities -> Bool
(SemanticTokensRangeClientCapabilities
 -> SemanticTokensRangeClientCapabilities -> Bool)
-> (SemanticTokensRangeClientCapabilities
    -> SemanticTokensRangeClientCapabilities -> Bool)
-> Eq SemanticTokensRangeClientCapabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SemanticTokensRangeClientCapabilities
-> SemanticTokensRangeClientCapabilities -> Bool
== :: SemanticTokensRangeClientCapabilities
-> SemanticTokensRangeClientCapabilities -> Bool
$c/= :: SemanticTokensRangeClientCapabilities
-> SemanticTokensRangeClientCapabilities -> Bool
/= :: SemanticTokensRangeClientCapabilities
-> SemanticTokensRangeClientCapabilities -> Bool
Eq)
deriveJSON lspOptionsUntagged ''SemanticTokensRangeClientCapabilities

data SemanticTokensDeltaClientCapabilities = SemanticTokensDeltaClientCapabilities {
  -- | The client will send the `textDocument/semanticTokens/full/delta`
  -- request if the server provides a corresponding handler.
  SemanticTokensDeltaClientCapabilities -> Maybe Bool
_delta :: Maybe Bool
} deriving (Int -> SemanticTokensDeltaClientCapabilities -> ShowS
[SemanticTokensDeltaClientCapabilities] -> ShowS
SemanticTokensDeltaClientCapabilities -> String
(Int -> SemanticTokensDeltaClientCapabilities -> ShowS)
-> (SemanticTokensDeltaClientCapabilities -> String)
-> ([SemanticTokensDeltaClientCapabilities] -> ShowS)
-> Show SemanticTokensDeltaClientCapabilities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SemanticTokensDeltaClientCapabilities -> ShowS
showsPrec :: Int -> SemanticTokensDeltaClientCapabilities -> ShowS
$cshow :: SemanticTokensDeltaClientCapabilities -> String
show :: SemanticTokensDeltaClientCapabilities -> String
$cshowList :: [SemanticTokensDeltaClientCapabilities] -> ShowS
showList :: [SemanticTokensDeltaClientCapabilities] -> ShowS
Show, ReadPrec [SemanticTokensDeltaClientCapabilities]
ReadPrec SemanticTokensDeltaClientCapabilities
Int -> ReadS SemanticTokensDeltaClientCapabilities
ReadS [SemanticTokensDeltaClientCapabilities]
(Int -> ReadS SemanticTokensDeltaClientCapabilities)
-> ReadS [SemanticTokensDeltaClientCapabilities]
-> ReadPrec SemanticTokensDeltaClientCapabilities
-> ReadPrec [SemanticTokensDeltaClientCapabilities]
-> Read SemanticTokensDeltaClientCapabilities
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SemanticTokensDeltaClientCapabilities
readsPrec :: Int -> ReadS SemanticTokensDeltaClientCapabilities
$creadList :: ReadS [SemanticTokensDeltaClientCapabilities]
readList :: ReadS [SemanticTokensDeltaClientCapabilities]
$creadPrec :: ReadPrec SemanticTokensDeltaClientCapabilities
readPrec :: ReadPrec SemanticTokensDeltaClientCapabilities
$creadListPrec :: ReadPrec [SemanticTokensDeltaClientCapabilities]
readListPrec :: ReadPrec [SemanticTokensDeltaClientCapabilities]
Read, SemanticTokensDeltaClientCapabilities
-> SemanticTokensDeltaClientCapabilities -> Bool
(SemanticTokensDeltaClientCapabilities
 -> SemanticTokensDeltaClientCapabilities -> Bool)
-> (SemanticTokensDeltaClientCapabilities
    -> SemanticTokensDeltaClientCapabilities -> Bool)
-> Eq SemanticTokensDeltaClientCapabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SemanticTokensDeltaClientCapabilities
-> SemanticTokensDeltaClientCapabilities -> Bool
== :: SemanticTokensDeltaClientCapabilities
-> SemanticTokensDeltaClientCapabilities -> Bool
$c/= :: SemanticTokensDeltaClientCapabilities
-> SemanticTokensDeltaClientCapabilities -> Bool
/= :: SemanticTokensDeltaClientCapabilities
-> SemanticTokensDeltaClientCapabilities -> Bool
Eq)
deriveJSON lspOptions ''SemanticTokensDeltaClientCapabilities

data SemanticTokensFullClientCapabilities = SemanticTokensFullBool Bool | SemanticTokensFullDelta SemanticTokensDeltaClientCapabilities
  deriving (Int -> SemanticTokensFullClientCapabilities -> ShowS
[SemanticTokensFullClientCapabilities] -> ShowS
SemanticTokensFullClientCapabilities -> String
(Int -> SemanticTokensFullClientCapabilities -> ShowS)
-> (SemanticTokensFullClientCapabilities -> String)
-> ([SemanticTokensFullClientCapabilities] -> ShowS)
-> Show SemanticTokensFullClientCapabilities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SemanticTokensFullClientCapabilities -> ShowS
showsPrec :: Int -> SemanticTokensFullClientCapabilities -> ShowS
$cshow :: SemanticTokensFullClientCapabilities -> String
show :: SemanticTokensFullClientCapabilities -> String
$cshowList :: [SemanticTokensFullClientCapabilities] -> ShowS
showList :: [SemanticTokensFullClientCapabilities] -> ShowS
Show, ReadPrec [SemanticTokensFullClientCapabilities]
ReadPrec SemanticTokensFullClientCapabilities
Int -> ReadS SemanticTokensFullClientCapabilities
ReadS [SemanticTokensFullClientCapabilities]
(Int -> ReadS SemanticTokensFullClientCapabilities)
-> ReadS [SemanticTokensFullClientCapabilities]
-> ReadPrec SemanticTokensFullClientCapabilities
-> ReadPrec [SemanticTokensFullClientCapabilities]
-> Read SemanticTokensFullClientCapabilities
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SemanticTokensFullClientCapabilities
readsPrec :: Int -> ReadS SemanticTokensFullClientCapabilities
$creadList :: ReadS [SemanticTokensFullClientCapabilities]
readList :: ReadS [SemanticTokensFullClientCapabilities]
$creadPrec :: ReadPrec SemanticTokensFullClientCapabilities
readPrec :: ReadPrec SemanticTokensFullClientCapabilities
$creadListPrec :: ReadPrec [SemanticTokensFullClientCapabilities]
readListPrec :: ReadPrec [SemanticTokensFullClientCapabilities]
Read, SemanticTokensFullClientCapabilities
-> SemanticTokensFullClientCapabilities -> Bool
(SemanticTokensFullClientCapabilities
 -> SemanticTokensFullClientCapabilities -> Bool)
-> (SemanticTokensFullClientCapabilities
    -> SemanticTokensFullClientCapabilities -> Bool)
-> Eq SemanticTokensFullClientCapabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SemanticTokensFullClientCapabilities
-> SemanticTokensFullClientCapabilities -> Bool
== :: SemanticTokensFullClientCapabilities
-> SemanticTokensFullClientCapabilities -> Bool
$c/= :: SemanticTokensFullClientCapabilities
-> SemanticTokensFullClientCapabilities -> Bool
/= :: SemanticTokensFullClientCapabilities
-> SemanticTokensFullClientCapabilities -> Bool
Eq)
deriveJSON lspOptionsUntagged ''SemanticTokensFullClientCapabilities

data SemanticTokensRequestsClientCapabilities = SemanticTokensRequestsClientCapabilities {
  -- | The client will send the `textDocument/semanticTokens/range` request
  -- if the server provides a corresponding handler.
  SemanticTokensRequestsClientCapabilities
-> Maybe SemanticTokensRangeClientCapabilities
_range :: Maybe SemanticTokensRangeClientCapabilities,
  -- | The client will send the `textDocument/semanticTokens/full` request
  -- if the server provides a corresponding handler.
  SemanticTokensRequestsClientCapabilities
-> Maybe SemanticTokensFullClientCapabilities
_full  :: Maybe SemanticTokensFullClientCapabilities
} deriving (Int -> SemanticTokensRequestsClientCapabilities -> ShowS
[SemanticTokensRequestsClientCapabilities] -> ShowS
SemanticTokensRequestsClientCapabilities -> String
(Int -> SemanticTokensRequestsClientCapabilities -> ShowS)
-> (SemanticTokensRequestsClientCapabilities -> String)
-> ([SemanticTokensRequestsClientCapabilities] -> ShowS)
-> Show SemanticTokensRequestsClientCapabilities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SemanticTokensRequestsClientCapabilities -> ShowS
showsPrec :: Int -> SemanticTokensRequestsClientCapabilities -> ShowS
$cshow :: SemanticTokensRequestsClientCapabilities -> String
show :: SemanticTokensRequestsClientCapabilities -> String
$cshowList :: [SemanticTokensRequestsClientCapabilities] -> ShowS
showList :: [SemanticTokensRequestsClientCapabilities] -> ShowS
Show, ReadPrec [SemanticTokensRequestsClientCapabilities]
ReadPrec SemanticTokensRequestsClientCapabilities
Int -> ReadS SemanticTokensRequestsClientCapabilities
ReadS [SemanticTokensRequestsClientCapabilities]
(Int -> ReadS SemanticTokensRequestsClientCapabilities)
-> ReadS [SemanticTokensRequestsClientCapabilities]
-> ReadPrec SemanticTokensRequestsClientCapabilities
-> ReadPrec [SemanticTokensRequestsClientCapabilities]
-> Read SemanticTokensRequestsClientCapabilities
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SemanticTokensRequestsClientCapabilities
readsPrec :: Int -> ReadS SemanticTokensRequestsClientCapabilities
$creadList :: ReadS [SemanticTokensRequestsClientCapabilities]
readList :: ReadS [SemanticTokensRequestsClientCapabilities]
$creadPrec :: ReadPrec SemanticTokensRequestsClientCapabilities
readPrec :: ReadPrec SemanticTokensRequestsClientCapabilities
$creadListPrec :: ReadPrec [SemanticTokensRequestsClientCapabilities]
readListPrec :: ReadPrec [SemanticTokensRequestsClientCapabilities]
Read, SemanticTokensRequestsClientCapabilities
-> SemanticTokensRequestsClientCapabilities -> Bool
(SemanticTokensRequestsClientCapabilities
 -> SemanticTokensRequestsClientCapabilities -> Bool)
-> (SemanticTokensRequestsClientCapabilities
    -> SemanticTokensRequestsClientCapabilities -> Bool)
-> Eq SemanticTokensRequestsClientCapabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SemanticTokensRequestsClientCapabilities
-> SemanticTokensRequestsClientCapabilities -> Bool
== :: SemanticTokensRequestsClientCapabilities
-> SemanticTokensRequestsClientCapabilities -> Bool
$c/= :: SemanticTokensRequestsClientCapabilities
-> SemanticTokensRequestsClientCapabilities -> Bool
/= :: SemanticTokensRequestsClientCapabilities
-> SemanticTokensRequestsClientCapabilities -> Bool
Eq)
deriveJSON lspOptions ''SemanticTokensRequestsClientCapabilities

data SemanticTokensClientCapabilities = SemanticTokensClientCapabilities {
  -- | Whether implementation supports dynamic registration. If this is set to
  -- `true` the client supports the new `(TextDocumentRegistrationOptions &
  -- StaticRegistrationOptions)` return value for the corresponding server
  -- capability as well.
  SemanticTokensClientCapabilities -> Maybe Bool
_dynamicRegistration     :: Maybe Bool,

  -- | Which requests the client supports and might send to the server
  -- depending on the server's capability. Please note that clients might not
  -- show semantic tokens or degrade some of the user experience if a range
  -- or full request is advertised by the client but not provided by the
  -- server. If for example the client capability `requests.full` and
  -- `request.range` are both set to true but the server only provides a
  -- range provider the client might not render a minimap correctly or might
  -- even decide to not show any semantic tokens at all.
  SemanticTokensClientCapabilities
-> SemanticTokensRequestsClientCapabilities
_requests                :: SemanticTokensRequestsClientCapabilities,

  -- | The token types that the client supports.
  SemanticTokensClientCapabilities -> List SemanticTokenTypes
_tokenTypes              :: List SemanticTokenTypes,

  -- | The token modifiers that the client supports.
  SemanticTokensClientCapabilities -> List SemanticTokenModifiers
_tokenModifiers          :: List SemanticTokenModifiers,

  -- | The formats the clients supports.
  SemanticTokensClientCapabilities -> List TokenFormat
_formats                 :: List TokenFormat,

  -- | Whether the client supports tokens that can overlap each other.
  SemanticTokensClientCapabilities -> Maybe Bool
_overlappingTokenSupport :: Maybe Bool,

  -- | Whether the client supports tokens that can span multiple lines.
  SemanticTokensClientCapabilities -> Maybe Bool
_multilineTokenSupport   :: Maybe Bool
} deriving (Int -> SemanticTokensClientCapabilities -> ShowS
[SemanticTokensClientCapabilities] -> ShowS
SemanticTokensClientCapabilities -> String
(Int -> SemanticTokensClientCapabilities -> ShowS)
-> (SemanticTokensClientCapabilities -> String)
-> ([SemanticTokensClientCapabilities] -> ShowS)
-> Show SemanticTokensClientCapabilities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SemanticTokensClientCapabilities -> ShowS
showsPrec :: Int -> SemanticTokensClientCapabilities -> ShowS
$cshow :: SemanticTokensClientCapabilities -> String
show :: SemanticTokensClientCapabilities -> String
$cshowList :: [SemanticTokensClientCapabilities] -> ShowS
showList :: [SemanticTokensClientCapabilities] -> ShowS
Show, ReadPrec [SemanticTokensClientCapabilities]
ReadPrec SemanticTokensClientCapabilities
Int -> ReadS SemanticTokensClientCapabilities
ReadS [SemanticTokensClientCapabilities]
(Int -> ReadS SemanticTokensClientCapabilities)
-> ReadS [SemanticTokensClientCapabilities]
-> ReadPrec SemanticTokensClientCapabilities
-> ReadPrec [SemanticTokensClientCapabilities]
-> Read SemanticTokensClientCapabilities
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SemanticTokensClientCapabilities
readsPrec :: Int -> ReadS SemanticTokensClientCapabilities
$creadList :: ReadS [SemanticTokensClientCapabilities]
readList :: ReadS [SemanticTokensClientCapabilities]
$creadPrec :: ReadPrec SemanticTokensClientCapabilities
readPrec :: ReadPrec SemanticTokensClientCapabilities
$creadListPrec :: ReadPrec [SemanticTokensClientCapabilities]
readListPrec :: ReadPrec [SemanticTokensClientCapabilities]
Read, SemanticTokensClientCapabilities
-> SemanticTokensClientCapabilities -> Bool
(SemanticTokensClientCapabilities
 -> SemanticTokensClientCapabilities -> Bool)
-> (SemanticTokensClientCapabilities
    -> SemanticTokensClientCapabilities -> Bool)
-> Eq SemanticTokensClientCapabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SemanticTokensClientCapabilities
-> SemanticTokensClientCapabilities -> Bool
== :: SemanticTokensClientCapabilities
-> SemanticTokensClientCapabilities -> Bool
$c/= :: SemanticTokensClientCapabilities
-> SemanticTokensClientCapabilities -> Bool
/= :: SemanticTokensClientCapabilities
-> SemanticTokensClientCapabilities -> Bool
Eq)
deriveJSON lspOptions ''SemanticTokensClientCapabilities

makeExtendingDatatype "SemanticTokensOptions" [''WorkDoneProgressOptions]
  [ ("_legend", [t| SemanticTokensLegend |])
  , ("_range", [t| Maybe SemanticTokensRangeClientCapabilities |])
  , ("_full", [t| Maybe SemanticTokensFullClientCapabilities |])
  ]
deriveJSON lspOptions ''SemanticTokensOptions

makeExtendingDatatype "SemanticTokensRegistrationOptions"
  [ ''TextDocumentRegistrationOptions
  , ''SemanticTokensOptions
  , ''StaticRegistrationOptions] []
deriveJSON lspOptions ''SemanticTokensRegistrationOptions

makeExtendingDatatype "SemanticTokensParams"
  [''WorkDoneProgressParams
  , ''PartialResultParams]
  [ ("_textDocument", [t| TextDocumentIdentifier |]) ]
deriveJSON lspOptions ''SemanticTokensParams

data SemanticTokens = SemanticTokens {
  -- | An optional result id. If provided and clients support delta updating
  -- the client will include the result id in the next semantic token request.
  -- A server can then instead of computing all semantic tokens again simply
  -- send a delta.
  SemanticTokens -> Maybe Text
_resultId :: Maybe Text,

  -- | The actual tokens.
  SemanticTokens -> List UInt
_xdata    :: List UInt
} deriving (Int -> SemanticTokens -> ShowS
[SemanticTokens] -> ShowS
SemanticTokens -> String
(Int -> SemanticTokens -> ShowS)
-> (SemanticTokens -> String)
-> ([SemanticTokens] -> ShowS)
-> Show SemanticTokens
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SemanticTokens -> ShowS
showsPrec :: Int -> SemanticTokens -> ShowS
$cshow :: SemanticTokens -> String
show :: SemanticTokens -> String
$cshowList :: [SemanticTokens] -> ShowS
showList :: [SemanticTokens] -> ShowS
Show, ReadPrec [SemanticTokens]
ReadPrec SemanticTokens
Int -> ReadS SemanticTokens
ReadS [SemanticTokens]
(Int -> ReadS SemanticTokens)
-> ReadS [SemanticTokens]
-> ReadPrec SemanticTokens
-> ReadPrec [SemanticTokens]
-> Read SemanticTokens
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SemanticTokens
readsPrec :: Int -> ReadS SemanticTokens
$creadList :: ReadS [SemanticTokens]
readList :: ReadS [SemanticTokens]
$creadPrec :: ReadPrec SemanticTokens
readPrec :: ReadPrec SemanticTokens
$creadListPrec :: ReadPrec [SemanticTokens]
readListPrec :: ReadPrec [SemanticTokens]
Read, SemanticTokens -> SemanticTokens -> Bool
(SemanticTokens -> SemanticTokens -> Bool)
-> (SemanticTokens -> SemanticTokens -> Bool) -> Eq SemanticTokens
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SemanticTokens -> SemanticTokens -> Bool
== :: SemanticTokens -> SemanticTokens -> Bool
$c/= :: SemanticTokens -> SemanticTokens -> Bool
/= :: SemanticTokens -> SemanticTokens -> Bool
Eq)
deriveJSON lspOptions ''SemanticTokens

data SemanticTokensPartialResult = SemanticTokensPartialResult {
  SemanticTokensPartialResult -> List UInt
_xdata :: List UInt
}
deriveJSON lspOptions ''SemanticTokensPartialResult

makeExtendingDatatype "SemanticTokensDeltaParams"
  [''WorkDoneProgressParams
  , ''PartialResultParams]
  [ ("_textDocument", [t| TextDocumentIdentifier  |])
  , ("_previousResultId", [t| Text |])
  ]
deriveJSON lspOptions ''SemanticTokensDeltaParams

data SemanticTokensEdit = SemanticTokensEdit {
  -- | The start offset of the edit.
  SemanticTokensEdit -> UInt
_start       :: UInt,
  -- | The count of elements to remove.
  SemanticTokensEdit -> UInt
_deleteCount :: UInt,
  -- | The elements to insert.
  SemanticTokensEdit -> Maybe (List UInt)
_xdata       :: Maybe (List UInt)
} deriving (Int -> SemanticTokensEdit -> ShowS
[SemanticTokensEdit] -> ShowS
SemanticTokensEdit -> String
(Int -> SemanticTokensEdit -> ShowS)
-> (SemanticTokensEdit -> String)
-> ([SemanticTokensEdit] -> ShowS)
-> Show SemanticTokensEdit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SemanticTokensEdit -> ShowS
showsPrec :: Int -> SemanticTokensEdit -> ShowS
$cshow :: SemanticTokensEdit -> String
show :: SemanticTokensEdit -> String
$cshowList :: [SemanticTokensEdit] -> ShowS
showList :: [SemanticTokensEdit] -> ShowS
Show, ReadPrec [SemanticTokensEdit]
ReadPrec SemanticTokensEdit
Int -> ReadS SemanticTokensEdit
ReadS [SemanticTokensEdit]
(Int -> ReadS SemanticTokensEdit)
-> ReadS [SemanticTokensEdit]
-> ReadPrec SemanticTokensEdit
-> ReadPrec [SemanticTokensEdit]
-> Read SemanticTokensEdit
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SemanticTokensEdit
readsPrec :: Int -> ReadS SemanticTokensEdit
$creadList :: ReadS [SemanticTokensEdit]
readList :: ReadS [SemanticTokensEdit]
$creadPrec :: ReadPrec SemanticTokensEdit
readPrec :: ReadPrec SemanticTokensEdit
$creadListPrec :: ReadPrec [SemanticTokensEdit]
readListPrec :: ReadPrec [SemanticTokensEdit]
Read, SemanticTokensEdit -> SemanticTokensEdit -> Bool
(SemanticTokensEdit -> SemanticTokensEdit -> Bool)
-> (SemanticTokensEdit -> SemanticTokensEdit -> Bool)
-> Eq SemanticTokensEdit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SemanticTokensEdit -> SemanticTokensEdit -> Bool
== :: SemanticTokensEdit -> SemanticTokensEdit -> Bool
$c/= :: SemanticTokensEdit -> SemanticTokensEdit -> Bool
/= :: SemanticTokensEdit -> SemanticTokensEdit -> Bool
Eq)
deriveJSON lspOptions ''SemanticTokensEdit

data SemanticTokensDelta = SemanticTokensDelta {
  SemanticTokensDelta -> Maybe Text
_resultId :: Maybe Text,
  -- | The semantic token edits to transform a previous result into a new
  -- result.
  SemanticTokensDelta -> List SemanticTokensEdit
_edits    :: List SemanticTokensEdit
} deriving (Int -> SemanticTokensDelta -> ShowS
[SemanticTokensDelta] -> ShowS
SemanticTokensDelta -> String
(Int -> SemanticTokensDelta -> ShowS)
-> (SemanticTokensDelta -> String)
-> ([SemanticTokensDelta] -> ShowS)
-> Show SemanticTokensDelta
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SemanticTokensDelta -> ShowS
showsPrec :: Int -> SemanticTokensDelta -> ShowS
$cshow :: SemanticTokensDelta -> String
show :: SemanticTokensDelta -> String
$cshowList :: [SemanticTokensDelta] -> ShowS
showList :: [SemanticTokensDelta] -> ShowS
Show, ReadPrec [SemanticTokensDelta]
ReadPrec SemanticTokensDelta
Int -> ReadS SemanticTokensDelta
ReadS [SemanticTokensDelta]
(Int -> ReadS SemanticTokensDelta)
-> ReadS [SemanticTokensDelta]
-> ReadPrec SemanticTokensDelta
-> ReadPrec [SemanticTokensDelta]
-> Read SemanticTokensDelta
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SemanticTokensDelta
readsPrec :: Int -> ReadS SemanticTokensDelta
$creadList :: ReadS [SemanticTokensDelta]
readList :: ReadS [SemanticTokensDelta]
$creadPrec :: ReadPrec SemanticTokensDelta
readPrec :: ReadPrec SemanticTokensDelta
$creadListPrec :: ReadPrec [SemanticTokensDelta]
readListPrec :: ReadPrec [SemanticTokensDelta]
Read, SemanticTokensDelta -> SemanticTokensDelta -> Bool
(SemanticTokensDelta -> SemanticTokensDelta -> Bool)
-> (SemanticTokensDelta -> SemanticTokensDelta -> Bool)
-> Eq SemanticTokensDelta
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SemanticTokensDelta -> SemanticTokensDelta -> Bool
== :: SemanticTokensDelta -> SemanticTokensDelta -> Bool
$c/= :: SemanticTokensDelta -> SemanticTokensDelta -> Bool
/= :: SemanticTokensDelta -> SemanticTokensDelta -> Bool
Eq)
deriveJSON lspOptions ''SemanticTokensDelta

data SemanticTokensDeltaPartialResult = SemantictokensDeltaPartialResult {
  SemanticTokensDeltaPartialResult -> List SemanticTokensEdit
_edits :: List SemanticTokensEdit
} deriving (Int -> SemanticTokensDeltaPartialResult -> ShowS
[SemanticTokensDeltaPartialResult] -> ShowS
SemanticTokensDeltaPartialResult -> String
(Int -> SemanticTokensDeltaPartialResult -> ShowS)
-> (SemanticTokensDeltaPartialResult -> String)
-> ([SemanticTokensDeltaPartialResult] -> ShowS)
-> Show SemanticTokensDeltaPartialResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SemanticTokensDeltaPartialResult -> ShowS
showsPrec :: Int -> SemanticTokensDeltaPartialResult -> ShowS
$cshow :: SemanticTokensDeltaPartialResult -> String
show :: SemanticTokensDeltaPartialResult -> String
$cshowList :: [SemanticTokensDeltaPartialResult] -> ShowS
showList :: [SemanticTokensDeltaPartialResult] -> ShowS
Show, ReadPrec [SemanticTokensDeltaPartialResult]
ReadPrec SemanticTokensDeltaPartialResult
Int -> ReadS SemanticTokensDeltaPartialResult
ReadS [SemanticTokensDeltaPartialResult]
(Int -> ReadS SemanticTokensDeltaPartialResult)
-> ReadS [SemanticTokensDeltaPartialResult]
-> ReadPrec SemanticTokensDeltaPartialResult
-> ReadPrec [SemanticTokensDeltaPartialResult]
-> Read SemanticTokensDeltaPartialResult
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SemanticTokensDeltaPartialResult
readsPrec :: Int -> ReadS SemanticTokensDeltaPartialResult
$creadList :: ReadS [SemanticTokensDeltaPartialResult]
readList :: ReadS [SemanticTokensDeltaPartialResult]
$creadPrec :: ReadPrec SemanticTokensDeltaPartialResult
readPrec :: ReadPrec SemanticTokensDeltaPartialResult
$creadListPrec :: ReadPrec [SemanticTokensDeltaPartialResult]
readListPrec :: ReadPrec [SemanticTokensDeltaPartialResult]
Read, SemanticTokensDeltaPartialResult
-> SemanticTokensDeltaPartialResult -> Bool
(SemanticTokensDeltaPartialResult
 -> SemanticTokensDeltaPartialResult -> Bool)
-> (SemanticTokensDeltaPartialResult
    -> SemanticTokensDeltaPartialResult -> Bool)
-> Eq SemanticTokensDeltaPartialResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SemanticTokensDeltaPartialResult
-> SemanticTokensDeltaPartialResult -> Bool
== :: SemanticTokensDeltaPartialResult
-> SemanticTokensDeltaPartialResult -> Bool
$c/= :: SemanticTokensDeltaPartialResult
-> SemanticTokensDeltaPartialResult -> Bool
/= :: SemanticTokensDeltaPartialResult
-> SemanticTokensDeltaPartialResult -> Bool
Eq)
deriveJSON lspOptions ''SemanticTokensDeltaPartialResult

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

data SemanticTokensWorkspaceClientCapabilities = SemanticTokensWorkspaceClientCapabilities {
  -- | Whether the client implementation supports a refresh request sent from
  -- the server to the client.
  --
  -- Note that this event is global and will force the client to refresh all
  -- semantic tokens currently shown. It should be used with absolute care
  -- and is useful for situation where a server for example detect a project
  -- wide change that requires such a calculation.
  SemanticTokensWorkspaceClientCapabilities -> Maybe Bool
_refreshSupport :: Maybe Bool
} deriving (Int -> SemanticTokensWorkspaceClientCapabilities -> ShowS
[SemanticTokensWorkspaceClientCapabilities] -> ShowS
SemanticTokensWorkspaceClientCapabilities -> String
(Int -> SemanticTokensWorkspaceClientCapabilities -> ShowS)
-> (SemanticTokensWorkspaceClientCapabilities -> String)
-> ([SemanticTokensWorkspaceClientCapabilities] -> ShowS)
-> Show SemanticTokensWorkspaceClientCapabilities
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SemanticTokensWorkspaceClientCapabilities -> ShowS
showsPrec :: Int -> SemanticTokensWorkspaceClientCapabilities -> ShowS
$cshow :: SemanticTokensWorkspaceClientCapabilities -> String
show :: SemanticTokensWorkspaceClientCapabilities -> String
$cshowList :: [SemanticTokensWorkspaceClientCapabilities] -> ShowS
showList :: [SemanticTokensWorkspaceClientCapabilities] -> ShowS
Show, ReadPrec [SemanticTokensWorkspaceClientCapabilities]
ReadPrec SemanticTokensWorkspaceClientCapabilities
Int -> ReadS SemanticTokensWorkspaceClientCapabilities
ReadS [SemanticTokensWorkspaceClientCapabilities]
(Int -> ReadS SemanticTokensWorkspaceClientCapabilities)
-> ReadS [SemanticTokensWorkspaceClientCapabilities]
-> ReadPrec SemanticTokensWorkspaceClientCapabilities
-> ReadPrec [SemanticTokensWorkspaceClientCapabilities]
-> Read SemanticTokensWorkspaceClientCapabilities
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SemanticTokensWorkspaceClientCapabilities
readsPrec :: Int -> ReadS SemanticTokensWorkspaceClientCapabilities
$creadList :: ReadS [SemanticTokensWorkspaceClientCapabilities]
readList :: ReadS [SemanticTokensWorkspaceClientCapabilities]
$creadPrec :: ReadPrec SemanticTokensWorkspaceClientCapabilities
readPrec :: ReadPrec SemanticTokensWorkspaceClientCapabilities
$creadListPrec :: ReadPrec [SemanticTokensWorkspaceClientCapabilities]
readListPrec :: ReadPrec [SemanticTokensWorkspaceClientCapabilities]
Read, SemanticTokensWorkspaceClientCapabilities
-> SemanticTokensWorkspaceClientCapabilities -> Bool
(SemanticTokensWorkspaceClientCapabilities
 -> SemanticTokensWorkspaceClientCapabilities -> Bool)
-> (SemanticTokensWorkspaceClientCapabilities
    -> SemanticTokensWorkspaceClientCapabilities -> Bool)
-> Eq SemanticTokensWorkspaceClientCapabilities
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SemanticTokensWorkspaceClientCapabilities
-> SemanticTokensWorkspaceClientCapabilities -> Bool
== :: SemanticTokensWorkspaceClientCapabilities
-> SemanticTokensWorkspaceClientCapabilities -> Bool
$c/= :: SemanticTokensWorkspaceClientCapabilities
-> SemanticTokensWorkspaceClientCapabilities -> Bool
/= :: SemanticTokensWorkspaceClientCapabilities
-> SemanticTokensWorkspaceClientCapabilities -> Bool
Eq)
deriveJSON lspOptions ''SemanticTokensWorkspaceClientCapabilities

----------------------------------------------------------
-- Tools for working with semantic tokens.
----------------------------------------------------------

-- | A single 'semantic token' as described in the LSP specification, using absolute positions.
-- This is the kind of token that is usually easiest for editors to produce.
data SemanticTokenAbsolute = SemanticTokenAbsolute {
  SemanticTokenAbsolute -> UInt
line           :: UInt,
  SemanticTokenAbsolute -> UInt
startChar      :: UInt,
  SemanticTokenAbsolute -> UInt
length         :: UInt,
  SemanticTokenAbsolute -> SemanticTokenTypes
tokenType      :: SemanticTokenTypes,
  SemanticTokenAbsolute -> [SemanticTokenModifiers]
tokenModifiers :: [SemanticTokenModifiers]
} deriving (Int -> SemanticTokenAbsolute -> ShowS
[SemanticTokenAbsolute] -> ShowS
SemanticTokenAbsolute -> String
(Int -> SemanticTokenAbsolute -> ShowS)
-> (SemanticTokenAbsolute -> String)
-> ([SemanticTokenAbsolute] -> ShowS)
-> Show SemanticTokenAbsolute
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SemanticTokenAbsolute -> ShowS
showsPrec :: Int -> SemanticTokenAbsolute -> ShowS
$cshow :: SemanticTokenAbsolute -> String
show :: SemanticTokenAbsolute -> String
$cshowList :: [SemanticTokenAbsolute] -> ShowS
showList :: [SemanticTokenAbsolute] -> ShowS
Show, ReadPrec [SemanticTokenAbsolute]
ReadPrec SemanticTokenAbsolute
Int -> ReadS SemanticTokenAbsolute
ReadS [SemanticTokenAbsolute]
(Int -> ReadS SemanticTokenAbsolute)
-> ReadS [SemanticTokenAbsolute]
-> ReadPrec SemanticTokenAbsolute
-> ReadPrec [SemanticTokenAbsolute]
-> Read SemanticTokenAbsolute
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SemanticTokenAbsolute
readsPrec :: Int -> ReadS SemanticTokenAbsolute
$creadList :: ReadS [SemanticTokenAbsolute]
readList :: ReadS [SemanticTokenAbsolute]
$creadPrec :: ReadPrec SemanticTokenAbsolute
readPrec :: ReadPrec SemanticTokenAbsolute
$creadListPrec :: ReadPrec [SemanticTokenAbsolute]
readListPrec :: ReadPrec [SemanticTokenAbsolute]
Read, SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool
(SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool)
-> (SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool)
-> Eq SemanticTokenAbsolute
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool
== :: SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool
$c/= :: SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool
/= :: SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool
Eq, Eq SemanticTokenAbsolute
Eq SemanticTokenAbsolute =>
(SemanticTokenAbsolute -> SemanticTokenAbsolute -> Ordering)
-> (SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool)
-> (SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool)
-> (SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool)
-> (SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool)
-> (SemanticTokenAbsolute
    -> SemanticTokenAbsolute -> SemanticTokenAbsolute)
-> (SemanticTokenAbsolute
    -> SemanticTokenAbsolute -> SemanticTokenAbsolute)
-> Ord SemanticTokenAbsolute
SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool
SemanticTokenAbsolute -> SemanticTokenAbsolute -> Ordering
SemanticTokenAbsolute
-> SemanticTokenAbsolute -> SemanticTokenAbsolute
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SemanticTokenAbsolute -> SemanticTokenAbsolute -> Ordering
compare :: SemanticTokenAbsolute -> SemanticTokenAbsolute -> Ordering
$c< :: SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool
< :: SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool
$c<= :: SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool
<= :: SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool
$c> :: SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool
> :: SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool
$c>= :: SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool
>= :: SemanticTokenAbsolute -> SemanticTokenAbsolute -> Bool
$cmax :: SemanticTokenAbsolute
-> SemanticTokenAbsolute -> SemanticTokenAbsolute
max :: SemanticTokenAbsolute
-> SemanticTokenAbsolute -> SemanticTokenAbsolute
$cmin :: SemanticTokenAbsolute
-> SemanticTokenAbsolute -> SemanticTokenAbsolute
min :: SemanticTokenAbsolute
-> SemanticTokenAbsolute -> SemanticTokenAbsolute
Ord)
-- Note: we want the Ord instance to sort the tokens textually: this is achieved due to the
-- order of the constructors

-- | A single 'semantic token' as described in the LSP specification, using relative positions.
data SemanticTokenRelative = SemanticTokenRelative {
  SemanticTokenRelative -> UInt
deltaLine      :: UInt,
  SemanticTokenRelative -> UInt
deltaStartChar :: UInt,
  SemanticTokenRelative -> UInt
length         :: UInt,
  SemanticTokenRelative -> SemanticTokenTypes
tokenType      :: SemanticTokenTypes,
  SemanticTokenRelative -> [SemanticTokenModifiers]
tokenModifiers :: [SemanticTokenModifiers]
} deriving (Int -> SemanticTokenRelative -> ShowS
[SemanticTokenRelative] -> ShowS
SemanticTokenRelative -> String
(Int -> SemanticTokenRelative -> ShowS)
-> (SemanticTokenRelative -> String)
-> ([SemanticTokenRelative] -> ShowS)
-> Show SemanticTokenRelative
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SemanticTokenRelative -> ShowS
showsPrec :: Int -> SemanticTokenRelative -> ShowS
$cshow :: SemanticTokenRelative -> String
show :: SemanticTokenRelative -> String
$cshowList :: [SemanticTokenRelative] -> ShowS
showList :: [SemanticTokenRelative] -> ShowS
Show, ReadPrec [SemanticTokenRelative]
ReadPrec SemanticTokenRelative
Int -> ReadS SemanticTokenRelative
ReadS [SemanticTokenRelative]
(Int -> ReadS SemanticTokenRelative)
-> ReadS [SemanticTokenRelative]
-> ReadPrec SemanticTokenRelative
-> ReadPrec [SemanticTokenRelative]
-> Read SemanticTokenRelative
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SemanticTokenRelative
readsPrec :: Int -> ReadS SemanticTokenRelative
$creadList :: ReadS [SemanticTokenRelative]
readList :: ReadS [SemanticTokenRelative]
$creadPrec :: ReadPrec SemanticTokenRelative
readPrec :: ReadPrec SemanticTokenRelative
$creadListPrec :: ReadPrec [SemanticTokenRelative]
readListPrec :: ReadPrec [SemanticTokenRelative]
Read, SemanticTokenRelative -> SemanticTokenRelative -> Bool
(SemanticTokenRelative -> SemanticTokenRelative -> Bool)
-> (SemanticTokenRelative -> SemanticTokenRelative -> Bool)
-> Eq SemanticTokenRelative
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SemanticTokenRelative -> SemanticTokenRelative -> Bool
== :: SemanticTokenRelative -> SemanticTokenRelative -> Bool
$c/= :: SemanticTokenRelative -> SemanticTokenRelative -> Bool
/= :: SemanticTokenRelative -> SemanticTokenRelative -> Bool
Eq, Eq SemanticTokenRelative
Eq SemanticTokenRelative =>
(SemanticTokenRelative -> SemanticTokenRelative -> Ordering)
-> (SemanticTokenRelative -> SemanticTokenRelative -> Bool)
-> (SemanticTokenRelative -> SemanticTokenRelative -> Bool)
-> (SemanticTokenRelative -> SemanticTokenRelative -> Bool)
-> (SemanticTokenRelative -> SemanticTokenRelative -> Bool)
-> (SemanticTokenRelative
    -> SemanticTokenRelative -> SemanticTokenRelative)
-> (SemanticTokenRelative
    -> SemanticTokenRelative -> SemanticTokenRelative)
-> Ord SemanticTokenRelative
SemanticTokenRelative -> SemanticTokenRelative -> Bool
SemanticTokenRelative -> SemanticTokenRelative -> Ordering
SemanticTokenRelative
-> SemanticTokenRelative -> SemanticTokenRelative
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SemanticTokenRelative -> SemanticTokenRelative -> Ordering
compare :: SemanticTokenRelative -> SemanticTokenRelative -> Ordering
$c< :: SemanticTokenRelative -> SemanticTokenRelative -> Bool
< :: SemanticTokenRelative -> SemanticTokenRelative -> Bool
$c<= :: SemanticTokenRelative -> SemanticTokenRelative -> Bool
<= :: SemanticTokenRelative -> SemanticTokenRelative -> Bool
$c> :: SemanticTokenRelative -> SemanticTokenRelative -> Bool
> :: SemanticTokenRelative -> SemanticTokenRelative -> Bool
$c>= :: SemanticTokenRelative -> SemanticTokenRelative -> Bool
>= :: SemanticTokenRelative -> SemanticTokenRelative -> Bool
$cmax :: SemanticTokenRelative
-> SemanticTokenRelative -> SemanticTokenRelative
max :: SemanticTokenRelative
-> SemanticTokenRelative -> SemanticTokenRelative
$cmin :: SemanticTokenRelative
-> SemanticTokenRelative -> SemanticTokenRelative
min :: SemanticTokenRelative
-> SemanticTokenRelative -> SemanticTokenRelative
Ord)
-- Note: we want the Ord instance to sort the tokens textually: this is achieved due to the
-- order of the constructors

-- | Turn a list of absolutely-positioned tokens into a list of relatively-positioned tokens. The tokens are assumed to be in the
-- order that they appear in the document!
relativizeTokens :: [SemanticTokenAbsolute] -> [SemanticTokenRelative]
relativizeTokens :: [SemanticTokenAbsolute] -> [SemanticTokenRelative]
relativizeTokens [SemanticTokenAbsolute]
xs = DList SemanticTokenRelative -> [SemanticTokenRelative]
forall a. DList a -> [a]
DList.toList (DList SemanticTokenRelative -> [SemanticTokenRelative])
-> DList SemanticTokenRelative -> [SemanticTokenRelative]
forall a b. (a -> b) -> a -> b
$ UInt
-> UInt
-> [SemanticTokenAbsolute]
-> DList SemanticTokenRelative
-> DList SemanticTokenRelative
go UInt
0 UInt
0 [SemanticTokenAbsolute]
xs DList SemanticTokenRelative
forall a. Monoid a => a
mempty
  where
    -- Pass an accumulator to make this tail-recursive
    go :: UInt -> UInt -> [SemanticTokenAbsolute] -> DList.DList SemanticTokenRelative -> DList.DList SemanticTokenRelative
    go :: UInt
-> UInt
-> [SemanticTokenAbsolute]
-> DList SemanticTokenRelative
-> DList SemanticTokenRelative
go UInt
_ UInt
_ [] DList SemanticTokenRelative
acc = DList SemanticTokenRelative
acc
    go UInt
lastLine UInt
lastChar (SemanticTokenAbsolute UInt
l UInt
c UInt
len SemanticTokenTypes
ty [SemanticTokenModifiers]
mods:[SemanticTokenAbsolute]
ts) DList SemanticTokenRelative
acc =
      let
        lastCharInLine :: UInt
lastCharInLine = if UInt
l UInt -> UInt -> Bool
forall a. Eq a => a -> a -> Bool
== UInt
lastLine then UInt
lastChar else UInt
0
        dl :: UInt
dl = UInt
l UInt -> UInt -> UInt
forall a. Num a => a -> a -> a
- UInt
lastLine
        dc :: UInt
dc = UInt
c UInt -> UInt -> UInt
forall a. Num a => a -> a -> a
- UInt
lastCharInLine
      in UInt
-> UInt
-> [SemanticTokenAbsolute]
-> DList SemanticTokenRelative
-> DList SemanticTokenRelative
go UInt
l UInt
c [SemanticTokenAbsolute]
ts (DList SemanticTokenRelative
-> SemanticTokenRelative -> DList SemanticTokenRelative
forall a. DList a -> a -> DList a
DList.snoc DList SemanticTokenRelative
acc (UInt
-> UInt
-> UInt
-> SemanticTokenTypes
-> [SemanticTokenModifiers]
-> SemanticTokenRelative
SemanticTokenRelative UInt
dl UInt
dc UInt
len SemanticTokenTypes
ty [SemanticTokenModifiers]
mods))

-- | Turn a list of relatively-positioned tokens into a list of absolutely-positioned tokens. The tokens are assumed to be in the
-- order that they appear in the document!
absolutizeTokens :: [SemanticTokenRelative] -> [SemanticTokenAbsolute]
absolutizeTokens :: [SemanticTokenRelative] -> [SemanticTokenAbsolute]
absolutizeTokens [SemanticTokenRelative]
xs = DList SemanticTokenAbsolute -> [SemanticTokenAbsolute]
forall a. DList a -> [a]
DList.toList (DList SemanticTokenAbsolute -> [SemanticTokenAbsolute])
-> DList SemanticTokenAbsolute -> [SemanticTokenAbsolute]
forall a b. (a -> b) -> a -> b
$ UInt
-> UInt
-> [SemanticTokenRelative]
-> DList SemanticTokenAbsolute
-> DList SemanticTokenAbsolute
go UInt
0 UInt
0 [SemanticTokenRelative]
xs DList SemanticTokenAbsolute
forall a. Monoid a => a
mempty
  where
    -- Pass an accumulator to make this tail-recursive
    go :: UInt -> UInt -> [SemanticTokenRelative] -> DList.DList SemanticTokenAbsolute -> DList.DList SemanticTokenAbsolute
    go :: UInt
-> UInt
-> [SemanticTokenRelative]
-> DList SemanticTokenAbsolute
-> DList SemanticTokenAbsolute
go UInt
_ UInt
_ [] DList SemanticTokenAbsolute
acc = DList SemanticTokenAbsolute
acc
    go UInt
lastLine UInt
lastChar (SemanticTokenRelative UInt
dl UInt
dc UInt
len SemanticTokenTypes
ty [SemanticTokenModifiers]
mods:[SemanticTokenRelative]
ts) DList SemanticTokenAbsolute
acc =
      let
        lastCharInLine :: UInt
lastCharInLine = if UInt
dl UInt -> UInt -> Bool
forall a. Eq a => a -> a -> Bool
== UInt
0 then UInt
lastChar else UInt
0
        l :: UInt
l = UInt
lastLine UInt -> UInt -> UInt
forall a. Num a => a -> a -> a
+ UInt
dl
        c :: UInt
c = UInt
lastCharInLine UInt -> UInt -> UInt
forall a. Num a => a -> a -> a
+ UInt
dc
      in UInt
-> UInt
-> [SemanticTokenRelative]
-> DList SemanticTokenAbsolute
-> DList SemanticTokenAbsolute
go UInt
l UInt
c [SemanticTokenRelative]
ts (DList SemanticTokenAbsolute
-> SemanticTokenAbsolute -> DList SemanticTokenAbsolute
forall a. DList a -> a -> DList a
DList.snoc DList SemanticTokenAbsolute
acc (UInt
-> UInt
-> UInt
-> SemanticTokenTypes
-> [SemanticTokenModifiers]
-> SemanticTokenAbsolute
SemanticTokenAbsolute UInt
l UInt
c UInt
len SemanticTokenTypes
ty [SemanticTokenModifiers]
mods))

-- | Encode a series of relatively-positioned semantic tokens into an integer array following the given legend.
encodeTokens :: SemanticTokensLegend -> [SemanticTokenRelative] -> Either Text [UInt]
encodeTokens :: SemanticTokensLegend
-> [SemanticTokenRelative] -> Either Text [UInt]
encodeTokens SemanticTokensLegend{_tokenTypes :: SemanticTokensLegend -> List SemanticTokenTypes
_tokenTypes=List [SemanticTokenTypes]
tts,_tokenModifiers :: SemanticTokensLegend -> List SemanticTokenModifiers
_tokenModifiers=List [SemanticTokenModifiers]
tms} [SemanticTokenRelative]
sts =
  DList UInt -> [UInt]
forall a. DList a -> [a]
DList.toList (DList UInt -> [UInt])
-> ([DList UInt] -> DList UInt) -> [DList UInt] -> [UInt]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [DList UInt] -> DList UInt
forall a. [DList a] -> DList a
DList.concat ([DList UInt] -> [UInt])
-> Either Text [DList UInt] -> Either Text [UInt]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (SemanticTokenRelative -> Either Text (DList UInt))
-> [SemanticTokenRelative] -> Either Text [DList UInt]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse SemanticTokenRelative -> Either Text (DList UInt)
encodeToken [SemanticTokenRelative]
sts
  where
    -- Note that there's no "fast" version of these (e.g. backed by an IntMap or similar)
    -- in general, due to the possibility  of unknown token types which are only identified by strings.
    tyMap :: Map.Map SemanticTokenTypes UInt
    tyMap :: Map SemanticTokenTypes UInt
tyMap = [(SemanticTokenTypes, UInt)] -> Map SemanticTokenTypes UInt
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(SemanticTokenTypes, UInt)] -> Map SemanticTokenTypes UInt)
-> [(SemanticTokenTypes, UInt)] -> Map SemanticTokenTypes UInt
forall a b. (a -> b) -> a -> b
$ [SemanticTokenTypes] -> [UInt] -> [(SemanticTokenTypes, UInt)]
forall a b. [a] -> [b] -> [(a, b)]
zip [SemanticTokenTypes]
tts [Item [UInt]
UInt
0..]
    modMap :: Map.Map SemanticTokenModifiers Int
    modMap :: Map SemanticTokenModifiers Int
modMap = [(SemanticTokenModifiers, Int)] -> Map SemanticTokenModifiers Int
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(SemanticTokenModifiers, Int)] -> Map SemanticTokenModifiers Int)
-> [(SemanticTokenModifiers, Int)]
-> Map SemanticTokenModifiers Int
forall a b. (a -> b) -> a -> b
$ [SemanticTokenModifiers]
-> [Int] -> [(SemanticTokenModifiers, Int)]
forall a b. [a] -> [b] -> [(a, b)]
zip [SemanticTokenModifiers]
tms [Int
Item [Int]
0..]

    lookupTy :: SemanticTokenTypes -> Either Text UInt
    lookupTy :: SemanticTokenTypes -> Either Text UInt
lookupTy SemanticTokenTypes
ty = case SemanticTokenTypes -> Map SemanticTokenTypes UInt -> Maybe UInt
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup SemanticTokenTypes
ty Map SemanticTokenTypes UInt
tyMap of
        Just UInt
tycode -> UInt -> Either Text UInt
forall a. a -> Either Text a
forall (f :: * -> *) a. Applicative f => a -> f a
pure UInt
tycode
        Maybe UInt
Nothing -> Text -> Either Text UInt
forall a. Text -> Either Text a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (Text -> Either Text UInt) -> Text -> Either Text UInt
forall a b. (a -> b) -> a -> b
$ Text
"Semantic token type " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
forall a. IsString a => String -> a
fromString (SemanticTokenTypes -> String
forall a. Show a => a -> String
show SemanticTokenTypes
ty) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" did not appear in the legend"
    lookupMod :: SemanticTokenModifiers -> Either Text Int
    lookupMod :: SemanticTokenModifiers -> Either Text Int
lookupMod SemanticTokenModifiers
modifier = case SemanticTokenModifiers
-> Map SemanticTokenModifiers Int -> Maybe Int
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup SemanticTokenModifiers
modifier Map SemanticTokenModifiers Int
modMap of
        Just Int
modcode -> Int -> Either Text Int
forall a. a -> Either Text a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
modcode
        Maybe Int
Nothing -> Text -> Either Text Int
forall a. Text -> Either Text a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (Text -> Either Text Int) -> Text -> Either Text Int
forall a b. (a -> b) -> a -> b
$ Text
"Semantic token modifier " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
forall a. IsString a => String -> a
fromString (SemanticTokenModifiers -> String
forall a. Show a => a -> String
show SemanticTokenModifiers
modifier) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" did not appear in the legend"

    -- Use a DList here for better efficiency when concatenating all these together
    encodeToken :: SemanticTokenRelative -> Either Text (DList.DList UInt)
    encodeToken :: SemanticTokenRelative -> Either Text (DList UInt)
encodeToken (SemanticTokenRelative UInt
dl UInt
dc UInt
len SemanticTokenTypes
ty [SemanticTokenModifiers]
mods) = do
      UInt
tycode <- SemanticTokenTypes -> Either Text UInt
lookupTy SemanticTokenTypes
ty
      [Int]
modcodes <- (SemanticTokenModifiers -> Either Text Int)
-> [SemanticTokenModifiers] -> Either Text [Int]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse SemanticTokenModifiers -> Either Text Int
lookupMod [SemanticTokenModifiers]
mods
      let Int
combinedModcode :: Int = (Int -> Int -> Int) -> Int -> [Int] -> Int
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Int -> Int -> Int
forall a. Bits a => a -> Int -> a
Bits.setBit Int
forall a. Bits a => a
Bits.zeroBits [Int]
modcodes

      DList UInt -> Either Text (DList UInt)
forall a. a -> Either Text a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [Item (DList UInt)
UInt
dl, Item (DList UInt)
UInt
dc, Item (DList UInt)
UInt
len, Item (DList UInt)
UInt
tycode, Int -> UInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
combinedModcode ]

-- This is basically 'SemanticTokensEdit', but slightly easier to work with.
-- | An edit to a buffer of items. 
data Edit a = Edit { forall a. Edit a -> UInt
editStart :: UInt, forall a. Edit a -> UInt
editDeleteCount :: UInt, forall a. Edit a -> [a]
editInsertions :: [a] }
  deriving (ReadPrec [Edit a]
ReadPrec (Edit a)
Int -> ReadS (Edit a)
ReadS [Edit a]
(Int -> ReadS (Edit a))
-> ReadS [Edit a]
-> ReadPrec (Edit a)
-> ReadPrec [Edit a]
-> Read (Edit a)
forall a. Read a => ReadPrec [Edit a]
forall a. Read a => ReadPrec (Edit a)
forall a. Read a => Int -> ReadS (Edit a)
forall a. Read a => ReadS [Edit a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Read a => Int -> ReadS (Edit a)
readsPrec :: Int -> ReadS (Edit a)
$creadList :: forall a. Read a => ReadS [Edit a]
readList :: ReadS [Edit a]
$creadPrec :: forall a. Read a => ReadPrec (Edit a)
readPrec :: ReadPrec (Edit a)
$creadListPrec :: forall a. Read a => ReadPrec [Edit a]
readListPrec :: ReadPrec [Edit a]
Read, Int -> Edit a -> ShowS
[Edit a] -> ShowS
Edit a -> String
(Int -> Edit a -> ShowS)
-> (Edit a -> String) -> ([Edit a] -> ShowS) -> Show (Edit a)
forall a. Show a => Int -> Edit a -> ShowS
forall a. Show a => [Edit a] -> ShowS
forall a. Show a => Edit a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Edit a -> ShowS
showsPrec :: Int -> Edit a -> ShowS
$cshow :: forall a. Show a => Edit a -> String
show :: Edit a -> String
$cshowList :: forall a. Show a => [Edit a] -> ShowS
showList :: [Edit a] -> ShowS
Show, Edit a -> Edit a -> Bool
(Edit a -> Edit a -> Bool)
-> (Edit a -> Edit a -> Bool) -> Eq (Edit a)
forall a. Eq a => Edit a -> Edit a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Edit a -> Edit a -> Bool
== :: Edit a -> Edit a -> Bool
$c/= :: forall a. Eq a => Edit a -> Edit a -> Bool
/= :: Edit a -> Edit a -> Bool
Eq, Eq (Edit a)
Eq (Edit a) =>
(Edit a -> Edit a -> Ordering)
-> (Edit a -> Edit a -> Bool)
-> (Edit a -> Edit a -> Bool)
-> (Edit a -> Edit a -> Bool)
-> (Edit a -> Edit a -> Bool)
-> (Edit a -> Edit a -> Edit a)
-> (Edit a -> Edit a -> Edit a)
-> Ord (Edit a)
Edit a -> Edit a -> Bool
Edit a -> Edit a -> Ordering
Edit a -> Edit a -> Edit a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (Edit a)
forall a. Ord a => Edit a -> Edit a -> Bool
forall a. Ord a => Edit a -> Edit a -> Ordering
forall a. Ord a => Edit a -> Edit a -> Edit a
$ccompare :: forall a. Ord a => Edit a -> Edit a -> Ordering
compare :: Edit a -> Edit a -> Ordering
$c< :: forall a. Ord a => Edit a -> Edit a -> Bool
< :: Edit a -> Edit a -> Bool
$c<= :: forall a. Ord a => Edit a -> Edit a -> Bool
<= :: Edit a -> Edit a -> Bool
$c> :: forall a. Ord a => Edit a -> Edit a -> Bool
> :: Edit a -> Edit a -> Bool
$c>= :: forall a. Ord a => Edit a -> Edit a -> Bool
>= :: Edit a -> Edit a -> Bool
$cmax :: forall a. Ord a => Edit a -> Edit a -> Edit a
max :: Edit a -> Edit a -> Edit a
$cmin :: forall a. Ord a => Edit a -> Edit a -> Edit a
min :: Edit a -> Edit a -> Edit a
Ord)

-- | Compute a list of edits that will turn the first list into the second list.
computeEdits :: Eq a => [a] -> [a] -> [Edit a]
computeEdits :: forall a. Eq a => [a] -> [a] -> [Edit a]
computeEdits [a]
l [a]
r = DList (Edit a) -> [Edit a]
forall a. DList a -> [a]
DList.toList (DList (Edit a) -> [Edit a]) -> DList (Edit a) -> [Edit a]
forall a b. (a -> b) -> a -> b
$ UInt
-> Maybe (Edit a) -> [Diff [a]] -> DList (Edit a) -> DList (Edit a)
forall a.
UInt
-> Maybe (Edit a) -> [Diff [a]] -> DList (Edit a) -> DList (Edit a)
go UInt
0 Maybe (Edit a)
forall a. Maybe a
Nothing ([a] -> [a] -> [Diff [a]]
forall a. Eq a => [a] -> [a] -> [Diff [a]]
Diff.getGroupedDiff [a]
l [a]
r) DList (Edit a)
forall a. Monoid a => a
mempty
  where
    {-
    Strategy: traverse the list of diffs, keeping the current index and (maybe) an in-progress 'Edit'.
    Whenever we see a 'Diff' that's only one side or the other, we can bundle that in to our in-progress
    'Edit'. We only have to stop if we see a 'Diff' that's on both sides (i.e. unchanged), then we
    dump the 'Edit' into the accumulator.
    We need the index, because 'Edit's need to say where they start.
    -}
    go :: UInt -> Maybe (Edit a) -> [Diff.Diff [a]] -> DList.DList (Edit a) -> DList.DList (Edit a)
    -- No more diffs: append the current edit if there is one and return
    go :: forall a.
UInt
-> Maybe (Edit a) -> [Diff [a]] -> DList (Edit a) -> DList (Edit a)
go UInt
_ Maybe (Edit a)
e [] DList (Edit a)
acc = DList (Edit a)
acc DList (Edit a) -> DList (Edit a) -> DList (Edit a)
forall a. Semigroup a => a -> a -> a
<> [Edit a] -> DList (Edit a)
forall a. [a] -> DList a
DList.fromList (Maybe (Edit a) -> [Edit a]
forall a. Maybe a -> [a]
maybeToList Maybe (Edit a)
e)

    -- Items only on the left (i.e. deletions): increment the current index, and record the count of deletions,
    -- starting a new edit if necessary.
    go UInt
ix Maybe (Edit a)
e (Diff.First [a]
ds : [Diff [a]]
rest) DList (Edit a)
acc =
      let
        deleteCount :: UInt
deleteCount = Int -> UInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> UInt) -> Int -> UInt
forall a b. (a -> b) -> a -> b
$ [a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Prelude.length [a]
ds
        edit :: Edit a
edit = Edit a -> Maybe (Edit a) -> Edit a
forall a. a -> Maybe a -> a
fromMaybe (UInt -> UInt -> [a] -> Edit a
forall a. UInt -> UInt -> [a] -> Edit a
Edit UInt
ix UInt
0 []) Maybe (Edit a)
e
      in UInt
-> Maybe (Edit a) -> [Diff [a]] -> DList (Edit a) -> DList (Edit a)
forall a.
UInt
-> Maybe (Edit a) -> [Diff [a]] -> DList (Edit a) -> DList (Edit a)
go (UInt
ix UInt -> UInt -> UInt
forall a. Num a => a -> a -> a
+ UInt
deleteCount) (Edit a -> Maybe (Edit a)
forall a. a -> Maybe a
Just (Edit a
edit{editDeleteCount=editDeleteCount edit + deleteCount})) [Diff [a]]
rest DList (Edit a)
acc
    -- Items only on the right (i.e. insertions): don't increment the current index, and record the insertions,
    -- starting a new edit if necessary.
    go UInt
ix Maybe (Edit a)
e (Diff.Second [a]
as : [Diff [a]]
rest) DList (Edit a)
acc =
      let edit :: Edit a
edit = Edit a -> Maybe (Edit a) -> Edit a
forall a. a -> Maybe a -> a
fromMaybe (UInt -> UInt -> [a] -> Edit a
forall a. UInt -> UInt -> [a] -> Edit a
Edit UInt
ix UInt
0 []) Maybe (Edit a)
e
      in UInt
-> Maybe (Edit a) -> [Diff [a]] -> DList (Edit a) -> DList (Edit a)
forall a.
UInt
-> Maybe (Edit a) -> [Diff [a]] -> DList (Edit a) -> DList (Edit a)
go UInt
ix (Edit a -> Maybe (Edit a)
forall a. a -> Maybe a
Just (Edit a
edit{editInsertions=editInsertions edit <> as})) [Diff [a]]
rest DList (Edit a)
acc

    -- Items on both sides: increment the current index appropriately (since the items appear on the left),
    -- and append the current edit (if there is one) to our list of edits (since we can't continue it with a break).
    go UInt
ix Maybe (Edit a)
e (Diff.Both [a]
bs [a]
_bs : [Diff [a]]
rest) DList (Edit a)
acc =
      let bothCount :: UInt
bothCount = Int -> UInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> UInt) -> Int -> UInt
forall a b. (a -> b) -> a -> b
$ [a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
Prelude.length [a]
bs
      in UInt
-> Maybe (Edit a) -> [Diff [a]] -> DList (Edit a) -> DList (Edit a)
forall a.
UInt
-> Maybe (Edit a) -> [Diff [a]] -> DList (Edit a) -> DList (Edit a)
go (UInt
ix UInt -> UInt -> UInt
forall a. Num a => a -> a -> a
+ UInt
bothCount) Maybe (Edit a)
forall a. Maybe a
Nothing [Diff [a]]
rest (DList (Edit a)
acc DList (Edit a) -> DList (Edit a) -> DList (Edit a)
forall a. Semigroup a => a -> a -> a
<> [Edit a] -> DList (Edit a)
forall a. [a] -> DList a
DList.fromList (Maybe (Edit a) -> [Edit a]
forall a. Maybe a -> [a]
maybeToList Maybe (Edit a)
e))

-- | Convenience method for making a 'SemanticTokens' from a list of 'SemanticTokenAbsolute's. An error may be returned if

-- The resulting 'SemanticTokens' lacks a result ID, which must be set separately if you are using that.
makeSemanticTokens :: SemanticTokensLegend -> [SemanticTokenAbsolute] -> Either Text SemanticTokens
makeSemanticTokens :: SemanticTokensLegend
-> [SemanticTokenAbsolute] -> Either Text SemanticTokens
makeSemanticTokens SemanticTokensLegend
legend [SemanticTokenAbsolute]
sts = do
  [UInt]
encoded <- SemanticTokensLegend
-> [SemanticTokenRelative] -> Either Text [UInt]
encodeTokens SemanticTokensLegend
legend ([SemanticTokenRelative] -> Either Text [UInt])
-> [SemanticTokenRelative] -> Either Text [UInt]
forall a b. (a -> b) -> a -> b
$ [SemanticTokenAbsolute] -> [SemanticTokenRelative]
relativizeTokens [SemanticTokenAbsolute]
sts
  SemanticTokens -> Either Text SemanticTokens
forall a. a -> Either Text a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SemanticTokens -> Either Text SemanticTokens)
-> SemanticTokens -> Either Text SemanticTokens
forall a b. (a -> b) -> a -> b
$ Maybe Text -> List UInt -> SemanticTokens
SemanticTokens Maybe Text
forall a. Maybe a
Nothing ([UInt] -> List UInt
forall a. [a] -> List a
List [UInt]
encoded)

-- | Convenience function for making a 'SemanticTokensDelta' from a previous and current 'SemanticTokens'.
-- The resulting 'SemanticTokensDelta' lacks a result ID, which must be set separately if you are using that.
makeSemanticTokensDelta :: SemanticTokens -> SemanticTokens -> SemanticTokensDelta
makeSemanticTokensDelta :: SemanticTokens -> SemanticTokens -> SemanticTokensDelta
makeSemanticTokensDelta SemanticTokens{_xdata :: SemanticTokens -> List UInt
_xdata=List [UInt]
prevTokens} SemanticTokens{_xdata :: SemanticTokens -> List UInt
_xdata=List [UInt]
curTokens} =
  let edits :: [Edit UInt]
edits = [UInt] -> [UInt] -> [Edit UInt]
forall a. Eq a => [a] -> [a] -> [Edit a]
computeEdits [UInt]
prevTokens [UInt]
curTokens
      stEdits :: [SemanticTokensEdit]
stEdits = (Edit UInt -> SemanticTokensEdit)
-> [Edit UInt] -> [SemanticTokensEdit]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Edit UInt
s UInt
ds [UInt]
as) -> UInt -> UInt -> Maybe (List UInt) -> SemanticTokensEdit
SemanticTokensEdit UInt
s UInt
ds (List UInt -> Maybe (List UInt)
forall a. a -> Maybe a
Just (List UInt -> Maybe (List UInt)) -> List UInt -> Maybe (List UInt)
forall a b. (a -> b) -> a -> b
$ [UInt] -> List UInt
forall a. [a] -> List a
List [UInt]
as)) [Edit UInt]
edits
  in Maybe Text -> List SemanticTokensEdit -> SemanticTokensDelta
SemanticTokensDelta Maybe Text
forall a. Maybe a
Nothing ([SemanticTokensEdit] -> List SemanticTokensEdit
forall a. [a] -> List a
List [SemanticTokensEdit]
stEdits)