Skip to content

Fix "Apply all hints" code action showing everywhere #1448

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

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 10 additions & 3 deletions plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,14 @@ getHlintSettingsRule usage =
-- ---------------------------------------------------------------------

codeActionProvider :: PluginMethodHandler IdeState TextDocumentCodeAction
codeActionProvider ideState plId (CodeActionParams _ _ docId _ context) = Right . LSP.List . map InR <$> liftIO getCodeActions
codeActionProvider ideState plId (CodeActionParams _ _ docId caRange context) = Right . LSP.List . map InR <$> liftIO getCodeActions
where
areOverlapping :: LSP.Range -> LSP.Range -> Bool
areOverlapping (LSP.Range from1 to1) (LSP.Range from2 to2) =
not $ to1 `lt` from2 || to2 `lt` from1
where
lt :: LSP.Position -> LSP.Position -> Bool
lt (LSP.Position l1 c1) (LSP.Position l2 c2) = l1 < l2 || l1 == l2 && c1 < c2

getCodeActions = do
diags <- getDiagnostics ideState
Expand All @@ -279,9 +285,10 @@ codeActionProvider ideState plId (CodeActionParams _ _ docId _ context) = Right
, validCommand d
, Just nfp == docNfp
]
let isOnHint = any (\(_, _, (LSP.Diagnostic {LSP._range = range})) -> areOverlapping range caRange) diags
-- We only want to show the applyAll code action if there is more than 1
-- hint in the current document
if numHintsInDoc > 1 then do
-- hint in the current document and the cursor is on one of these hints
if numHintsInDoc > 1 && isOnHint then do
pure $ applyAllAction:applyOneActions
else
pure applyOneActions
Expand Down