From d73aaa69f09ca0b786ff3e29f5f0c7fb5c6fd447 Mon Sep 17 00:00:00 2001 From: andys8 Date: Tue, 5 Jul 2022 17:04:21 +0200 Subject: [PATCH 1/2] 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. --- plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs b/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs index 1b58e21919..9fed79791e 100644 --- a/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs +++ b/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs @@ -450,19 +450,19 @@ diagnosticToCodeActions dynFlags fileContents pluginId documentId diagnostic , let applyHintTitle = "Apply hint \"" <> hint <> "\"" applyHintArguments = [toJSON (AOP (documentId ^. LSP.uri) start hint)] applyHintCommand = mkLspCommand pluginId "applyOne" applyHintTitle (Just applyHintArguments) -> - Just (mkCodeAction applyHintTitle diagnostic Nothing (Just applyHintCommand)) + Just (mkCodeAction applyHintTitle diagnostic Nothing (Just applyHintCommand) True) | otherwise -> Nothing - , Just (mkCodeAction suppressHintTitle diagnostic (Just suppressHintWorkspaceEdit) Nothing) + , Just (mkCodeAction suppressHintTitle diagnostic (Just suppressHintWorkspaceEdit) Nothing False) ] | otherwise = [] -mkCodeAction :: T.Text -> LSP.Diagnostic -> Maybe LSP.WorkspaceEdit -> Maybe LSP.Command -> LSP.CodeAction -mkCodeAction title diagnostic workspaceEdit command = +mkCodeAction :: T.Text -> LSP.Diagnostic -> Maybe LSP.WorkspaceEdit -> Maybe LSP.Command -> Bool -> LSP.CodeAction +mkCodeAction title diagnostic workspaceEdit command isPreferred = LSP.CodeAction { _title = title , _kind = Just LSP.CodeActionQuickFix , _diagnostics = Just (LSP.List [diagnostic]) - , _isPreferred = Nothing + , _isPreferred = Just isPreferred , _disabled = Nothing , _edit = workspaceEdit , _command = command From ab7f57be980852b8a100bb43fe66d508e77467c3 Mon Sep 17 00:00:00 2001 From: andys8 Date: Tue, 5 Jul 2022 18:47:55 +0200 Subject: [PATCH 2/2] Hlint: Comment for isPreferred Including the rationale for why we're making this decision as a comment in the code. --- plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs b/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs index 9fed79791e..9f75dff9f3 100644 --- a/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs +++ b/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs @@ -446,6 +446,8 @@ diagnosticToCodeActions dynFlags fileContents pluginId documentId diagnostic Nothing Nothing = catMaybes + -- Applying the hint is marked preferred because it addresses the underlying error. + -- Disabling the rule isn't, because less often used and configuration can be adapted. [ if | isHintApplicable , let applyHintTitle = "Apply hint \"" <> hint <> "\"" applyHintArguments = [toJSON (AOP (documentId ^. LSP.uri) start hint)]