Closed
Description
Using hls 2.7.0.0 in vscode with ghc 9.4.8, I sometimes don't get "remove redundant imports" code action.
Here's a one-module reproducer (assuming you have a cabal project with postgresql-simple dependency):
module Main where
import Database.PostgreSQL.Simple.Types (In (..), PGArray (..), Values (..), fromIdentifier, fromQuery)
main :: IO ()
main = do
let array = PGArray []
in_ = In []
values = Values [] []
putStrLn "Hello, Haskell!"
Although warning is generated and displayed on hover:
The import of ‘Identifier(fromIdentifier), Query(fromQuery)’
from module ‘Database.PostgreSQL.Simple.Types’ is redundanttypecheck(-Wunused-imports)
The usual code action to remove unused import is not created.
Not a big deal, but it's breaking my flow, as now I have to focus on what the warning is exactly saying and fix it manually 😄
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]Code action to remove redundant imports is sometimes missing[/-][+]Code action to remove redundant imports is sometimes not created[/+]jhrcek commentedon May 12, 2024
Hint for anyone looking into fixing this
The place where this breaks down is in this function:
haskell-language-server/plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs
Lines 1942 to 1955 in 23005f8
which gets passed b::String like
RecordConstructor(recordFieldName)
, tries to compare it withprintOutputable b'
which at this point is justrecordFieldName
, which are not equal and so no code action is generated for these.battermann commentedon Jun 9, 2024
Looking into this
Code action to remove redundant record field import (fixes #4220) (#4308