@@ -19,6 +19,9 @@ module Ide.Plugin
19
19
, responseError
20
20
, getClientConfig
21
21
, getClientConfigAction
22
+ , getPluginConfig
23
+ , configForPlugin
24
+ , pluginEnabled
22
25
) where
23
26
24
27
import Control.Exception (SomeException , catch )
@@ -121,7 +124,12 @@ makeCodeAction :: [(PluginId, CodeActionProvider)]
121
124
makeCodeAction cas lf ideState (CodeActionParams docId range context _) = do
122
125
let caps = LSP. clientCapabilities lf
123
126
unL (List ls) = ls
124
- r <- mapM (\ (pid,provider) -> provider lf ideState pid docId range context) cas
127
+ makeAction (pid,provider) = do
128
+ pluginConfig <- getPluginConfig lf pid
129
+ if pluginEnabled pluginConfig plcCodeActionsOn
130
+ then provider lf ideState pid docId range context
131
+ else return $ Right (List [] )
132
+ r <- mapM makeAction cas
125
133
let actions = filter wasRequested . concat $ map unL $ rights r
126
134
res <- send caps actions
127
135
return $ Right res
@@ -181,7 +189,10 @@ makeCodeLens cas lf ideState params = do
181
189
logInfo (ideLogger ideState) " Plugin.makeCodeLens (ideLogger)" -- AZ
182
190
let
183
191
makeLens (pid, provider) = do
184
- r <- provider lf ideState pid params
192
+ pluginConfig <- getPluginConfig lf pid
193
+ r <- if pluginEnabled pluginConfig plcCodeLensOn
194
+ then provider lf ideState pid params
195
+ else return $ Right (List [] )
185
196
return (pid, r)
186
197
breakdown :: [(PluginId , Either ResponseError a )] -> ([(PluginId , ResponseError )], [(PluginId , a )])
187
198
breakdown ls = (concatMap doOneLeft ls, concatMap doOneRight ls)
@@ -409,9 +420,15 @@ makeHover :: [(PluginId, HoverProvider)]
409
420
-> LSP. LspFuncs Config -> IdeState
410
421
-> TextDocumentPositionParams
411
422
-> IO (Either ResponseError (Maybe Hover ))
412
- makeHover hps _lf ideState params
423
+ makeHover hps lf ideState params
413
424
= do
414
- mhs <- mapM (\ (_,p) -> p ideState params) hps
425
+ let
426
+ makeHover(pid,p) = do
427
+ pluginConfig <- getPluginConfig lf pid
428
+ if pluginEnabled pluginConfig plcHoverOn
429
+ then p ideState params
430
+ else return $ Right Nothing
431
+ mhs <- mapM makeHover hps
415
432
-- TODO: We should support ServerCapabilities and declare that
416
433
-- we don't support hover requests during initialization if we
417
434
-- don't have any hover providers
@@ -462,7 +479,12 @@ makeSymbols sps lf ideState params
462
479
si = SymbolInformation name' (ds ^. kind) (ds ^. deprecated) loc parent
463
480
in [si] <> children'
464
481
465
- mhs <- mapM (\ (_,p) -> p lf ideState params) sps
482
+ makeSymbols (pid,p) = do
483
+ pluginConfig <- getPluginConfig lf pid
484
+ if pluginEnabled pluginConfig plcSymbolsOn
485
+ then p lf ideState params
486
+ else return $ Right []
487
+ mhs <- mapM makeSymbols sps
466
488
case rights mhs of
467
489
[] -> return $ Left $ responseError $ T. pack $ show $ lefts mhs
468
490
hs -> return $ Right $ convertSymbols $ concat hs
@@ -485,7 +507,14 @@ renameWith ::
485
507
RenameParams ->
486
508
IO (Either ResponseError WorkspaceEdit )
487
509
renameWith providers lspFuncs state params = do
488
- results <- mapM (\ (_,p) -> p lspFuncs state params) providers
510
+ let
511
+ makeAction (pid,p) = do
512
+ pluginConfig <- getPluginConfig lspFuncs pid
513
+ if pluginEnabled pluginConfig plcRenameOn
514
+ then p lspFuncs state params
515
+ else return $ Right $ WorkspaceEdit Nothing Nothing
516
+ -- TODO:AZ: we need to consider the right way to combine possible renamers
517
+ results <- mapM makeAction providers
489
518
case partitionEithers results of
490
519
(errors, [] ) -> return $ Left $ responseError $ T. pack $ show $ errors
491
520
(_, edits) -> return $ Right $ mconcat edits
@@ -530,7 +559,7 @@ makeCompletions :: [(PluginId, CompletionProvider)]
530
559
makeCompletions sps lf ideState params@ (CompletionParams (TextDocumentIdentifier doc) pos _context _mt)
531
560
= do
532
561
mprefix <- getPrefixAtPos lf doc pos
533
- _snippets <- WithSnippets <$> completionSnippetsOn <$> ( getClientConfig lf)
562
+ _snippets <- WithSnippets <$> completionSnippetsOn <$> getClientConfig lf
534
563
535
564
let
536
565
combine :: [CompletionResponseResult ] -> CompletionResponseResult
@@ -545,11 +574,16 @@ makeCompletions sps lf ideState params@(CompletionParams (TextDocumentIdentifier
545
574
= go (CompletionList $ CompletionListType (complete || complete2) (List (ls <> ls2))) rest
546
575
go (CompletionList (CompletionListType complete (List ls))) (Completions (List ls2): rest)
547
576
= go (CompletionList $ CompletionListType complete (List (ls <> ls2))) rest
577
+ makeAction (pid,p) = do
578
+ pluginConfig <- getPluginConfig lf pid
579
+ if pluginEnabled pluginConfig plcCompletionOn
580
+ then p lf ideState params
581
+ else return $ Right $ Completions $ List []
548
582
549
583
case mprefix of
550
584
Nothing -> return $ Right $ Completions $ List []
551
585
Just _prefix -> do
552
- mhs <- mapM ( \ (_,p) -> p lf ideState params) sps
586
+ mhs <- mapM makeAction sps
553
587
case rights mhs of
554
588
[] -> return $ Left $ responseError $ T. pack $ show $ lefts mhs
555
589
hs -> return $ Right $ combine hs
@@ -583,15 +617,15 @@ getPrefixAtPos lf uri pos = do
583
617
584
618
-- ---------------------------------------------------------------------
585
619
-- | Returns the current client configuration. It is not wise to permanently
586
- -- cache the returned value of this function, as clients can at runitime change
587
- -- their configuration.
620
+ -- cache the returned value of this function, as clients can change their
621
+ -- configuration at runtime .
588
622
--
589
623
-- If no custom configuration has been set by the client, this function returns
590
624
-- our own defaults.
591
625
getClientConfig :: LSP. LspFuncs Config -> IO Config
592
626
getClientConfig lf = fromMaybe Data.Default. def <$> LSP. config lf
593
627
594
- -- | Returns the client configurarion stored in the IdeState.
628
+ -- | Returns the client configuration stored in the IdeState.
595
629
-- You can use this function to access it from shake Rules
596
630
getClientConfigAction :: Action Config
597
631
getClientConfigAction = do
@@ -600,4 +634,27 @@ getClientConfigAction = do
600
634
case J. fromJSON <$> mbVal of
601
635
Just (J. Success c) -> return c
602
636
_ -> return Data.Default. def
637
+
603
638
-- ---------------------------------------------------------------------
639
+
640
+ -- | Returns the current plugin configuration. It is not wise to permanently
641
+ -- cache the returned value of this function, as clients can change their
642
+ -- configuration at runtime.
643
+ --
644
+ -- If no custom configuration has been set by the client, this function returns
645
+ -- our own defaults.
646
+ getPluginConfig :: LSP. LspFuncs Config -> PluginId -> IO PluginConfig
647
+ getPluginConfig lf plugin = do
648
+ config <- getClientConfig lf
649
+ return $ configForPlugin config plugin
650
+
651
+ configForPlugin :: Config -> PluginId -> PluginConfig
652
+ configForPlugin config (PluginId plugin)
653
+ = Map. findWithDefault Data.Default. def plugin (plugins config)
654
+
655
+ -- ---------------------------------------------------------------------
656
+
657
+ -- | Checks that a given plugin is both enabled and the specific feature is
658
+ -- enabled
659
+ pluginEnabled :: PluginConfig -> (PluginConfig -> Bool ) -> Bool
660
+ pluginEnabled pluginConfig f = plcGlobalOn pluginConfig && f pluginConfig
0 commit comments