22
22
23
23
module Ide.Types
24
24
( PluginDescriptor (.. ), defaultPluginDescriptor, defaultCabalPluginDescriptor
25
+ , defaultPluginPriority
25
26
, IdeCommand (.. )
26
27
, IdeMethod (.. )
27
28
, IdeNotification (.. )
@@ -61,10 +62,14 @@ import Data.Dependent.Map (DMap)
61
62
import qualified Data.Dependent.Map as DMap
62
63
import qualified Data.DList as DList
63
64
import Data.GADT.Compare
64
- import Data.List.Extra (nubOrdOn )
65
+ import Data.Hashable (Hashable )
66
+ import Data.HashMap.Strict (HashMap )
67
+ import qualified Data.HashMap.Strict as HashMap
68
+ import Data.List.Extra (sortOn )
65
69
import Data.List.NonEmpty (NonEmpty (.. ), toList )
66
70
import qualified Data.Map as Map
67
71
import Data.Maybe
72
+ import Data.Ord
68
73
import Data.Semigroup
69
74
import Data.String
70
75
import qualified Data.Text as T
@@ -94,6 +99,7 @@ import Language.LSP.Types.Lens as J (HasChildren (children),
94
99
HasTitle (title ),
95
100
HasUri (.. ))
96
101
import Language.LSP.VFS
102
+ import Numeric.Natural
97
103
import OpenTelemetry.Eventlog
98
104
import Options.Applicative (ParserInfo )
99
105
import System.FilePath
@@ -102,20 +108,16 @@ import Text.Regex.TDFA.Text ()
102
108
103
109
-- ---------------------------------------------------------------------
104
110
105
- newtype IdePlugins ideState = IdePlugins_
106
- { ipMap_ :: [(PluginId , PluginDescriptor ideState )]}
107
- deriving newtype Monoid
111
+ newtype IdePlugins ideState = IdePlugins_ { ipMap_ :: HashMap PluginId (PluginDescriptor ideState )}
112
+ deriving newtype (Semigroup , Monoid )
108
113
109
114
-- | Smart constructor that deduplicates plugins
110
115
pattern IdePlugins :: [(PluginId , PluginDescriptor ideState )] -> IdePlugins ideState
111
- pattern IdePlugins {ipMap} <- IdePlugins_ ipMap
116
+ pattern IdePlugins {ipMap} <- IdePlugins_ (sortOn ( Down . pluginPriority . snd ) . HashMap. toList -> ipMap)
112
117
where
113
- IdePlugins ipMap = IdePlugins_ {ipMap_ = nubOrdOn fst ipMap}
118
+ IdePlugins ipMap = IdePlugins_ {ipMap_ = HashMap. fromList ipMap}
114
119
{-# COMPLETE IdePlugins #-}
115
120
116
- instance Semigroup (IdePlugins s ) where
117
- IdePlugins a <> IdePlugins b = IdePlugins (a <> b)
118
-
119
121
-- | Hooks for modifying the 'DynFlags' at different times of the compilation
120
122
-- process. Plugins can install a 'DynFlagsModifications' via
121
123
-- 'pluginModifyDynflags' in their 'PluginDescriptor'.
@@ -149,6 +151,8 @@ instance Show (IdeCommand st) where show _ = "<ide command>"
149
151
data PluginDescriptor (ideState :: * ) =
150
152
PluginDescriptor { pluginId :: ! PluginId
151
153
-- ^ Unique identifier of the plugin.
154
+ , pluginPriority :: Natural
155
+ -- ^ Plugin handlers are called in priority order, higher priority first
152
156
, pluginRules :: ! (Rules () )
153
157
, pluginCommands :: ! [PluginCommand ideState ]
154
158
, pluginHandlers :: PluginHandlers ideState
@@ -631,6 +635,9 @@ mkPluginNotificationHandler m f
631
635
where
632
636
f' pid ide vfs = f ide vfs pid
633
637
638
+ defaultPluginPriority :: Natural
639
+ defaultPluginPriority = 1000
640
+
634
641
-- | Set up a plugin descriptor, initialized with default values.
635
642
-- This is plugin descriptor is prepared for @haskell@ files, such as
636
643
--
@@ -644,6 +651,7 @@ defaultPluginDescriptor :: PluginId -> PluginDescriptor ideState
644
651
defaultPluginDescriptor plId =
645
652
PluginDescriptor
646
653
plId
654
+ defaultPluginPriority
647
655
mempty
648
656
mempty
649
657
mempty
@@ -663,6 +671,7 @@ defaultCabalPluginDescriptor :: PluginId -> PluginDescriptor ideState
663
671
defaultCabalPluginDescriptor plId =
664
672
PluginDescriptor
665
673
plId
674
+ defaultPluginPriority
666
675
mempty
667
676
mempty
668
677
mempty
@@ -694,6 +703,7 @@ type CommandFunction ideState a
694
703
695
704
newtype PluginId = PluginId T. Text
696
705
deriving (Show , Read , Eq , Ord )
706
+ deriving newtype Hashable
697
707
698
708
instance IsString PluginId where
699
709
fromString = PluginId . T. pack
0 commit comments