rikvdkleij / intellij-haskell

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

Quick documentation for (+) shows documentation for (++) #436

Closed AlainODea closed 5 years ago

AlainODea commented 5 years ago

If I have the following code:

f x y = x + y

And I place my caret before the + and click View > Quick Documentation (or hit F1 on macOS or Ctrl-Q on Windows/Linux) I get the following popup:

(++) :: [a] -> [a] -> [a] base Prelude

Append two lists, i.e.,

[x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn]
[x1, ..., xm] ++ [y1, ...] == [x1, ..., xm, y1, ...]

If the first list is not finite, the result is the first list.  

GHC.Num -- No type info available


Here's a screenshot of the behaviour: Quick documentation for (+) shows documentation for (++)

I tried to follow HaskellDocumentationProvider's use of TypeInfoComponent and StringUtils. I couldn't find the issue in StringUtils so I suspect it is somewhere down the TypeInfoComponent rabbit hole.

I've gotten the development setup working following your excellent CONTRIBUTING.md, so I will debug this and hopefully have a PR to fix it fairly soon.

AlainODea commented 5 years ago

The problem is something in how HoogleComponent encodes the arguments for the hoogle command. It seems like searching for + literally in hoogle on the CLI also does not work.

Literally running this command brings up the documentation for (++):

/Users/alain_odea/Library/Caches/com.github.rikvdkleij.intellij-haskell/lts-13/bin/hoogle --database=/Users/alain_odea/Library/Caches/com.github.rikvdkleij.intellij-haskell/finding-success-and-failure/hoogle -i + +GHC.Num +Prelude

It looks like the bug is in hoogle. I'll see how to encode + to work around this.

AlainODea commented 5 years ago

Show Type (Option-Command-P) correctly shows (+) :: Num a => a -> a -> a.

The Edit Source (Command-Down Arrow) option in the gear menu on the quick documentation popup works as expected: it takes me to GHC.Num to the line where (+) is defined. This appears to be isolated to how the Hoogle CLI handles an undocumented element. Excluding +Prelude from the query correctly returns no docs, but isn't a viable fix since it would break quick doc on things like map.

This may actually be a weird corner case in that (+) has no documentation and (++) is in Prelude and using hoogle from the command line allows partial matches, so (++) is the best match with documentation. The problem is that it is partial matching. How do we get Hoogle to partial match? We need a search tag. Tags are defined here, and particularly the exact tag: https://github.com/ndmitchell/hoogle/blob/de11775da67547079d3e8069aa57e221eec4ea5e/src/Output/Tags.hs#L85

Thankfully, this has a direct solution: add is:exact to the query. I have done some cursory testing and should have a PR shortly. I'm open to performing additional tests.

rikvdkleij commented 5 years ago

Your fix is released in beta49, https://github.com/rikvdkleij/intellij-haskell/releases/tag/v1.0.0-beta49

AlainODea commented 5 years ago

Thank you!