From eef5532d8f902d2fb529d450b9ad1ab2b02530c5 Mon Sep 17 00:00:00 2001 From: Alan Zimmerman Date: Mon, 11 Nov 2019 23:13:13 +0000 Subject: [PATCH] Generate an "Apply all hints" hlint code action This commit generates it all the time, without checking if we actually have any hints. --- src/Haskell/Ide/Engine/Plugin/ApplyRefact.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Haskell/Ide/Engine/Plugin/ApplyRefact.hs b/src/Haskell/Ide/Engine/Plugin/ApplyRefact.hs index ff1903728..096ce4e44 100644 --- a/src/Haskell/Ide/Engine/Plugin/ApplyRefact.hs +++ b/src/Haskell/Ide/Engine/Plugin/ApplyRefact.hs @@ -307,7 +307,10 @@ codeActionProvider plId docId _ context = IdeResultOk <$> hlintActions where hlintActions :: IdeM [LSP.CodeAction] - hlintActions = catMaybes <$> mapM mkHlintAction (filter validCommand diags) + hlintActions = do + actions <- mapM mkHlintAction (filter validCommand diags) + applyAll <- mkApplyAllAction + return (catMaybes $ applyAll:actions) -- |Some hints do not have an associated refactoring validCommand (LSP.Diagnostic _ _ (Just (LSP.StringValue code)) (Just "hlint") _ _) = @@ -327,3 +330,10 @@ codeActionProvider plId docId _ context = IdeResultOk <$> hlintActions -- need 'file', 'start_pos' and hint title (to distinguish between alternative suggestions at the same location) args = [toJSON (AOP (docId ^. LSP.uri) start code)] mkHlintAction (LSP.Diagnostic _r _s _c _source _m _) = return Nothing + + mkApplyAllAction :: IdeM (Maybe LSP.CodeAction) + mkApplyAllAction = + Just . codeAction <$> mkLspCommand plId "applyAll" title (Just [toJSON (docId ^. LSP.uri)]) + where + title = "Apply all hints" + codeAction cmd = LSP.CodeAction title (Just LSP.CodeActionRefactor) Nothing Nothing (Just cmd)