Skip to content
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

Inlay hints usage #2938

Open
July541 opened this issue Jun 2, 2022 · 18 comments
Open

Inlay hints usage #2938

July541 opened this issue Jun 2, 2022 · 18 comments
Labels
status: in discussion Not actionable, because discussion is still ongoing or there's no decision yet type: enhancement New feature or request

Comments

@July541
Copy link
Collaborator

July541 commented Jun 2, 2022

In order to prevent spam, I open a thread to discuss about the inlay hint usage in Haskell.

Previous info is here: #2019 (comment)

lsp-3.17 had supported inlay hint, in which can embed some useful info, it wildly used by displaying function parameter names in other languages. But it is not suitable in Haskell since Haskell have a lot of currying, which looks not valid to display parameter name in Haskell.

Sample of inlay hint:
image

I don't want Haskell missing this straightforward function, so I wrote these to discuss what we can do to use inlay hint best, here are some I'd like:

  1. Show type signature for let expressions
f = let g {- inlay hint here, should be `:: Bool` -}= True
     in g
  1. Show operator fixity as mentioned in Feature request: Fixity information in hover #2019 (comment)

All these are initial ideas for discussion, feel free to put forward any suggestions:)

@July541 July541 added type: enhancement New feature or request status: in discussion Not actionable, because discussion is still ongoing or there's no decision yet labels Jun 2, 2022
@drsooch
Copy link
Collaborator

drsooch commented Jun 2, 2022

+1 for let bindings.

I'd have to see what the fixity one actually looks like, but in my head it seems like overload.

@pepeiborra
Copy link
Collaborator

pepeiborra commented Jun 2, 2022

+1 for let bindings too

Can we use this to show the implicit imports list, instead of a code lens?

@July541
Copy link
Collaborator Author

July541 commented Jun 4, 2022

Can we use this to show the implicit imports list, instead of a code lens?

Not sure, I haven't seen any inlay hint in a new line. But is there any shortcoming for code lens?

@pepeiborra
Copy link
Collaborator

The idea is to show the implicit imports list inline, not in a new line. We have wanted this for a while:

#426 (comment)

@michaelpj
Copy link
Collaborator

Note that inlay hints aren't supported by the lsp library yet. I'm working on generating the types from the new machine-readable version, which will hopefully include this, but it may be a while.


More ideas

Type signatures

Lambda arguments? i.e.

\x {- :: Int -} -> ...

Function arguments? i.e.

foo x {- :: Int -}

(probably not, a bit redundant with the main type signature?)

Bindings in do blocks? i.e.

x {- :: Int -} <- ...

These are all really special cases of "put an inlay hint every time a variable is bound without a type signature", but I think that would probably be too much in many cases. But might be worth trying to see if it's unbearable! Maybe the general case is what we want.

Implicit names

Record wildcards?

x{... {- foo, bar, baz -}}

An explicit imports inlay hint is arguably an example of this!

Misc

Record names in positional record construction?

MyRec {- foo= -} a {- bar= -} b {- baz= -} c

@drsooch
Copy link
Collaborator

drsooch commented Jun 7, 2022

These are all really special cases of "put an inlay hint every time a variable is bound without a type signature", but I think that would probably be too much in many cases. But might be worth trying to see if it's unbearable! Maybe the general case is what we want.

I can see someone wanting to keep some of the inlay hints but not all (myself included). Is this something we want to allow to be configurable? Or should we aim for a minimum case first (i.e. just let bindings and lambdas for example) and go from there?

@michaelpj
Copy link
Collaborator

Ideally we don't configure things too much, but we might want a "noisy" version and a "quiet" version, perhaps.

I think the observation about the general case is more for design thinking: I'm not sure I have a good rationale for why some places that introduce a name without a type signature should get inlay hints and some shouldn't. So what's our heuristic?

@July541
Copy link
Collaborator Author

July541 commented Jun 7, 2022

Agree @michaelpj 's ideas, just one thought, I prefer to show function parameters' name instead of their type. (Although not beautiful to look at)

@July541
Copy link
Collaborator Author

July541 commented Jun 7, 2022

I still believe it's not bad to have more configure, it has little effect for most users(they won't touch these settings)

Here is some configuration(partial) for TypeScript.

image


Here is some configuration(partial) for Rust.

image

@michaelpj
Copy link
Collaborator

Also maybe holes: #3228

@michaelpj
Copy link
Collaborator

I think all our code lenses that display signatures should be inlay hints also: #3254

@ozkutuk
Copy link
Collaborator

ozkutuk commented Nov 16, 2022

Out of curiosity, what is the current status of the inlay hints support of lsp library?

@michaelpj
Copy link
Collaborator

It'll be there once I finish haskell/lsp#458 😅

@rockboynton
Copy link

It'll be there once I finish haskell/lsp#458 😅

@michaelpj I noticed the linked issue was closed in favor of another one that is now merged. Do you know how long until that will land in a release?

@michaelpj
Copy link
Collaborator

Support in the library has been there for a while now, now someone just actually needs to implement using them in HLS.

@michaelpj
Copy link
Collaborator

Another idea: show inferred deriving strategies and allow clicking on them to make them explicit.

@jetjinser jetjinser mentioned this issue Mar 10, 2024
10 tasks
@jetjinser
Copy link

HI, guys. I think I've made some progress #4131. I successfully display fixity info via inlay hints, there's still a lot of work to do :)

@Jashweii
Copy link

If you're looking for ideas:
Related to fixity - what about inserting parentheses? So a * b + c / d gains inlay hints (a * b) + (c / d) in accordance with fixity (I might be remembering this from some other IDE, not sure)
Along the lines of #2938 (comment) there's other implicit stuff that could be wrong, like type roles, defaulted instances e.g. in show . read, overloaded list/string syntax, defaulted method implementations.
Some less clear ideas - with LinearTypes it might be useful to see info about usage (e.g. let %1 inference coming in 9.10), I also wonder if there's any useful information that could be shown for analysing performance like where allocations can occur or rules can fire or what is still lazy in O2 or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: in discussion Not actionable, because discussion is still ongoing or there's no decision yet type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants