File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
lsp-types/src/Language/LSP/Types Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -21,13 +21,22 @@ import Data.Kind (Type)
21
21
import Data.Map (Map )
22
22
import qualified Data.Map.Strict as Map
23
23
import Data.Text (Text )
24
- import GHC.Exts (Int (.. ), dataToTag #)
24
+ import GHC.Exts (Int (.. ), dataToTag #, Any )
25
25
import Unsafe.Coerce (unsafeCoerce )
26
26
27
27
import Language.LSP.Types.Method (Method (.. ), SMethod (.. ))
28
28
29
+ -- This type exists to avoid a dependency on 'dependent-map'. It is less
30
+ -- safe (since we use 'unsafeCoerce') but much simpler and hence easier to include.
31
+ -- | A specialized altenative to a full dependent map for use with 'SMethod'.
29
32
data SMethodMap (v :: Method f t -> Type ) =
30
- SMethodMap ! (IntMap (v 'CustomMethod)) ! (Map Text (v 'CustomMethod))
33
+ -- This works by using an 'IntMap' indexed by constructor tag for the majority
34
+ -- of 'SMethod's, which have no parameters, and hence can only appear once as keys
35
+ -- in the map. We do not attempt to be truly dependent here, and instead exploit
36
+ -- 'usafeCoerce' to go to and from 'v Any'.
37
+ -- The sole exception is 'SCustomMethod', for which we keep a separate map from
38
+ -- its 'Text' parameter (and where we can get the type indices right).
39
+ SMethodMap ! (IntMap (v Any )) ! (Map Text (v 'CustomMethod))
31
40
32
41
toIx :: SMethod a -> Int
33
42
toIx k = I # (dataToTag# k)
You can’t perform that action at this time.
0 commit comments