haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.71k stars 368 forks source link

Better ordering for the list of actions for a "variable not in scope" #3540

Open MatthewDaggitt opened 1 year ago

MatthewDaggitt commented 1 year ago

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

When giving a list of suggestions for a variable not in scope 98% of the time, the action I want to do is to add it to the imports of an already existing module. The problem is when the list of possible modules is very long the add suggestions are right down the bottom.

image

image

Describe the solution you'd like

Sort the list of suggested actions to put the more likely ones at the top. In particular the import options (of which there may be zillions) should be below the add options.

Describe alternatives you've considered

N/A

Additional context

N/A

MatthewDaggitt commented 1 year ago

Another sorting criteria for within the import options: when a qualified variable is not in scope, e.g. Map.member then the qualified import suggestions which have Map in their name should be lifted to the top of the suggestions.

image

For example here Data.Map, Data.Map.Strict and Data.Map.Lazy should all be at the top of the suggestions.

michaelpj commented 1 year ago

So one issue is that get is re-exported frequently. I think that would be less bad if we implemented this suggestion.

But yes, I think it would be sensible to put the "Add to import list" code actions before the ones that create new imports.

For your second suggestion there is an importance score calculation which can be tweaked: https://github.com/haskell/haskell-language-server/blob/master/plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs#L1500

fendor commented 1 year ago

The second suggestion has been implemented in https://github.com/haskell/haskell-language-server/pull/3271

Moving the 'Add to import list' code action to the top is all that remains to do here, I think