From 6bdb80928a6cdbc019317b143589d194d76e6bdb Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Wed, 20 May 2020 23:41:30 +0100 Subject: [PATCH 1/3] defaultPluginDescriptor --- src/Ide/Plugin/Brittany.hs | 10 +--------- src/Ide/Plugin/Example.hs | 4 +--- src/Ide/Plugin/Example2.hs | 4 +--- src/Ide/Plugin/Floskell.hs | 10 +--------- src/Ide/Plugin/GhcIde.hs | 5 +---- src/Ide/Plugin/Ormolu.hs | 10 +--------- src/Ide/Plugin/Pragmas.hs | 9 +-------- src/Ide/Types.hs | 15 +++++++++++++++ 8 files changed, 22 insertions(+), 45 deletions(-) diff --git a/src/Ide/Plugin/Brittany.hs b/src/Ide/Plugin/Brittany.hs index 3fef8f39d9..831a590f49 100644 --- a/src/Ide/Plugin/Brittany.hs +++ b/src/Ide/Plugin/Brittany.hs @@ -19,17 +19,9 @@ import System.FilePath import Data.Maybe (maybeToList) descriptor :: PluginId -> PluginDescriptor -descriptor plId = PluginDescriptor +descriptor plId = defaultPluginDescriptor { pluginId = plId - , pluginRules = mempty - , pluginCommands = [] - , pluginCodeActionProvider = Nothing - , pluginCodeLensProvider = Nothing - , pluginDiagnosticProvider = Nothing - , pluginHoverProvider = Nothing - , pluginSymbolsProvider = Nothing , pluginFormattingProvider = Just provider - , pluginCompletionProvider = Nothing } -- | Formatter provider of Brittany. diff --git a/src/Ide/Plugin/Example.hs b/src/Ide/Plugin/Example.hs index f73af86a13..4ba0d5843c 100644 --- a/src/Ide/Plugin/Example.hs +++ b/src/Ide/Plugin/Example.hs @@ -41,16 +41,14 @@ import Text.Regex.TDFA.Text() -- --------------------------------------------------------------------- descriptor :: PluginId -> PluginDescriptor -descriptor plId = PluginDescriptor +descriptor plId = defaultPluginDescriptor { pluginId = 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 } diff --git a/src/Ide/Plugin/Example2.hs b/src/Ide/Plugin/Example2.hs index a5db95f78f..09faab3e99 100644 --- a/src/Ide/Plugin/Example2.hs +++ b/src/Ide/Plugin/Example2.hs @@ -41,16 +41,14 @@ import Text.Regex.TDFA.Text() -- --------------------------------------------------------------------- descriptor :: PluginId -> PluginDescriptor -descriptor plId = PluginDescriptor +descriptor plId = defaultPluginDescriptor { pluginId = 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 } diff --git a/src/Ide/Plugin/Floskell.hs b/src/Ide/Plugin/Floskell.hs index e4446a6343..ea7488c4cb 100644 --- a/src/Ide/Plugin/Floskell.hs +++ b/src/Ide/Plugin/Floskell.hs @@ -25,17 +25,9 @@ import Text.Regex.TDFA.Text() -- --------------------------------------------------------------------- descriptor :: PluginId -> PluginDescriptor -descriptor plId = PluginDescriptor +descriptor plId = defaultPluginDescriptor { pluginId = plId - , pluginRules = mempty - , pluginCommands = [] - , pluginCodeActionProvider = Nothing - , pluginCodeLensProvider = Nothing - , pluginDiagnosticProvider = Nothing - , pluginHoverProvider = Nothing - , pluginSymbolsProvider = Nothing , pluginFormattingProvider = Just provider - , pluginCompletionProvider = Nothing } -- --------------------------------------------------------------------- diff --git a/src/Ide/Plugin/GhcIde.hs b/src/Ide/Plugin/GhcIde.hs index 788e58ac26..0aa7c12b77 100644 --- a/src/Ide/Plugin/GhcIde.hs +++ b/src/Ide/Plugin/GhcIde.hs @@ -20,16 +20,13 @@ import Text.Regex.TDFA.Text() -- --------------------------------------------------------------------- descriptor :: PluginId -> PluginDescriptor -descriptor plId = PluginDescriptor +descriptor plId = defaultPluginDescriptor { pluginId = plId - , pluginRules = mempty , 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 } diff --git a/src/Ide/Plugin/Ormolu.hs b/src/Ide/Plugin/Ormolu.hs index 0197c8e2b3..a63f84df56 100644 --- a/src/Ide/Plugin/Ormolu.hs +++ b/src/Ide/Plugin/Ormolu.hs @@ -29,17 +29,9 @@ import Text.Regex.TDFA.Text() -- --------------------------------------------------------------------- descriptor :: PluginId -> PluginDescriptor -descriptor plId = PluginDescriptor +descriptor plId = defaultPluginDescriptor { pluginId = plId - , pluginRules = mempty - , pluginCommands = [] - , pluginCodeActionProvider = Nothing - , pluginCodeLensProvider = Nothing - , pluginDiagnosticProvider = Nothing - , pluginHoverProvider = Nothing - , pluginSymbolsProvider = Nothing , pluginFormattingProvider = Just provider - , pluginCompletionProvider = Nothing } -- --------------------------------------------------------------------- diff --git a/src/Ide/Plugin/Pragmas.hs b/src/Ide/Plugin/Pragmas.hs index c70e818d5a..87a40670dd 100644 --- a/src/Ide/Plugin/Pragmas.hs +++ b/src/Ide/Plugin/Pragmas.hs @@ -24,17 +24,10 @@ import Language.Haskell.LSP.Types -- --------------------------------------------------------------------- descriptor :: PluginId -> PluginDescriptor -descriptor plId = PluginDescriptor +descriptor plId = defaultPluginDescriptor { pluginId = plId - , pluginRules = mempty , pluginCommands = commands , pluginCodeActionProvider = Just codeActionProvider - , pluginCodeLensProvider = Nothing - , pluginDiagnosticProvider = Nothing - , pluginHoverProvider = Nothing - , pluginSymbolsProvider = Nothing - , pluginFormattingProvider = Nothing - , pluginCompletionProvider = Nothing } -- --------------------------------------------------------------------- diff --git a/src/Ide/Types.hs b/src/Ide/Types.hs index 018e8acb4f..5ec155f3d7 100644 --- a/src/Ide/Types.hs +++ b/src/Ide/Types.hs @@ -1,10 +1,12 @@ {-# LANGUAGE GADTs #-} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} module Ide.Types ( IdePlugins(..) , PluginDescriptor(..) + , defaultPluginDescriptor , PluginCommand(..) , PluginId(..) , CommandId(..) @@ -59,6 +61,19 @@ data PluginDescriptor = , pluginCompletionProvider :: !(Maybe CompletionProvider) } +defaultPluginDescriptor :: PluginDescriptor +defaultPluginDescriptor = + PluginDescriptor + "" + mempty + mempty + Nothing + Nothing + Nothing + Nothing + Nothing + Nothing + Nothing -- instance Show PluginCommand where -- show (PluginCommand i _ _) = "PluginCommand { name = " ++ show i ++ " }" From d51c2796bd9f49e3dec5e831dcb589046a8d4ce2 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Wed, 20 May 2020 23:57:48 +0100 Subject: [PATCH 2/3] renameProviders --- src/Ide/Plugin.hs | 26 +++++++++++++++++++++++++- src/Ide/Types.hs | 9 +++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) 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))) From 1a46b0ba2e42becbbae5eb71fa0b827bbf9cb5d0 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Sat, 23 May 2020 14:53:01 +0100 Subject: [PATCH 3/3] defaultPluginDescripor - take PluginId as argument --- src/Ide/Plugin/Brittany.hs | 5 ++--- src/Ide/Plugin/Example.hs | 5 ++--- src/Ide/Plugin/Example2.hs | 5 ++--- src/Ide/Plugin/Floskell.hs | 5 ++--- src/Ide/Plugin/GhcIde.hs | 5 ++--- src/Ide/Plugin/Ormolu.hs | 5 ++--- src/Ide/Plugin/Pragmas.hs | 5 ++--- src/Ide/Types.hs | 6 +++--- 8 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/Ide/Plugin/Brittany.hs b/src/Ide/Plugin/Brittany.hs index 831a590f49..9d4fca2368 100644 --- a/src/Ide/Plugin/Brittany.hs +++ b/src/Ide/Plugin/Brittany.hs @@ -19,9 +19,8 @@ import System.FilePath import Data.Maybe (maybeToList) descriptor :: PluginId -> PluginDescriptor -descriptor plId = defaultPluginDescriptor - { pluginId = plId - , pluginFormattingProvider = Just provider +descriptor plId = (defaultPluginDescriptor plId) + { pluginFormattingProvider = Just provider } -- | Formatter provider of Brittany. diff --git a/src/Ide/Plugin/Example.hs b/src/Ide/Plugin/Example.hs index 4ba0d5843c..17ecb08efc 100644 --- a/src/Ide/Plugin/Example.hs +++ b/src/Ide/Plugin/Example.hs @@ -41,9 +41,8 @@ import Text.Regex.TDFA.Text() -- --------------------------------------------------------------------- descriptor :: PluginId -> PluginDescriptor -descriptor plId = defaultPluginDescriptor - { pluginId = plId - , pluginRules = exampleRules +descriptor plId = (defaultPluginDescriptor plId) + { pluginRules = exampleRules , pluginCommands = [PluginCommand "codelens.todo" "example adding" addTodoCmd] , pluginCodeActionProvider = Just codeAction , pluginCodeLensProvider = Just codeLens diff --git a/src/Ide/Plugin/Example2.hs b/src/Ide/Plugin/Example2.hs index 09faab3e99..d91d14e296 100644 --- a/src/Ide/Plugin/Example2.hs +++ b/src/Ide/Plugin/Example2.hs @@ -41,9 +41,8 @@ import Text.Regex.TDFA.Text() -- --------------------------------------------------------------------- descriptor :: PluginId -> PluginDescriptor -descriptor plId = defaultPluginDescriptor - { pluginId = plId - , pluginRules = exampleRules +descriptor plId = (defaultPluginDescriptor plId) + { pluginRules = exampleRules , pluginCommands = [PluginCommand "codelens.todo" "example adding" addTodoCmd] , pluginCodeActionProvider = Just codeAction , pluginCodeLensProvider = Just codeLens diff --git a/src/Ide/Plugin/Floskell.hs b/src/Ide/Plugin/Floskell.hs index ea7488c4cb..b77f974e3e 100644 --- a/src/Ide/Plugin/Floskell.hs +++ b/src/Ide/Plugin/Floskell.hs @@ -25,9 +25,8 @@ import Text.Regex.TDFA.Text() -- --------------------------------------------------------------------- descriptor :: PluginId -> PluginDescriptor -descriptor plId = defaultPluginDescriptor - { pluginId = plId - , pluginFormattingProvider = Just provider +descriptor plId = (defaultPluginDescriptor plId) + { pluginFormattingProvider = Just provider } -- --------------------------------------------------------------------- diff --git a/src/Ide/Plugin/GhcIde.hs b/src/Ide/Plugin/GhcIde.hs index 0aa7c12b77..06ebbd5f75 100644 --- a/src/Ide/Plugin/GhcIde.hs +++ b/src/Ide/Plugin/GhcIde.hs @@ -20,9 +20,8 @@ import Text.Regex.TDFA.Text() -- --------------------------------------------------------------------- descriptor :: PluginId -> PluginDescriptor -descriptor plId = defaultPluginDescriptor - { pluginId = plId - , 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' , pluginHoverProvider = Just hover' diff --git a/src/Ide/Plugin/Ormolu.hs b/src/Ide/Plugin/Ormolu.hs index a63f84df56..aa337fbc8e 100644 --- a/src/Ide/Plugin/Ormolu.hs +++ b/src/Ide/Plugin/Ormolu.hs @@ -29,9 +29,8 @@ import Text.Regex.TDFA.Text() -- --------------------------------------------------------------------- descriptor :: PluginId -> PluginDescriptor -descriptor plId = defaultPluginDescriptor - { pluginId = plId - , pluginFormattingProvider = Just provider +descriptor plId = (defaultPluginDescriptor plId) + { pluginFormattingProvider = Just provider } -- --------------------------------------------------------------------- diff --git a/src/Ide/Plugin/Pragmas.hs b/src/Ide/Plugin/Pragmas.hs index 87a40670dd..534610f963 100644 --- a/src/Ide/Plugin/Pragmas.hs +++ b/src/Ide/Plugin/Pragmas.hs @@ -24,9 +24,8 @@ import Language.Haskell.LSP.Types -- --------------------------------------------------------------------- descriptor :: PluginId -> PluginDescriptor -descriptor plId = defaultPluginDescriptor - { pluginId = plId - , pluginCommands = commands +descriptor plId = (defaultPluginDescriptor plId) + { pluginCommands = commands , pluginCodeActionProvider = Just codeActionProvider } diff --git a/src/Ide/Types.hs b/src/Ide/Types.hs index d5f759336a..2d564a4e97 100644 --- a/src/Ide/Types.hs +++ b/src/Ide/Types.hs @@ -63,10 +63,10 @@ data PluginDescriptor = , pluginRenameProvider :: !(Maybe RenameProvider) } -defaultPluginDescriptor :: PluginDescriptor -defaultPluginDescriptor = +defaultPluginDescriptor :: PluginId -> PluginDescriptor +defaultPluginDescriptor plId = PluginDescriptor - "" + plId mempty mempty Nothing