Skip to content

Commit 362ca34

Browse files
authored
Refactor plugin: Prefer code action (#3167)
`isPreferred` can influence the client side order of code actions. The idea is that an unused import is likely to be removed and less likely the warning will be disabled. Therefore actions to remove a single or all redundant imports should be preferred, so that the client can prioritize them higher. Followup of <#3018>
1 parent b378de2 commit 362ca34

File tree

1 file changed

+13
-4
lines changed
  • plugins/hls-refactor-plugin/src/Development/IDE/Plugin

1 file changed

+13
-4
lines changed

plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs

+13-4
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ suggestHideShadow ps fileContents mTcM mHar Diagnostic {_message, _range}
389389
| otherwise = []
390390
where
391391
L _ HsModule {hsmodImports} = astA ps
392-
392+
393393
suggests identifier modName s
394394
| Just tcM <- mTcM,
395395
Just har <- mHar,
@@ -458,6 +458,12 @@ suggestRemoveRedundantImport ParsedModule{pm_parsed_source = L _ HsModule{hsmod
458458
= [("Remove import", [TextEdit (extendToWholeLineIfPossible contents _range) ""])]
459459
| otherwise = []
460460

461+
462+
-- Note [Removing imports is preferred]
463+
-- It's good to prefer the remove imports code action because an unused import
464+
-- is likely to be removed and less likely the warning will be disabled.
465+
-- Therefore actions to remove a single or all redundant imports should be
466+
-- preferred, so that the client can prioritize them higher.
461467
caRemoveRedundantImports :: Maybe ParsedModule -> Maybe T.Text -> [Diagnostic] -> [Diagnostic] -> Uri -> [Command |? CodeAction]
462468
caRemoveRedundantImports m contents digs ctxDigs uri
463469
| Just pm <- m,
@@ -481,7 +487,8 @@ caRemoveRedundantImports m contents digs ctxDigs uri
481487
_diagnostics = Nothing
482488
_documentChanges = Nothing
483489
_edit = Just WorkspaceEdit{..}
484-
_isPreferred = Nothing
490+
-- See Note [Removing imports is preferred]
491+
_isPreferred = Just True
485492
_command = Nothing
486493
_disabled = Nothing
487494
_xdata = Nothing
@@ -520,7 +527,8 @@ caRemoveInvalidExports m contents digs ctxDigs uri
520527
_documentChanges = Nothing
521528
_edit = Just WorkspaceEdit{..}
522529
_command = Nothing
523-
_isPreferred = Nothing
530+
-- See Note [Removing imports is preferred]
531+
_isPreferred = Just True
524532
_disabled = Nothing
525533
_xdata = Nothing
526534
_changeAnnotations = Nothing
@@ -534,7 +542,8 @@ caRemoveInvalidExports m contents digs ctxDigs uri
534542
_documentChanges = Nothing
535543
_edit = Just WorkspaceEdit{..}
536544
_command = Nothing
537-
_isPreferred = Nothing
545+
-- See Note [Removing imports is preferred]
546+
_isPreferred = Just True
538547
_disabled = Nothing
539548
_xdata = Nothing
540549
_changeAnnotations = Nothing

0 commit comments

Comments
 (0)