@@ -62,6 +62,7 @@ data PluginDescriptor ideState =
62
62
, pluginRules :: ! (Rules () )
63
63
, pluginCommands :: ! [PluginCommand ideState ]
64
64
, pluginHandlers :: PluginHandlers ideState
65
+ , pluginNotificationHandlers :: PluginNotificationHandlers ideState
65
66
}
66
67
67
68
-- | Methods that can be handled by plugins.
@@ -180,18 +181,59 @@ instance PluginMethod TextDocumentRangeFormatting where
180
181
pluginEnabled _ pid conf = (PluginId $ formattingProvider conf) == pid
181
182
combineResponses _ _ _ _ (x :| _) = x
182
183
184
+ -- ---------------------------------------------------------------------
185
+
186
+ -- | Notifications that can be handled by plugins.
187
+ -- 'ExtraParams' captures any extra data the IDE passes to the handlers for this method
188
+ class HasTracing (MessageParams m ) => PluginNotification m where
189
+
190
+ -- | Parse the configuration to check if this plugin is enabled
191
+ pluginEnabledNotification :: SMethod m -> PluginId -> Config -> Bool
192
+
193
+ instance PluginNotification TextDocumentDidOpen where
194
+ pluginEnabledNotification _ _ _ = True
195
+
196
+ instance PluginNotification TextDocumentDidChange where
197
+ pluginEnabledNotification _ _ _ = True
198
+
199
+ instance PluginNotification TextDocumentDidSave where
200
+ pluginEnabledNotification _ _ _ = True
201
+
202
+ -- ---------------------------------------------------------------------
203
+
183
204
-- | Methods which have a PluginMethod instance
184
205
data IdeMethod (m :: Method FromClient Request ) = PluginMethod m => IdeMethod (SMethod m )
185
206
instance GEq IdeMethod where
186
207
geq (IdeMethod a) (IdeMethod b) = geq a b
187
208
instance GCompare IdeMethod where
188
209
gcompare (IdeMethod a) (IdeMethod b) = gcompare a b
189
210
211
+ -- | Methods which have a PluginMethod instance
212
+ data IdeNotification (m :: Method FromClient Notification ) = PluginNotification m => IdeNotification (SMethod m )
213
+ instance GEq IdeNotification where
214
+ geq (IdeNotification a) (IdeNotification b) = geq a b
215
+ instance GCompare IdeNotification where
216
+ gcompare (IdeNotification a) (IdeNotification b) = gcompare a b
217
+
190
218
-- | Combine handlers for the
191
219
newtype PluginHandler a (m :: Method FromClient Request )
192
220
= PluginHandler (PluginId -> a -> MessageParams m -> LspM Config (NonEmpty (Either ResponseError (ResponseResult m ))))
193
221
194
- newtype PluginHandlers a = PluginHandlers (DMap IdeMethod (PluginHandler a ))
222
+ newtype PluginNotificationHandler a (m :: Method FromClient Notification )
223
+ = PluginNotificationHandler (PluginId -> a -> MessageParams m -> LspM Config (NonEmpty () ))
224
+ -- newtype PluginNotificationHandler a (m :: Method FromClient Notification)
225
+ -- = PluginNotificationHandler (PluginNotificationMethodHandler a m)`
226
+
227
+ {-
228
+ From Zubin
229
+ alanz_: I would say `newtype PluginNotificationHandler a (m :: Method FromClient Notification) = PluginNotificationHandler (PluginNotificationMethodHandler a m)`
230
+ 16:28 and `newtype PluginNotificationHandlers a = PluginNotificationHandlers (DMap SMethod (PluginNotificationHandler a))
231
+
232
+ -}
233
+
234
+ newtype PluginHandlers a = PluginHandlers (DMap IdeMethod (PluginHandler a ))
235
+ newtype PluginNotificationHandlers a = PluginNotificationHandlers (DMap IdeNotification (PluginNotificationHandler a ))
236
+ -- newtype PluginNotificationHandlers a = PluginNotificationHandlers (DMap SMethod (PluginNotificationHandler a))
195
237
196
238
instance Semigroup (PluginHandlers a ) where
197
239
(PluginHandlers a) <> (PluginHandlers b) = PluginHandlers $ DMap. unionWithKey go a b
@@ -202,8 +244,19 @@ instance Semigroup (PluginHandlers a) where
202
244
instance Monoid (PluginHandlers a ) where
203
245
mempty = PluginHandlers mempty
204
246
247
+ instance Semigroup (PluginNotificationHandlers a ) where
248
+ (PluginNotificationHandlers a) <> (PluginNotificationHandlers b) = PluginNotificationHandlers $ DMap. unionWithKey go a b
249
+ where
250
+ go _ (PluginNotificationHandler f) (PluginNotificationHandler g) = PluginNotificationHandler $ \ pid ide params ->
251
+ f pid ide params >> g pid ide params
252
+
253
+ instance Monoid (PluginNotificationHandlers a ) where
254
+ mempty = PluginNotificationHandlers mempty
255
+
205
256
type PluginMethodHandler a m = a -> PluginId -> MessageParams m -> LspM Config (Either ResponseError (ResponseResult m ))
206
257
258
+ type PluginNotificationMethodHandler a m = a -> PluginId -> MessageParams m -> LspM Config ()
259
+
207
260
-- | Make a handler for plugins with no extra data
208
261
mkPluginHandler
209
262
:: PluginMethod m
@@ -214,13 +267,25 @@ mkPluginHandler m f = PluginHandlers $ DMap.singleton (IdeMethod m) (PluginHandl
214
267
where
215
268
f' pid ide params = pure <$> f ide pid params
216
269
270
+ -- | Make a handler for plugins with no extra data
271
+ mkPluginNotificationHandler
272
+ :: (PluginNotification m )
273
+ => SClientMethod (m :: Method FromClient Notification )
274
+ -> PluginNotificationMethodHandler ideState m
275
+ -> PluginNotificationHandlers ideState
276
+ mkPluginNotificationHandler m f
277
+ = PluginNotificationHandlers $ DMap. singleton (IdeNotification m) (PluginNotificationHandler f')
278
+ where
279
+ f' pid ide params = pure <$> f ide pid params
280
+
217
281
defaultPluginDescriptor :: PluginId -> PluginDescriptor ideState
218
282
defaultPluginDescriptor plId =
219
283
PluginDescriptor
220
284
plId
221
285
mempty
222
286
mempty
223
287
mempty
288
+ mempty
224
289
225
290
newtype CommandId = CommandId T. Text
226
291
deriving (Show , Read , Eq , Ord )
0 commit comments