Skip to content

Commit 04cc40d

Browse files
andys8hololeap
authored andcommitted
Hlint: CodeAction with isPreferred (haskell#3018)
* Hlint: CodeAction with isPreferred > A refactoring should be marked preferred if it is the most reasonable choice of actions to take. For hlint it is the likeliest choice to apply the fix. Ignore the rule for the complete module is preferred less. * Hlint: Comment for isPreferred Including the rationale for why we're making this decision as a comment in the code.
1 parent fd9865a commit 04cc40d

File tree

1 file changed

+7
-5
lines changed
  • plugins/hls-hlint-plugin/src/Ide/Plugin

1 file changed

+7
-5
lines changed

plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,23 +446,25 @@ diagnosticToCodeActions dynFlags fileContents pluginId documentId diagnostic
446446
Nothing
447447
Nothing
448448
= catMaybes
449+
-- Applying the hint is marked preferred because it addresses the underlying error.
450+
-- Disabling the rule isn't, because less often used and configuration can be adapted.
449451
[ if | isHintApplicable
450452
, let applyHintTitle = "Apply hint \"" <> hint <> "\""
451453
applyHintArguments = [toJSON (AOP (documentId ^. LSP.uri) start hint)]
452454
applyHintCommand = mkLspCommand pluginId "applyOne" applyHintTitle (Just applyHintArguments) ->
453-
Just (mkCodeAction applyHintTitle diagnostic Nothing (Just applyHintCommand))
455+
Just (mkCodeAction applyHintTitle diagnostic Nothing (Just applyHintCommand) True)
454456
| otherwise -> Nothing
455-
, Just (mkCodeAction suppressHintTitle diagnostic (Just suppressHintWorkspaceEdit) Nothing)
457+
, Just (mkCodeAction suppressHintTitle diagnostic (Just suppressHintWorkspaceEdit) Nothing False)
456458
]
457459
| otherwise = []
458460

459-
mkCodeAction :: T.Text -> LSP.Diagnostic -> Maybe LSP.WorkspaceEdit -> Maybe LSP.Command -> LSP.CodeAction
460-
mkCodeAction title diagnostic workspaceEdit command =
461+
mkCodeAction :: T.Text -> LSP.Diagnostic -> Maybe LSP.WorkspaceEdit -> Maybe LSP.Command -> Bool -> LSP.CodeAction
462+
mkCodeAction title diagnostic workspaceEdit command isPreferred =
461463
LSP.CodeAction
462464
{ _title = title
463465
, _kind = Just LSP.CodeActionQuickFix
464466
, _diagnostics = Just (LSP.List [diagnostic])
465-
, _isPreferred = Nothing
467+
, _isPreferred = Just isPreferred
466468
, _disabled = Nothing
467469
, _edit = workspaceEdit
468470
, _command = command

0 commit comments

Comments
 (0)