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

Smarter import suggestion with defaults #605

Open
expipiplus1 opened this issue Nov 18, 2020 · 1 comment
Open

Smarter import suggestion with defaults #605

expipiplus1 opened this issue Nov 18, 2020 · 1 comment
Labels

Comments

@expipiplus1
Copy link
Contributor

The code action to add imports is great and I use it all the time, but my interactions with it can sometimes be a little repetitive.

For example, if I use the type Int32 HLS suggests a litany of potential imports, but every time I use this name I want to import Data.Int from base. There are a host of these "defaults" and it would be great to inform HLS of these to avoid cluttering the code actions with options I'm never going to choose.

image

The defaults could be specified either as:

  • A name and the corresponding import statement, in the above example: ('Int32, "import Data.Int")
  • Just a module name Data.Int with the meaning of, if this exists at all in the suggestions, don't suggest anything else

On a similar topic, it would be nice to specify "canonical" imports for types, for example I'm sure that despite Int32 being reexported from Foreign, Foreign.Safe, GHC.Int and UnliftIO.Foreign, nobody ever imports it from those modules (specifically, i.e. not with an open import). Does HLS have information at code-action generation time on the provenance of the symbols in the imports it's suggesting? In the above example this would present the import options from Data.Int and the Vulkan imports (assuming the user hasn't specified a canonical import for Vulkan.Core10.CommandBufferBuilding.ClearColorValue.Int32, in which case that canonical module would be returned).

I'm not sure that having a built in list of these default would be sensible, especially when alternative preludes get involved, but it would be nice to have some configuration that users could opt into easily to avoid people duplicating large amounts of the specifications in their configs.

Other motivating examples:

  • Anything from Data.Traversable, Data.Foldable, Data.Maybe. Basically any import from base which doesn't gobble up common names.
  • I quite often like: import Data.Text (Text); import Data.Text qualified as T (would have to present the options for Data.Text.Lazy too for when the user wants that)
    • Similarly for import Data.Vector(Vector); import Data.Vector qualified as V
@wz1000
Copy link
Collaborator

wz1000 commented Nov 18, 2020

The mechanism from haskell/ghcide#861 should allow this

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

3 participants