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

Plugin idea: exporting unexported identifier #2939

Open
sergv opened this issue Jun 3, 2022 · 0 comments
Open

Plugin idea: exporting unexported identifier #2939

sergv opened this issue Jun 3, 2022 · 0 comments
Labels

Comments

@sergv
Copy link
Contributor

sergv commented Jun 3, 2022

Is your feature request related to a problem? Please describe.

Currently HLS suggests a code action to export identifier only if GHC determined it as unused and produced a warning like

-- Foo.hs:4:1: warning: [-Wunused-top-binds] Defined but not used: ‘f’
-- Foo.hs:5:1: warning: [-Wunused-top-binds] Defined but not used: type constructor or class ‘F’
-- Foo.hs:6:1: warning: [-Wunused-top-binds] Defined but not used: data constructor ‘Bar’

However I, as a user, could want to export already used type to make it available in other modules. I'd like HLS to automate adding of the name to the export list for me.

For instance, the user may want to export an internal type already used by an exported function. This is the simplest case where GHC won't produce a warning that the type is unused and thus no code action to export it would be offered.

Describe the solution you'd like

For each unexported toplevel function, datatype, type family, type class, etc identifier provide a code action to export it. In a perfect world also provide this suggestion for each not yet exported constructor name but this seems like harder to implement for no good reason. Most of the datatype exports export all constructors via (..).

Additional context

Currently the code action to export unused identifier from GHC's warning is implemented by suggestExportUnusedTopBinding at https://github.com/haskell/haskell-language-server/blob/master/ghcide/src/Development/IDE/Plugin/CodeAction.hs#L557. This may be a good chance to extract into a standalone plugin that does what's described above since suggestExportUnusedTopBinding suggests to export a name only in a subset of all cases that the new plugin would.

However it's not entirely clear to me how to check that a given name is already exported other than analyzing existing exprot list by hand, which may be suboptimal since it duplicates logic already present in GHC for checking what's exported.

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

No branches or pull requests

2 participants