Skip to content

Commit

Permalink
renameProviders
Browse files Browse the repository at this point in the history
  • Loading branch information
pepeiborra committed May 23, 2020
1 parent 6bdb809 commit d51c279
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/Ide/Plugin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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) = []
Expand Down Expand Up @@ -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

-- ---------------------------------------------------------------------
-- ---------------------------------------------------------------------

Expand Down
9 changes: 9 additions & 0 deletions src/Ide/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Ide.Types
, CommandFunction
, ExecuteCommandProvider
, CompletionProvider
, RenameProvider
, WithSnippets(..)
) where

Expand Down Expand Up @@ -59,6 +60,7 @@ data PluginDescriptor =
, pluginSymbolsProvider :: !(Maybe SymbolsProvider)
, pluginFormattingProvider :: !(Maybe (FormattingProvider IO))
, pluginCompletionProvider :: !(Maybe CompletionProvider)
, pluginRenameProvider :: !(Maybe RenameProvider)
}

defaultPluginDescriptor :: PluginDescriptor
Expand All @@ -74,6 +76,8 @@ defaultPluginDescriptor =
Nothing
Nothing
Nothing
Nothing

-- instance Show PluginCommand where
-- show (PluginCommand i _ _) = "PluginCommand { name = " ++ show i ++ " }"

Expand Down Expand Up @@ -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)))
Expand Down

0 comments on commit d51c279

Please sign in to comment.