-
-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing Inferred Type in Tooltip when using Visible Type Applications #4017
Comments
I find this curious and managed to reproduce the issue (with latest hls + ghc 9.4.8 on fedora) I narrowed down somewhat that the issue is observable in the vicinity of the following code:
When type application is not used, this usually contains 2 values (most general type and currently inferred type(?)) |
They are pretty dependent on the hieAst. Since we are hover only on the we can see it from the HIeAst.
|
Nice investigation @soulomoon I'd be interested how you got the printout of the relevant ranges. |
You can setup ghc session and build the HieAst for a simple file @jhrcek , without the HLS.
|
Awesome, thanks! This seems pretty tedious. I wonder what do the hls devs do when they want to investigate "what's in the hie ast"? Isn't there a way to pretty print it for debugging purposes? You know, to debug things like "the info I was expecting is not in this ast node, where can I get it instead?".. |
I am not sure the others, I just going through the source code of hls or ghc. it's a bit off topic here, maybe we can discuss this in matrix. |
So it seems like this is a bug in HIE file generation? I would expect the |
This does look better. Take a look at the evidence variables. They are the ones with more concrete types. |
Ok, I got to the bottom of this (what a fun learning experience this was 😄) TL;DR: not showing types when TypeApplications is used seems like deliberate design - the type is not shown at the bottom of markdown block because it is already shown at the top (so having it repeated at the bottom would seem redundant) More details:
Then there is this dropEnd1 logic which basically drops the last type from the list in cases when there's only single identifier associated with the hovered-over symbol. That logic has been implemented back in 2020 in this PR: 5dfee4c#diff-91f773bae93bbf86035573f4dbffa3035c1689b1bb7e17bde5937bb1271c0131R104 I hope the following screenshots from my debugging sessions (where I just |
Shame there's no comment explaining, maybe @wz1000 remembers and could write one? It seems like the logic we want is to not reproduce the "original" type signature. It's not clear that we're really achieving that, though; in that case we should be filtering out the original type signature from the list rather than what we're doing now. I'd be somewhat in favour of just displaying everything (ideally with a title for that section of the hover explaining what it means!), at least that's consistent. |
This explains how the HIE AST is shown in the user interface, but I am still wondering why the AST contains only the general type I was expecting HLS to behave similarly to GHCI in this case:
In fact, I would argue that showing the instantiated signature is more important than showing the original one (which can always be looked up in the documentation or source). Additionally, the fact that the user is using visible type applications indicates that the type inference situation is tricky and these are exactly the situations in which the user really benefits from insight into which types their expressions ultimately got assigned. |
This is just how the language works. for If the user explicitly writes I suppose what you want is the type of the expression |
I think there's maybe an issue in how people think about things indeed. I think it's quite natural to think that in Perhaps one issue in the
|
Ah, I think I understand now, that actually makes a lot of sense, thank you for explaining. So what I really want is to view the type of the expression The situation in the annotated case seems a little confusing, but nonetheless I find it incredibly useful to be able to view the inferred/elaborated types that way. Of course, ideally, we would like to be able to view the types of arbitrary expressions as proposed in #709. I have been teaching Haskell to a friend of mine and I think that this functionality would be very useful for people learning the language, as many things make so much more sense when you see the underlying types of the expressions involved. |
Thinking about this, I think there are some things we could do. In particular, while showing people the type of an arbitrary expression is hard, we can make some guesses about what expressions people might want to see. In particular, when hovering over an identifier here are a few ideas for things we could show:
|
Your environment
Which OS do you use?
ArchLinux
Which version of GHC do you use and how did you install it?
9.6.4 from ghcup
How is your project built (alternative: link to the project)?
cabal
Which LSP client (editor/plugin) do you use?
Code - OSS + vscode-haskell
Which version of HLS do you use and how did you install it?
2.6.0.0 from ghcup
Have you configured HLS in any way (especially: a
hie.yaml
file)?Steps to reproduce
Hovering over
print
in this example:Hovering over
print
in this example:Expected behaviour
The inferred type for
print
is shown in the tooltip in both examples.Actual behaviour
The inferred type for
print
is only shown with type annotations via::
, but not with visible type applications via@
. The inferred type is shown correctly without any type annotations (together with a warning about defaulting the type variable toInteger
).Debug information
I could not find anything relevant in the HLS output log either when typing the expression or when hovering to produce the tooltip.
The text was updated successfully, but these errors were encountered: