@@ -19,6 +19,9 @@ module Ide.Plugin
1919 , responseError
2020 , getClientConfig
2121 , getClientConfigAction
22+ , getPluginConfig
23+ , configForPlugin
24+ , pluginEnabled
2225 ) where
2326
2427import Control.Exception (SomeException , catch )
@@ -121,7 +124,12 @@ makeCodeAction :: [(PluginId, CodeActionProvider)]
121124makeCodeAction cas lf ideState (CodeActionParams docId range context _) = do
122125 let caps = LSP. clientCapabilities lf
123126 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
125133 let actions = filter wasRequested . concat $ map unL $ rights r
126134 res <- send caps actions
127135 return $ Right res
@@ -181,7 +189,10 @@ makeCodeLens cas lf ideState params = do
181189 logInfo (ideLogger ideState) " Plugin.makeCodeLens (ideLogger)" -- AZ
182190 let
183191 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 [] )
185196 return (pid, r)
186197 breakdown :: [(PluginId , Either ResponseError a )] -> ([(PluginId , ResponseError )], [(PluginId , a )])
187198 breakdown ls = (concatMap doOneLeft ls, concatMap doOneRight ls)
@@ -409,9 +420,15 @@ makeHover :: [(PluginId, HoverProvider)]
409420 -> LSP. LspFuncs Config -> IdeState
410421 -> TextDocumentPositionParams
411422 -> IO (Either ResponseError (Maybe Hover ))
412- makeHover hps _lf ideState params
423+ makeHover hps lf ideState params
413424 = 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
415432 -- TODO: We should support ServerCapabilities and declare that
416433 -- we don't support hover requests during initialization if we
417434 -- don't have any hover providers
@@ -462,7 +479,12 @@ makeSymbols sps lf ideState params
462479 si = SymbolInformation name' (ds ^. kind) (ds ^. deprecated) loc parent
463480 in [si] <> children'
464481
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
466488 case rights mhs of
467489 [] -> return $ Left $ responseError $ T. pack $ show $ lefts mhs
468490 hs -> return $ Right $ convertSymbols $ concat hs
@@ -485,7 +507,14 @@ renameWith ::
485507 RenameParams ->
486508 IO (Either ResponseError WorkspaceEdit )
487509renameWith 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
489518 case partitionEithers results of
490519 (errors, [] ) -> return $ Left $ responseError $ T. pack $ show $ errors
491520 (_, edits) -> return $ Right $ mconcat edits
@@ -530,7 +559,7 @@ makeCompletions :: [(PluginId, CompletionProvider)]
530559makeCompletions sps lf ideState params@ (CompletionParams (TextDocumentIdentifier doc) pos _context _mt)
531560 = do
532561 mprefix <- getPrefixAtPos lf doc pos
533- _snippets <- WithSnippets <$> completionSnippetsOn <$> ( getClientConfig lf)
562+ _snippets <- WithSnippets <$> completionSnippetsOn <$> getClientConfig lf
534563
535564 let
536565 combine :: [CompletionResponseResult ] -> CompletionResponseResult
@@ -545,11 +574,16 @@ makeCompletions sps lf ideState params@(CompletionParams (TextDocumentIdentifier
545574 = go (CompletionList $ CompletionListType (complete || complete2) (List (ls <> ls2))) rest
546575 go (CompletionList (CompletionListType complete (List ls))) (Completions (List ls2): rest)
547576 = 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 []
548582
549583 case mprefix of
550584 Nothing -> return $ Right $ Completions $ List []
551585 Just _prefix -> do
552- mhs <- mapM ( \ (_,p) -> p lf ideState params) sps
586+ mhs <- mapM makeAction sps
553587 case rights mhs of
554588 [] -> return $ Left $ responseError $ T. pack $ show $ lefts mhs
555589 hs -> return $ Right $ combine hs
@@ -583,15 +617,15 @@ getPrefixAtPos lf uri pos = do
583617
584618-- ---------------------------------------------------------------------
585619-- | 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 .
588622--
589623-- If no custom configuration has been set by the client, this function returns
590624-- our own defaults.
591625getClientConfig :: LSP. LspFuncs Config -> IO Config
592626getClientConfig lf = fromMaybe Data.Default. def <$> LSP. config lf
593627
594- -- | Returns the client configurarion stored in the IdeState.
628+ -- | Returns the client configuration stored in the IdeState.
595629-- You can use this function to access it from shake Rules
596630getClientConfigAction :: Action Config
597631getClientConfigAction = do
@@ -600,4 +634,27 @@ getClientConfigAction = do
600634 case J. fromJSON <$> mbVal of
601635 Just (J. Success c) -> return c
602636 _ -> return Data.Default. def
637+
603638-- ---------------------------------------------------------------------
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