Skip to content

Remove suggested imports completely #1121

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

Merged
merged 1 commit into from
Feb 1, 2016
Merged

Remove suggested imports completely #1121

merged 1 commit into from
Feb 1, 2016

Conversation

geraldus
Copy link
Contributor

Do not leave blank line when removing import statement.

Now covers multiline imports properly when remove or comment out option
selected.

Will think about some test, don't merge yet.

Fixes #1109

Do not leave blank line when removing import statement.

Now covers multiline imports properly when remove or comment out option
selected.

Tidy up tests a bit.
@geraldus
Copy link
Contributor Author

geraldus commented Feb 1, 2016

@gracjan I have no good test case for this.

gracjan added a commit that referenced this pull request Feb 1, 2016
Remove suggested imports completely
@gracjan gracjan merged commit 4e126e1 into haskell:master Feb 1, 2016
@chrisdone
Copy link
Member

This is a regression! 😱

I'm reverting this PR.

@geraldus The reason this feature only blanks (rather than removes) the line and does not remove it is because then any future import line removals will have the wrong line number. Try this feature on this module:

module X where

import Data.Char
import Data.Foldable
import Prelude
import Control.Monad
x :: ()
x = ()

It prompts: (1) Remove Data.Char and removes Data.Char, then (2) Remove Data.Foldable? and removes Prelude. Then prompts Remove Prelude? hit y and it throws a type error.

So leaving the import lines there is the solution I went with.

  • The alternative is to keep track of which lines have been removed and compute line offsets to properly remove the right lines.
  • An easier alternative is to blank all the lines, then put the line numbers in a hashtable. Then at the end of the import removing process (e.g. after modules have loaded), go ahead and actually delete those lines from bottom to top.

If you want to do that work, feel free. 👍 I might do it myself, but let's coordinate in this PR if one of us starts working on it.

@geraldus
Copy link
Contributor Author

@chrisdone ahh, I've noticed some issues with this, but haven't time to investigate what's going on, thanks. I think I could take second approach.

@chrisdone
Copy link
Member

@geraldus Cool! 👍

@geraldus
Copy link
Contributor Author

@chrisdone, by the way, we have discussed this a bit earlier and decided, that rather prompting user during loading process it is much better to inform him that there are redundant imports and suggest to run some command manually to remove/comment out this stuff. The issue with current behavior (at least for me) that I usually miss this prompts and wait for some time before I finally realize that I have to answer what to do. Also another a bit annoying thing is that I have to save manually all modified files.

So, I want to know other people opinion about following two points:

  1. do not prompt user during compilation, warn him and suggest run special command to handle redundant imports instead
  2. save all files after modifications

Ping @gracjan and other active people

@gracjan
Copy link
Contributor

gracjan commented Feb 19, 2016

I'd imagine overlays (similar to those provided by Flycheck), with the ability to navigate between them and then do fixups. Then we could have overlays signaling errors and warnings and some of those could have one (or more) automatic actions associated.

@vlatkoB
Copy link
Contributor

vlatkoB commented Mar 4, 2016

Can removing imports be done from the end?
Than removing lines wouldn't affect other removals and line numbers are preserved.

@geraldus
Copy link
Contributor Author

geraldus commented Mar 4, 2016

@vlatkoB in this case we need some stack of all redundant imports. I'm going to implement this soon #1109 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants