diff --git a/src/Ide/Plugin.hs b/src/Ide/Plugin.hs index e0dfe6eda9..0fd249745c 100644 --- a/src/Ide/Plugin.hs +++ b/src/Ide/Plugin.hs @@ -62,7 +62,8 @@ asGhcIdePlugin mp = mkPlugin hoverPlugins pluginHoverProvider <> mkPlugin symbolsPlugins pluginSymbolsProvider <> mkPlugin formatterPlugins pluginFormattingProvider <> - mkPlugin completionsPlugins pluginCompletionProvider + mkPlugin completionsPlugins pluginCompletionProvider <> + mkPlugin renamePlugins pluginRenameProvider where justs (p, Just x) = [(p, x)] justs (_, Nothing) = [] @@ -453,6 +454,29 @@ makeSymbols sps lf ideState params [] -> return $ Left $ responseError $ T.pack $ show $ lefts mhs hs -> return $ Right $ convertSymbols $ concat hs + +-- --------------------------------------------------------------------- +-- --------------------------------------------------------------------- + +renamePlugins :: [(PluginId, RenameProvider)] -> Plugin Config +renamePlugins providers = Plugin rules handlers + where + rules = mempty + handlers = PartialHandlers $ \WithMessage{..} x -> return x + { LSP.renameHandler = withResponse RspRename (renameWith providers)} + +renameWith :: + [(PluginId, RenameProvider)] -> + LSP.LspFuncs Config -> + IdeState -> + RenameParams -> + IO (Either ResponseError WorkspaceEdit) +renameWith providers lspFuncs state params = do + results <- mapM (\(_,p) -> p lspFuncs state params) providers + case partitionEithers results of + (errors, []) -> return $ Left $ responseError $ T.pack $ show $ errors + (_, edits) -> return $ Right $ mconcat edits + -- --------------------------------------------------------------------- -- --------------------------------------------------------------------- diff --git a/src/Ide/Types.hs b/src/Ide/Types.hs index 5ec155f3d7..d5f759336a 100644 --- a/src/Ide/Types.hs +++ b/src/Ide/Types.hs @@ -21,6 +21,7 @@ module Ide.Types , CommandFunction , ExecuteCommandProvider , CompletionProvider + , RenameProvider , WithSnippets(..) ) where @@ -59,6 +60,7 @@ data PluginDescriptor = , pluginSymbolsProvider :: !(Maybe SymbolsProvider) , pluginFormattingProvider :: !(Maybe (FormattingProvider IO)) , pluginCompletionProvider :: !(Maybe CompletionProvider) + , pluginRenameProvider :: !(Maybe RenameProvider) } defaultPluginDescriptor :: PluginDescriptor @@ -74,6 +76,8 @@ defaultPluginDescriptor = Nothing Nothing Nothing + Nothing + -- instance Show PluginCommand where -- show (PluginCommand i _ _) = "PluginCommand { name = " ++ show i ++ " }" @@ -127,6 +131,11 @@ type CodeLensProvider = LSP.LspFuncs Config -> CodeLensParams -> IO (Either ResponseError (List CodeLens)) +type RenameProvider = LSP.LspFuncs Config + -> IdeState + -> RenameParams + -> IO (Either ResponseError WorkspaceEdit) + type DiagnosticProviderFuncSync = DiagnosticTrigger -> Uri -> IO (Either ResponseError (Map.Map Uri (S.Set Diagnostic)))