Skip to content

Refactor plugin: Prefer code action #3167

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

Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ suggestHideShadow ps fileContents mTcM mHar Diagnostic {_message, _range}
| otherwise = []
where
L _ HsModule {hsmodImports} = astA ps

suggests identifier modName s
| Just tcM <- mTcM,
Just har <- mHar,
Expand Down Expand Up @@ -458,6 +458,12 @@ suggestRemoveRedundantImport ParsedModule{pm_parsed_source = L _ HsModule{hsmod
= [("Remove import", [TextEdit (extendToWholeLineIfPossible contents _range) ""])]
| otherwise = []


-- Note [Removing imports is preferred]
-- It's good to prefer the remove imports code action because 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.
caRemoveRedundantImports :: Maybe ParsedModule -> Maybe T.Text -> [Diagnostic] -> [Diagnostic] -> Uri -> [Command |? CodeAction]
caRemoveRedundantImports m contents digs ctxDigs uri
| Just pm <- m,
Expand All @@ -481,7 +487,8 @@ caRemoveRedundantImports m contents digs ctxDigs uri
_diagnostics = Nothing
_documentChanges = Nothing
_edit = Just WorkspaceEdit{..}
_isPreferred = Nothing
-- See Note [Removing imports is preferred]
_isPreferred = Just True
_command = Nothing
_disabled = Nothing
_xdata = Nothing
Expand Down Expand Up @@ -520,7 +527,8 @@ caRemoveInvalidExports m contents digs ctxDigs uri
_documentChanges = Nothing
_edit = Just WorkspaceEdit{..}
_command = Nothing
_isPreferred = Nothing
-- See Note [Removing imports is preferred]
_isPreferred = Just True
_disabled = Nothing
_xdata = Nothing
_changeAnnotations = Nothing
Expand All @@ -534,7 +542,8 @@ caRemoveInvalidExports m contents digs ctxDigs uri
_documentChanges = Nothing
_edit = Just WorkspaceEdit{..}
_command = Nothing
_isPreferred = Nothing
-- See Note [Removing imports is preferred]
_isPreferred = Just True
_disabled = Nothing
_xdata = Nothing
_changeAnnotations = Nothing
Expand Down