Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

[WIP] Generate an "Apply all hints" hlint code action #1450

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 11 additions & 1 deletion src/Haskell/Ide/Engine/Plugin/ApplyRefact.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some clients like coc.vim have keybindings to apply the first code action, so would it make sense to return this last?

Suggested change
return (catMaybes $ applyAll:actions)
return (catMaybes $ actions ++ [applyAll])


-- |Some hints do not have an associated refactoring
validCommand (LSP.Diagnostic _ _ (Just (LSP.StringValue code)) (Just "hlint") _ _) =
Expand All @@ -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)