haskell / haskell-ide-engine

The engine for haskell ide-integration. Not an IDE
BSD 3-Clause "New" or "Revised" License
2.38k stars 211 forks source link

"remove redundant import" removes used imports #873

Open wedens opened 6 years ago

wedens commented 6 years ago

When I have an import string:

import           Path (Abs, Dir, File, Path, reldir, absfile, (</>))

and absfile is unused, there is a suggestion to remove redundant import. When I apply the suggestion, it removes whole import string instead of just absfile. Tooltip correctly shows that only absfile is unused.

Versions: haskell-ide-engine: 77ff1fa (HEAD at the moment) ghc: 8.4.3 vscode-hie-server: 0.0.24 stack: 1.7.1

fendor commented 4 years ago

Solution is to use hsimport which we have patched to actually support this!

majkrzak commented 4 years ago

@fendor can you give quick explanation how?

fendor commented 4 years ago

Currently, we remove the line that contains the import here: https://github.com/haskell/haskell-ide-engine/blob/master/src/Haskell/Ide/Engine/Plugin/Generic.hs#L200

Which is just wrong, we have to modify the import line correctly. My idea would be to reuse our hsimport plugin which is responsible for offering import Code-Actions for symbols that it can find in the local hoogle db. Instead of importing, we want to hide a symbol now. hsimport offers an API to hide a symbol from an import and we could use that for hie.

What needs to be done

I think that we mostly have to change the generation of the code-actions, e.g. https://github.com/haskell/haskell-ide-engine/blob/master/src/Haskell/Ide/Engine/Plugin/HsImport.hs#L275 Also, the arguments to hsimport which are generated here: https://github.com/haskell/haskell-ide-engine/blob/master/src/Haskell/Ide/Engine/Plugin/HsImport.hs#L225

If there are more questions, just ask.