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

Allow configuration of preferred imports for quick fix

Open ejconlon opened this issue 3 years ago • 3 comments

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

You can often import the same symbols from multiple modules. For example, try the import quick fix for when - I prefer to import it from Control.Monad (where I believe it is originally defined) and not through any of a dozen MTL modules as the quick fix suggests. Selecting just the right import from a large list happens hundreds of times in a small project, which in my experience feels like a big point of friction. I believe we need a way to pick sensible defaults so import quick fixes work well en masse.

Describe the solution you'd like

What if you could bring your own mapping of symbols to modules (maybe in hie.yaml). Something like:

preferredImports:
    when: "Control.Monad"
    get: "Control.Monad.State.Strict"
    Map: "Data.Map.Strict"
preferredQualifiedImports:
    Seq: "Data.Sequence"
    Map: "Data.Map.Strict"
    BS: "Data.Bytestring"

With this configuration, one could have the preferred modules selected by default when quick fixing missing imports (or applied for all missing imports in a file). One could even resolve qualified module names with additional configuration.

Describe alternatives you've considered

The alternative is just the status quo, I think.

Additional context

Thank you for reading!

ejconlon avatar Jul 24 '22 22:07 ejconlon

This sounds like a good idea to me, but I would simplify and just provide:

  • an ordered list of module names by preference
  • an unordered list of "banned" module regexps to filter out

Moreover, I would ship HLS with sensible default values for those so that 99% of users don't need any custom config.

pepeiborra avatar Jul 27 '22 07:07 pepeiborra

Probably any configuration should go in the plugin options, not in hie.yaml. But also there's quite a lot of ways to configure this...

michaelpj avatar Aug 10 '22 11:08 michaelpj

I think {-# OPTIONS_HADDOCK not-home #-} should be the preferred way to configure these rather than custom HLS configuration:


``not-home``
    Indicates that the current module should not be considered to be the
    home module for each entity it exports, unless that entity is not
    exported from any other module. See :ref:`hyperlinking-re-exported`
    for more details.

We can access this information using processModules in the haddock api.

wz1000 avatar Aug 10 '22 11:08 wz1000