rikvdkleij / intellij-haskell

IntelliJ plugin for Haskell
https://rikvdkleij.github.io/intellij-haskell/
Apache License 2.0
1.31k stars 94 forks source link

Add import such that already included modules are prefered #564

Closed keksnicoh closed 4 years ago

keksnicoh commented 4 years ago

Hi, thank you very much for this tool, it is very useful. Using the import action frequently I have some suggestions for improvements:

Consider the following import

import Control.Monad.Reader (MonadReader)

when using the import action (alt+enter) for a function which is not in scope, yet, e.g. liftIO, a list of suggestions is presented

which is ordered alphanumerically, I guess. It would be super cool if the item

would be the first item in the list as there exists an import of Control.Monad.Reader in the module already, thus liftIO would be added like

import Control.Monad.Reader (MonadReader, liftIO)

As there are many items in the list, this would speed up the dev experience because Alt+Enter -> Enter would add the liftIO to the import list instead of Alt+Enter->42 times Page Down ->Enter

just an idea :) Best, Nico

rikvdkleij commented 4 years ago

Thanks for your suggestion but I don't have control over the order.

The only option is to show only one intention which is in your case Import liftIO of module Control.Monad.Reader when the module is already there.

keksnicoh commented 4 years ago

Hi,

I'm not sure about the best solution here, but it seems plausible to suggest already imported modules over new ones. From the perspective of IntelliJ it seems a bit weird that the same function can be imported from many different modules. But when using libs like mtl, without an IDE, it is useful...

Your approach seems reasonable. I start thinking about what happens if there are different values having the same identifier? Maybe, only suggestions having the same type should be grouped?

import C (a)
import D (f)

b

suggestions

might be grouped as

keksnicoh commented 4 years ago

I would love to contribute but i got stuck running the plugin locally at the moment. I made a run configuration which builds a new IDE, but unfortunately, the plugin is not available then.

.run/intellij-haskell.run.xml

<component name="ProjectRunConfigurationManager">
  <configuration default="false" name="IntelliJ Haskell" type="#org.jetbrains.idea.devkit.run.PluginConfigurationType">
    <module name="IntelliJ Haskell" />
    <option name="VM_PARAMETERS" value="-Xmx512m -Xms256m -ea" />
    <option name="PROGRAM_PARAMETERS" value="" />
    <alternative-path path="$APPLICATION_HOME_DIR$" alternative-path-enabled="true" />
    <predefined_log_file enabled="true" id="idea.log" />
    <method v="2">
      <option name="Make" enabled="true" />
    </method>
  </configuration>
</component>

any hints what I should change?

rikvdkleij commented 4 years ago

I don't understand your approach of running IntelliJ. Please see https://github.com/rikvdkleij/intellij-haskell/blob/master/CONTRIBUTING.md

rikvdkleij commented 4 years ago

Should be fixed in beta72

rikvdkleij commented 4 years ago

Please reopen if still an issue.