Type information for arbitrary portions of code
ghcide gives me information on most alphanumeric symbols (and numeric literals) but there are two features that I'm used to from dante and/or intero:
- type information on operators
- type information on arbitrary selected expressions
Do these features exist, and have I simply not found them?
If not, any hints on how to implement them?
I'm able to see type information on operators.

Operators should definitely work, given that it seems to work in some cases, it would be good if you could provide a specific test case where it fails.
Getting type information of a range is a bit more tricky. It is obviously more complex to implement but there is a second issue here: LSP hover does only give us a position not a range. I’ve taken a quick look at the spec and I also couldn’t find any other method that we could use here either.
Operators should definitely work
Sorry, yes, they do (it's just that in my configuration symbols' types were being shown spontaneously, while it took a bit more effort for symbols).
I guess that the bug label isn't appropriate here, as everything that is expected to work (information about symbols) seems to work.
The type of arbitrary expression can be extracted indirectly in hls, using the eval plugin, that includes :t.
Not sure if it is possible right now to translate in the hover, using the lsp protocol as pointed by @cocreature. So we should wait for some spec update to implement it.
@jacg does the workaround using eval works for you?
That question should be addressed by me nearly twin @jacg :) Cheers,
FYI https://github.com/microsoft/language-server-protocol/issues/377
The type of arbitrary expression can be extracted indirectly in hls, using the eval plugin, that includes :t.
@jneira Could you please give some more advice on how to install/ configure?
@normenmueller you have to install haskell-language-server which includes by default the eval plugin (you can see it in action here ).
Then you can write -- >>> in the code to evaluate expressions in the module context:
-- >>> :t fooExe
fooExe :: [Char]
fooExe = "hi"
- pressing a link
Evaluate
-- >>> :t fooExe
-- fooExe :: [Char]
fooExe :: [Char]
fooExe = "hi"
You can write arbitrary expressions:
-- >>> :t "hi"
fooExe :: [Char]
fooExe = "hi"
-- >>> :t "hi"
-- "hi" :: [Char]
fooExe :: [Char]
fooExe = "hi"
@alanz commented in the issue originally in hls:
I guess someone needs to actually make a PR for microsoft/language-server-protocol#377
“Type information on arbitrary selected expressions” is the killer feature of any Haskell IDE.
vim-hdevtools has that. Actually, what it has works a little bit differently:
- Press the F1 key and it will select the token which the cursor is on, and tell you the type of the token.
- Press the F1 key again, and it will expand the selection to the next outer subexpression and tell you the type of that.
... and you can repeat step 2 as many times as you like.
It would be great if we could have that feature again with HLS.
As @jamesdbrock gently pointed in #1973, this feature used to work in haskell-ide-engine (see the pr in the vscode extension which added the feature here) Maybe it worths investigate how was done in hie, althoug it seems it used ghcmod underneath, a deprecated library that should not be used.
I found this comment explaining a bit on how they implemented this in rust-analyzer: https://github.com/microsoft/language-server-protocol/issues/377#issuecomment-889898650 -> maybe this is useful to guide the possible implementation efforts?
@alanz @mpickering does anyone have knowledge whether this is difficult in ghcide itself (getting type of arbitrary expression), ignoring the issues with LSP and clients?
Maybe we can make some step by step progress.
For type information, I bet we can hack something together using HIE files and hiedb.