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)
2121import Data.Map (Map )
2222import qualified Data.Map.Strict as Map
2323import Data.Text (Text )
24- import GHC.Exts (Int (.. ), dataToTag #)
24+ import GHC.Exts (Int (.. ), dataToTag #, Any )
2525import Unsafe.Coerce (unsafeCoerce )
2626
2727import Language.LSP.Types.Method (Method (.. ), SMethod (.. ))
2828
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'.
2932data 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))
3140
3241toIx :: SMethod a -> Int
3342toIx k = I # (dataToTag# k)
You can’t perform that action at this time.
0 commit comments