Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin support for Rename providers #123

Merged
merged 3 commits into from
May 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 2 additions & 11 deletions src/Ide/Plugin/Brittany.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,8 @@ import System.FilePath
import Data.Maybe (maybeToList)

descriptor :: PluginId -> PluginDescriptor
descriptor plId = PluginDescriptor
{ pluginId = plId
, pluginRules = mempty
, pluginCommands = []
, pluginCodeActionProvider = Nothing
, pluginCodeLensProvider = Nothing
, pluginDiagnosticProvider = Nothing
, pluginHoverProvider = Nothing
, pluginSymbolsProvider = Nothing
, pluginFormattingProvider = Just provider
, pluginCompletionProvider = Nothing
descriptor plId = (defaultPluginDescriptor plId)
{ pluginFormattingProvider = Just provider
}

-- | Formatter provider of Brittany.
Expand Down
7 changes: 2 additions & 5 deletions src/Ide/Plugin/Example.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,13 @@ import Text.Regex.TDFA.Text()
-- ---------------------------------------------------------------------

descriptor :: PluginId -> PluginDescriptor
descriptor plId = PluginDescriptor
{ pluginId = plId
, pluginRules = exampleRules
descriptor plId = (defaultPluginDescriptor plId)
{ pluginRules = exampleRules
, pluginCommands = [PluginCommand "codelens.todo" "example adding" addTodoCmd]
, pluginCodeActionProvider = Just codeAction
, pluginCodeLensProvider = Just codeLens
, pluginDiagnosticProvider = Nothing
, pluginHoverProvider = Just hover
, pluginSymbolsProvider = Just symbols
, pluginFormattingProvider = Nothing
, pluginCompletionProvider = Just completion
}

Expand Down
7 changes: 2 additions & 5 deletions src/Ide/Plugin/Example2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,13 @@ import Text.Regex.TDFA.Text()
-- ---------------------------------------------------------------------

descriptor :: PluginId -> PluginDescriptor
descriptor plId = PluginDescriptor
{ pluginId = plId
, pluginRules = exampleRules
descriptor plId = (defaultPluginDescriptor plId)
{ pluginRules = exampleRules
, pluginCommands = [PluginCommand "codelens.todo" "example adding" addTodoCmd]
, pluginCodeActionProvider = Just codeAction
, pluginCodeLensProvider = Just codeLens
, pluginDiagnosticProvider = Nothing
, pluginHoverProvider = Just hover
, pluginSymbolsProvider = Just symbols
, pluginFormattingProvider = Nothing
, pluginCompletionProvider = Just completion
}

Expand Down
13 changes: 2 additions & 11 deletions src/Ide/Plugin/Floskell.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,8 @@ import Text.Regex.TDFA.Text()
-- ---------------------------------------------------------------------

descriptor :: PluginId -> PluginDescriptor
descriptor plId = PluginDescriptor
{ pluginId = plId
, pluginRules = mempty
, pluginCommands = []
, pluginCodeActionProvider = Nothing
, pluginCodeLensProvider = Nothing
, pluginDiagnosticProvider = Nothing
, pluginHoverProvider = Nothing
, pluginSymbolsProvider = Nothing
, pluginFormattingProvider = Just provider
, pluginCompletionProvider = Nothing
descriptor plId = (defaultPluginDescriptor plId)
{ pluginFormattingProvider = Just provider
}

-- ---------------------------------------------------------------------
Expand Down
8 changes: 2 additions & 6 deletions src/Ide/Plugin/GhcIde.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,12 @@ import Text.Regex.TDFA.Text()
-- ---------------------------------------------------------------------

descriptor :: PluginId -> PluginDescriptor
descriptor plId = PluginDescriptor
{ pluginId = plId
, pluginRules = mempty
, pluginCommands = [PluginCommand (CommandId "typesignature.add") "adds a signature" commandAddSignature]
descriptor plId = (defaultPluginDescriptor plId)
{ pluginCommands = [PluginCommand (CommandId "typesignature.add") "adds a signature" commandAddSignature]
, pluginCodeActionProvider = Just codeAction'
, pluginCodeLensProvider = Just codeLens'
, pluginDiagnosticProvider = Nothing
, pluginHoverProvider = Just hover'
, pluginSymbolsProvider = Just symbolsProvider
, pluginFormattingProvider = Nothing
, pluginCompletionProvider = Just getCompletionsLSP
}

Expand Down
13 changes: 2 additions & 11 deletions src/Ide/Plugin/Ormolu.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,8 @@ import Text.Regex.TDFA.Text()
-- ---------------------------------------------------------------------

descriptor :: PluginId -> PluginDescriptor
descriptor plId = PluginDescriptor
{ pluginId = plId
, pluginRules = mempty
, pluginCommands = []
, pluginCodeActionProvider = Nothing
, pluginCodeLensProvider = Nothing
, pluginDiagnosticProvider = Nothing
, pluginHoverProvider = Nothing
, pluginSymbolsProvider = Nothing
, pluginFormattingProvider = Just provider
, pluginCompletionProvider = Nothing
descriptor plId = (defaultPluginDescriptor plId)
{ pluginFormattingProvider = Just provider
}

-- ---------------------------------------------------------------------
Expand Down
12 changes: 2 additions & 10 deletions src/Ide/Plugin/Pragmas.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,9 @@ import Language.Haskell.LSP.Types
-- ---------------------------------------------------------------------

descriptor :: PluginId -> PluginDescriptor
descriptor plId = PluginDescriptor
{ pluginId = plId
, pluginRules = mempty
, pluginCommands = commands
descriptor plId = (defaultPluginDescriptor plId)
{ pluginCommands = commands
, pluginCodeActionProvider = Just codeActionProvider
, pluginCodeLensProvider = Nothing
, pluginDiagnosticProvider = Nothing
, pluginHoverProvider = Nothing
, pluginSymbolsProvider = Nothing
, pluginFormattingProvider = Nothing
, pluginCompletionProvider = Nothing
}

-- ---------------------------------------------------------------------
Expand Down
24 changes: 24 additions & 0 deletions src/Ide/Types.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Ide.Types
(
IdePlugins(..)
, PluginDescriptor(..)
, defaultPluginDescriptor
, PluginCommand(..)
, PluginId(..)
, CommandId(..)
Expand All @@ -19,6 +21,7 @@ module Ide.Types
, CommandFunction
, ExecuteCommandProvider
, CompletionProvider
, RenameProvider
, WithSnippets(..)
) where

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

defaultPluginDescriptor :: PluginId -> PluginDescriptor
defaultPluginDescriptor plId =
PluginDescriptor
plId
mempty
mempty
Nothing
Nothing
Nothing
Nothing
Nothing
Nothing
Nothing
Nothing

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

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