Skip to content
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

Implement pretty-printing of imports #26

Merged
merged 1 commit into from
Mar 21, 2019
Merged

Implement pretty-printing of imports #26

merged 1 commit into from
Mar 21, 2019

Conversation

mrkkrp
Copy link
Member

@mrkkrp mrkkrp commented Feb 28, 2019

Close #27.

This should be ready.

@mrkkrp mrkkrp force-pushed the mk/imports branch 3 times, most recently from f2b1ab5 to 0d82a53 Compare March 3, 2019 19:14
@mrkkrp
Copy link
Member Author

mrkkrp commented Mar 3, 2019

Actually I found a decent way to sort explicit import lists too. Some bits of AST are not clear, but we can adjust the code when we discover concrete cases where they are used.

Copy link
Member

@facundominguez facundominguez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we preserve line breaks in import lists?

import Package.Internal.A
import Package.Internal.B

import External.A
import External.B

I've added some tests which fail.

Also, we need to advice on how to deal with a redundant Prelude:

{-# OPTIONS_GHC -Wall -Werror #-}
import Text.Read
import Prelude

f :: Int
f = read "0"

The above program would fail to build in GHC if imports are reordered.

{-# OPTIONS_GHC -Wall -Werror #-}
import Prelude
import Text.Read

f :: Int
f = read "0"
error: [-Wunused-imports, -Werror=unused-imports]
    The import of 'Text.Read' is redundant
      except perhaps to import instances from 'Text.Read'
    To import instances alone, use: import Text.Read()
  |
3 | import Text.Read
  | ^^^^^^^^^^^^^^^^

@mrkkrp mrkkrp force-pushed the mk/imports branch 4 times, most recently from d4906e6 to 7c29f6f Compare March 17, 2019 19:01
@mrkkrp
Copy link
Member Author

mrkkrp commented Mar 21, 2019

I'm going to merge this one, Prelude is always placed last in the import list, this should be OK in all cases. For dropping of comments that we do I'm going to open another issue so we won't forget about the problem.

@mrkkrp mrkkrp merged commit b6d49bb into master Mar 21, 2019
@mrkkrp mrkkrp deleted the mk/imports branch March 21, 2019 13:45
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.

2 participants