13
13
{-# LANGUAGE MonadComprehensions #-}
14
14
{-# LANGUAGE MultiParamTypeClasses #-}
15
15
{-# LANGUAGE NamedFieldPuns #-}
16
- {-# LANGUAGE OverloadedLabels #-}
17
16
{-# LANGUAGE OverloadedStrings #-}
18
17
{-# LANGUAGE PatternSynonyms #-}
19
18
{-# LANGUAGE PolyKinds #-}
@@ -76,6 +75,7 @@ import Data.Default
76
75
import Data.Dependent.Map (DMap )
77
76
import qualified Data.Dependent.Map as DMap
78
77
import qualified Data.DList as DList
78
+ import Data.Foldable (foldl' )
79
79
import Data.GADT.Compare
80
80
import Data.Hashable (Hashable )
81
81
import Data.HashMap.Strict (HashMap )
@@ -560,7 +560,7 @@ instance PluginRequestMethod Method_TextDocumentCodeAction where
560
560
-- should check whether the requested kind is a *prefix* of the action kind.
561
561
-- That means, for example, we will return actions with kinds `quickfix.import` and
562
562
-- `quickfix.somethingElse` if the requested kind is `quickfix`.
563
- , Just caKind <- ca ^. L. kind = any (\ k -> k `codeActionKindSubsumes` caKind) allowed
563
+ , Just caKind <- ca ^. L. kind = any (`codeActionKindSubsumes` caKind) allowed
564
564
| otherwise = False
565
565
566
566
instance PluginRequestMethod Method_CodeActionResolve where
@@ -569,10 +569,10 @@ instance PluginRequestMethod Method_CodeActionResolve where
569
569
combineResponses _ _ _ _ (x :| _) = x
570
570
571
571
instance PluginRequestMethod Method_TextDocumentDefinition where
572
- combineResponses _ _ _ _ (x :| _ ) = x
572
+ combineResponses _ _ _ _ (x :| xs ) = foldl' mergeDefinitions x xs
573
573
574
574
instance PluginRequestMethod Method_TextDocumentTypeDefinition where
575
- combineResponses _ _ _ _ (x :| _ ) = x
575
+ combineResponses _ _ _ _ (x :| xs ) = foldl' mergeDefinitions x xs
576
576
577
577
instance PluginRequestMethod Method_TextDocumentDocumentHighlight where
578
578
@@ -693,6 +693,24 @@ nullToMaybe' :: (a |? (b |? Null)) -> Maybe (a |? b)
693
693
nullToMaybe' (InL x) = Just $ InL x
694
694
nullToMaybe' (InR (InL x)) = Just $ InR x
695
695
nullToMaybe' (InR (InR _)) = Nothing
696
+
697
+ type Definitions = (Definition |? ([DefinitionLink ] |? Null ))
698
+
699
+ mergeDefinitions :: Definitions -> Definitions -> Definitions
700
+ mergeDefinitions definitions1 definitions2 = case (definitions1, definitions2) of
701
+ (InR (InR Null ), def2) -> def2
702
+ (def1, InR (InR Null )) -> def1
703
+ (InL def1, InL def2) -> InR $ InL (defToLinks def1 ++ defToLinks def2)
704
+ (InL def1, InR (InL links)) -> InR $ InL (defToLinks def1 ++ links)
705
+ (InR (InL links), InL def2) -> InR $ InL (links ++ defToLinks def2)
706
+ (InR (InL links1), InR (InL links2)) -> InR $ InL (links1 ++ links2)
707
+ where
708
+ defToLinks :: Definition -> [DefinitionLink ]
709
+ defToLinks (Definition (InL location)) = [DefinitionLink $ locationToLocationLink location]
710
+ defToLinks (Definition (InR locations)) = map (DefinitionLink . locationToLocationLink) locations
711
+
712
+ locationToLocationLink :: Location -> LocationLink
713
+ locationToLocationLink Location {_uri, _range} = LocationLink {_originSelectionRange = Just _range, _targetUri = _uri, _targetRange = _range, _targetSelectionRange = _range}
696
714
-- ---------------------------------------------------------------------
697
715
-- Plugin Notifications
698
716
-- ---------------------------------------------------------------------
@@ -942,7 +960,7 @@ mkResolveHandler m f = mkPluginHandler m $ \ideState plId params -> do
942
960
-- as this is filtered out in `pluginEnabled`
943
961
_ -> throwError $ PluginInternalError invalidRequest
944
962
where invalidRequest = " The resolve request incorrectly got routed to the wrong resolve handler!"
945
- parseError value err = " Unable to decode: " <> ( T. pack $ show value) <> " . Error: " <> ( T. pack $ show err)
963
+ parseError value err = " Unable to decode: " <> T. pack ( show value) <> " . Error: " <> T. pack ( show err)
946
964
947
965
wrapResolveData :: L. HasData_ a (Maybe Value ) => PluginId -> Uri -> a -> a
948
966
wrapResolveData pid uri hasData =
0 commit comments