ndmitchell / hoogle

Haskell API search engine
http://hoogle.haskell.org/
Other
754 stars 137 forks source link

Action/Server reorder modules #393

Open Profpatsch opened 2 years ago

Profpatsch commented 2 years ago

(This is on top of #392)

The previous sorting of modules within packages meant that the first link would usually point to some random re-export of the definition. I figured out that the modules where in reversed topological order, so by reversing & applying a heuristic for internal modules, we get vastly improved default module links.

Action/Server: reverse the order of modules in showFroms

This will not change the top-link for the target to the first module, just switch around the displayed list.

We need to push the logic out a bit further to change the top target.

Action/Server: Take the main search result link from reversed module

Previously only the module list was reversed, but the main link to a search result would still point to the first module in the non-reversed list.

This uses the logic for both the showFroms and the main result loop.

Note that the order of packages is still pretty much arbitrary, so the user might still land in a package other than where the symbol was originally defined.

But for example in the case of find, the base package is most often displayed first, and the find from Data.Foldable will now take precedence of the reexport from the reexport in Data.List.

Action/Server: Sort any leading Internal module to the back

After reversing the module list, we have a pretty good topological order for modules, meaning the main link of a search result target (and the first module displayed) will usually be the definition of that target.

There is however a convention to expose .Internal modules so that users can use unstable APIs if they have a need to.

So in case the first module is such an .Internal module, we want to sort it back and display the next module in the list first.

For example the result

toList :: IntSet -> [Key]
containers Data.IntSet.Internal Data.IntSet

will now be displayed as

toList :: IntSet -> [Key]
containers Data.IntSet Data.IntSet.Internal

and link to Data.IntSet by default.

Profpatsch commented 2 years ago

cc @smatting

Profpatsch commented 2 years ago

I noticed a problem with this; the documentation & module was previously taken just from the first module in each target list, but after filtering out everything that does not contain a (module or package) in the target, some results might be left without any results, meaning the partial match on Target{..}:_ fails.

Profpatsch commented 2 years ago

The problem should be fixed now & the PR ready for review.