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

Improve type hints for long/deeply nested types (parser combinators etc.) #11240

Open
zesterer opened this issue Jan 8, 2022 · 5 comments
Open
Labels
A-ide general IDE features A-inlay-hints inlay/inline hints A-ty type system / type inference / traits / method resolution C-feature Category: feature request

Comments

@zesterer
Copy link

zesterer commented Jan 8, 2022

Hello!

I'm the author of chumsky, a parser combinator crate. As I'm sure you know, parser combinators involve combining simple parsers together with the type system to produce parsers for more complex syntaxes.

Unfortunately, this can result in very large types that, although very useful to the compiler, are almost entirely useless for the programmer trying to work with them (each parser has a virtually identical API to any other, and so the type conveys no real meaning: only the traits that it implements matter).

I'm not personally a user of rust-analyzer, but I have a few users that are, and I've noticed that they're getting rather intrusive type annotations within combinator code, like so:

image

It would be great is there were a way to opt out of inline type hints (perhaps with an override) that could be controlled by crate developers. Perhaps it would be possible to have some sort of #[rust_analyzer(no_hint)] attribute that I can add to my combinator types that would be understood by rust-analyzer?

My apologies if this has already been requested: I checked existing issues already and was unable to find something similar.

@jhgg
Copy link
Contributor

jhgg commented Jan 10, 2022

I don't think we should allow crate developers to turn off inlay hints - I fear this might lead to even more confusion for the end user. But perhaps we should endeavor to render something more sensible for inlay hints in places like this, similar to what is done for iterable chains already.

bors bot added a commit that referenced this issue Jan 10, 2022
11247: Print a single ellipsis for any number of omitted types r=jonas-schievink a=jonas-schievink

Helps a little bit with #11240

bors r+

Co-authored-by: Jonas Schievink <[email protected]>
@flodiebold flodiebold changed the title Add a way to opt out of type hints on specific types Improve type hints for long/deeply nested types (parser combinators etc.) Mar 31, 2022
@flodiebold flodiebold added A-ty type system / type inference / traits / method resolution C-feature Category: feature request A-ide general IDE features labels Mar 31, 2022
@1Dragoon
Copy link

Couldn't type aliases solve this?

@flodiebold
Copy link
Member

No, because 1. rust-analyzer doesn't use type aliases when displaying types, and doing so is kind of complicated, and 2. type aliases can't really simplify such a nested type much anyway. padded() has to return Padded<Self>, so a type alias wouldn't help. Returning impl Parser would help, but has other problems.

@Veykril Veykril added the A-inlay-hints inlay/inline hints label Apr 26, 2022
@rami3l
Copy link
Member

rami3l commented Dec 8, 2022

Playing with @zesterer's idea a bit, I'm wondering how we might get lib authors involved in this process by allowing them to annotate for example, "I want this to be displayed as some impl Parser instead of the concrete type".

For the reference:

@Veykril
Copy link
Member

Veykril commented Dec 8, 2022

Ideally via #11556 would be my first thought

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ide general IDE features A-inlay-hints inlay/inline hints A-ty type system / type inference / traits / method resolution C-feature Category: feature request
Projects
None yet
Development

No branches or pull requests

6 participants