@@ -69,6 +69,7 @@ import Language.LSP.Types.Lens as J (HasChildren (children),
69
69
import Language.LSP.VFS
70
70
import OpenTelemetry.Eventlog
71
71
import Options.Applicative (ParserInfo )
72
+ import System.FilePath
72
73
import System.IO.Unsafe
73
74
import Text.Regex.TDFA.Text ()
74
75
@@ -117,6 +118,7 @@ data PluginDescriptor ideState =
117
118
, pluginNotificationHandlers :: PluginNotificationHandlers ideState
118
119
, pluginModifyDynflags :: DynFlagsModifications
119
120
, pluginCli :: Maybe (ParserInfo (IdeCommand ideState ))
121
+ , pluginFileType :: [T. Text ]
120
122
}
121
123
122
124
-- | An existential wrapper of 'Properties'
@@ -162,7 +164,7 @@ defaultConfigDescriptor = ConfigDescriptor True False (mkCustomConfig emptyPrope
162
164
class HasTracing (MessageParams m ) => PluginMethod m where
163
165
164
166
-- | Parse the configuration to check if this plugin is enabled
165
- pluginEnabled :: SMethod m -> PluginId -> Config -> Bool
167
+ pluginEnabled :: SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> Bool
166
168
167
169
-- | How to combine responses from different plugins
168
170
combineResponses
@@ -177,11 +179,14 @@ class HasTracing (MessageParams m) => PluginMethod m where
177
179
combineResponses _method _config _caps _params = sconcat
178
180
179
181
instance PluginMethod TextDocumentCodeAction where
180
- pluginEnabled _ = pluginEnabledConfig plcCodeActionsOn
182
+ pluginEnabled _ msgParams pluginDesc
183
+ | pluginResponsible uri pluginDesc = pluginEnabledConfig plcCodeActionsOn (pluginId pluginDesc)
184
+ | otherwise = const False
185
+ where
186
+ uri = msgParams ^. J. textDocument . J. uri
181
187
combineResponses _method _config (ClientCapabilities _ textDocCaps _ _ _) (CodeActionParams _ _ _ _ context) resps =
182
188
fmap compat $ List $ filter wasRequested $ (\ (List x) -> x) $ sconcat resps
183
189
where
184
-
185
190
compat :: (Command |? CodeAction ) -> (Command |? CodeAction )
186
191
compat x@ (InL _) = x
187
192
compat x@ (InR action)
@@ -205,12 +210,31 @@ instance PluginMethod TextDocumentCodeAction where
205
210
, Just caKind <- ca ^. kind = any (\ k -> k `codeActionKindSubsumes` caKind) allowed
206
211
| otherwise = False
207
212
213
+ pluginResponsible :: Uri -> PluginDescriptor c -> Bool
214
+ pluginResponsible uri pluginDesc
215
+ | Just fp <- mfp
216
+ , T. pack (takeExtension fp) `elem` pluginFileType pluginDesc = True
217
+ | otherwise = False
218
+ where
219
+ mfp = uriToFilePath uri
220
+
208
221
instance PluginMethod TextDocumentCodeLens where
209
- pluginEnabled _ = pluginEnabledConfig plcCodeLensOn
222
+ pluginEnabled _ msgParams pluginDesc config =
223
+ pluginResponsible uri pluginDesc
224
+ && pluginEnabledConfig plcCodeLensOn (pluginId pluginDesc) config
225
+ where
226
+ uri = msgParams ^. J. textDocument . J. uri
227
+
210
228
instance PluginMethod TextDocumentRename where
211
- pluginEnabled _ = pluginEnabledConfig plcRenameOn
229
+ pluginEnabled _ msgParams pluginDesc config = pluginResponsible uri pluginDesc
230
+ && pluginEnabledConfig plcRenameOn (pluginId pluginDesc) config
231
+ where
232
+ uri = msgParams ^. J. textDocument . J. uri
212
233
instance PluginMethod TextDocumentHover where
213
- pluginEnabled _ = pluginEnabledConfig plcHoverOn
234
+ pluginEnabled _ msgParams pluginDesc config = pluginResponsible uri pluginDesc
235
+ && pluginEnabledConfig plcHoverOn (pluginId pluginDesc) config
236
+ where
237
+ uri = msgParams ^. J. textDocument . J. uri
214
238
combineResponses _ _ _ _ (catMaybes . toList -> hs) = h
215
239
where
216
240
r = listToMaybe $ mapMaybe (^. range) hs
@@ -219,7 +243,10 @@ instance PluginMethod TextDocumentHover where
219
243
hh -> Just $ Hover hh r
220
244
221
245
instance PluginMethod TextDocumentDocumentSymbol where
222
- pluginEnabled _ = pluginEnabledConfig plcSymbolsOn
246
+ pluginEnabled _ msgParams pluginDesc config = pluginResponsible uri pluginDesc
247
+ && pluginEnabledConfig plcSymbolsOn (pluginId pluginDesc) config
248
+ where
249
+ uri = msgParams ^. J. textDocument . J. uri
223
250
combineResponses _ _ (ClientCapabilities _ tdc _ _ _) params xs = res
224
251
where
225
252
uri' = params ^. textDocument . uri
@@ -241,7 +268,10 @@ instance PluginMethod TextDocumentDocumentSymbol where
241
268
in [si] <> children'
242
269
243
270
instance PluginMethod TextDocumentCompletion where
244
- pluginEnabled _ = pluginEnabledConfig plcCompletionOn
271
+ pluginEnabled _ msgParams pluginDesc config = pluginResponsible uri pluginDesc
272
+ && pluginEnabledConfig plcCompletionOn (pluginId pluginDesc) config
273
+ where
274
+ uri = msgParams ^. J. textDocument . J. uri
245
275
combineResponses _ conf _ _ (toList -> xs) = snd $ consumeCompletionResponse limit $ combine xs
246
276
where
247
277
limit = maxCompletions conf
@@ -270,32 +300,82 @@ instance PluginMethod TextDocumentCompletion where
270
300
consumeCompletionResponse n (InR (CompletionList isCompleteResponse (List xx)))
271
301
272
302
instance PluginMethod TextDocumentFormatting where
273
- pluginEnabled _ pid conf = (PluginId $ formattingProvider conf) == pid
274
- combineResponses _ _ _ _ (x :| _) = x
303
+ pluginEnabled STextDocumentFormatting msgParams pluginDesc conf =
304
+ pluginResponsible uri pluginDesc && PluginId (formattingProvider conf) == pid
305
+ where
306
+ uri = msgParams ^. J. textDocument . J. uri
307
+ pid = pluginId pluginDesc
308
+ combineResponses _ _ _ _ x = sconcat x
309
+
275
310
276
311
instance PluginMethod TextDocumentRangeFormatting where
277
- pluginEnabled _ pid conf = (PluginId $ formattingProvider conf) == pid
312
+ pluginEnabled _ msgParams pluginDesc conf = pluginResponsible uri pluginDesc
313
+ && PluginId (formattingProvider conf) == pid
314
+ where
315
+ uri = msgParams ^. J. textDocument . J. uri
316
+ pid = pluginId pluginDesc
278
317
combineResponses _ _ _ _ (x :| _) = x
279
318
280
319
instance PluginMethod TextDocumentPrepareCallHierarchy where
281
- pluginEnabled _ = pluginEnabledConfig plcCallHierarchyOn
320
+ pluginEnabled _ msgParams pluginDesc conf = pluginResponsible uri pluginDesc
321
+ && pluginEnabledConfig plcCallHierarchyOn pid conf
322
+ where
323
+ uri = msgParams ^. J. textDocument . J. uri
324
+ pid = pluginId pluginDesc
282
325
283
326
instance PluginMethod TextDocumentSelectionRange where
284
- pluginEnabled _ = pluginEnabledConfig plcSelectionRangeOn
327
+ pluginEnabled _ _ pluginDesc conf = pluginEnabledConfig plcSelectionRangeOn pid conf
328
+ where
329
+ pid = pluginId pluginDesc
285
330
combineResponses _ _ _ _ (x :| _) = x
286
331
287
332
instance PluginMethod CallHierarchyIncomingCalls where
288
- pluginEnabled _ = pluginEnabledConfig plcCallHierarchyOn
333
+ pluginEnabled _ _ pluginDesc conf = pluginEnabledConfig plcCallHierarchyOn pid conf
334
+ where
335
+ pid = pluginId pluginDesc
289
336
290
337
instance PluginMethod CallHierarchyOutgoingCalls where
291
- pluginEnabled _ = pluginEnabledConfig plcCallHierarchyOn
338
+ pluginEnabled _ _ pluginDesc conf = pluginEnabledConfig plcCallHierarchyOn pid conf
339
+ where
340
+ pid = pluginId pluginDesc
292
341
293
342
instance PluginMethod CustomMethod where
294
- pluginEnabled _ _ _ = True
343
+ pluginEnabled _ _ _ _ = True
295
344
combineResponses _ _ _ _ (x :| _) = x
296
345
297
346
-- ---------------------------------------------------------------------
298
347
348
+ class HasTracing (MessageParams m ) => PluginNotificationMethod (m :: Method FromClient Notification ) where
349
+ pluginEnabled2 :: SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> Bool
350
+
351
+ default pluginEnabled2 :: (HasTextDocument (MessageParams m ) doc , HasUri doc Uri )
352
+ => SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> Bool
353
+ pluginEnabled2 _ params desc conf = pluginResponsible uri desc && plcGlobalOn (configForPlugin conf (pluginId desc))
354
+ where
355
+ uri = params ^. J. textDocument . J. uri
356
+
357
+ instance PluginNotificationMethod TextDocumentDidOpen where
358
+
359
+ instance PluginNotificationMethod TextDocumentDidChange where
360
+
361
+ instance PluginNotificationMethod TextDocumentDidSave where
362
+
363
+ instance PluginNotificationMethod TextDocumentDidClose where
364
+
365
+ instance PluginNotificationMethod WorkspaceDidChangeWatchedFiles where
366
+ pluginEnabled2 _ _ desc conf = plcGlobalOn $ configForPlugin conf (pluginId desc)
367
+
368
+ instance PluginNotificationMethod WorkspaceDidChangeWorkspaceFolders where
369
+ pluginEnabled2 _ _ desc conf = plcGlobalOn $ configForPlugin conf (pluginId desc)
370
+
371
+ instance PluginNotificationMethod WorkspaceDidChangeConfiguration where
372
+ pluginEnabled2 _ _ desc conf = plcGlobalOn $ configForPlugin conf (pluginId desc)
373
+
374
+ instance PluginNotificationMethod Initialized where
375
+ pluginEnabled2 _ _ desc conf = plcGlobalOn $ configForPlugin conf (pluginId desc)
376
+
377
+ -- ---------------------------------------------------------------------
378
+
299
379
-- | Methods which have a PluginMethod instance
300
380
data IdeMethod (m :: Method FromClient Request ) = PluginMethod m => IdeMethod (SMethod m )
301
381
instance GEq IdeMethod where
@@ -304,7 +384,7 @@ instance GCompare IdeMethod where
304
384
gcompare (IdeMethod a) (IdeMethod b) = gcompare a b
305
385
306
386
-- | Methods which have a PluginMethod instance
307
- data IdeNotification (m :: Method FromClient Notification ) = HasTracing ( MessageParams m ) => IdeNotification (SMethod m )
387
+ data IdeNotification (m :: Method FromClient Notification ) = PluginNotificationMethod m => IdeNotification (SMethod m )
308
388
instance GEq IdeNotification where
309
389
geq (IdeNotification a) (IdeNotification b) = geq a b
310
390
instance GCompare IdeNotification where
@@ -353,7 +433,7 @@ mkPluginHandler m f = PluginHandlers $ DMap.singleton (IdeMethod m) (PluginHandl
353
433
354
434
-- | Make a handler for plugins with no extra data
355
435
mkPluginNotificationHandler
356
- :: HasTracing ( MessageParams m )
436
+ :: PluginNotificationMethod m
357
437
=> SClientMethod (m :: Method FromClient Notification )
358
438
-> PluginNotificationMethodHandler ideState m
359
439
-> PluginNotificationHandlers ideState
@@ -373,6 +453,20 @@ defaultPluginDescriptor plId =
373
453
mempty
374
454
mempty
375
455
Nothing
456
+ [" .hs" , " .lhs" ]
457
+
458
+ defaultCabalPluginDescriptor :: PluginId -> PluginDescriptor ideState
459
+ defaultCabalPluginDescriptor plId =
460
+ PluginDescriptor
461
+ plId
462
+ mempty
463
+ mempty
464
+ mempty
465
+ defaultConfigDescriptor
466
+ mempty
467
+ mempty
468
+ Nothing
469
+ [" .cabal" ]
376
470
377
471
newtype CommandId = CommandId T. Text
378
472
deriving (Show , Read , Eq , Ord )
0 commit comments