haskell-language-server icon indicating copy to clipboard operation
haskell-language-server copied to clipboard

[new plugin] Add explicit export lists to each module using the minimal import lists

Open jrp2014 opened this issue 6 years ago • 13 comments

GHC has a -ddump-minimal-imports flag. Would it be possible to use the ghcide apparatus to write a new app to apply the minimal imports (optionally ignoring Prelude, perhaps) generated automatically?

For bonus points, it should also be possible to use the set of minimal imports across a project to add explicit export lists to each module using the minimal import lists.

Of course, weeder does some of this at the module level, but not the module contents level.

Presumably, this would help faster compilation and provide GHC with better optimization opportunities.

Undoubtedly the automatically-generated results would need hand tweaking, but I think that it might be a great help to some older code bases that have developed a certain amount of cruft that this sort of analysis could help improve. Doing it by hand, with a shell script or two would be one approach, but it would be good to have something a bit more robust (eg, preserving comments).

Perhaps someone has already done this.

jrp2014 avatar Mar 14 '20 16:03 jrp2014

The idea is that ghcide is a small core, and that plugins are used to extend it. Most of the plugins are going to live in the https://github.com/haskell/haskell-language-server repo, so I suspect that is the place to ask for a plugin to be created (or even better, to write one yourself).

ndmitchell avatar Mar 14 '20 17:03 ndmitchell

Oh, and for implementation, we don't need to rely on dump minimal imports flag - we have all the information in hand in the GHC AST, so it should be pretty easy to make the imports precisely minimal.

ndmitchell avatar Mar 14 '20 17:03 ndmitchell

Grand.

jrp2014 avatar Mar 14 '20 17:03 jrp2014

It should be a plugin in hls so transferred

jneira avatar Oct 02 '20 08:10 jneira

The "make exports explicit" was implemented by #436

EDIT: wrong comment, #436 is about make imports explicit and the issue is about make exports explicit

jneira avatar Oct 02 '20 08:10 jneira

Not sure i minimize imports could be part of the organize imports action in #719

jneira avatar Nov 26 '21 22:11 jneira

Minimize imports is exactly what the refine imports plugin does.

pepeiborra avatar Nov 27 '21 09:11 pepeiborra

nice, so this can be close as already implmented :-)

jneira avatar Nov 27 '21 10:11 jneira

I think this should still be open --- we don't yet have "make exports explicit," do we?

isovector avatar Jan 25 '22 17:01 isovector

@isovector https://github.com/haskell/haskell-language-server/issues/450#issuecomment-702603386 writes

The "make exports explicit" was implemented by #436

ocharles avatar Jan 25 '22 18:01 ocharles

Edit: whoops. I think that was a mis-comment, because #436 is about imports.

ocharles avatar Jan 25 '22 18:01 ocharles

ugh, yeah, noted in the original comment. Change the title as minimise imports is already implemented

@isovector @ocharles thanks for the correction!

jneira avatar Jan 25 '22 19:01 jneira

I think this should still be open --- we don't yet have "make exports explicit," do we?

Afaiu this should be a new plugin then?

hasufell avatar Jul 13 '22 17:07 hasufell