Skip to content

Plugin idea: exporting unexported identifier #2939

Description

@sergv

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 export list by hand, which may be suboptimal since it duplicates logic already present in GHC for checking what's exported.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions