-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Optimize the user experience when line gets too long after inlay hints are inserted. #3138
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
Comments
I guess we could opt out showing inlay hints when the length of the line of code goes over some user-defined limit. |
We can do that, but I am unsure if the cure won't be worse than disease. I guess we should just do whatever IntelliJ does in this case (which IIRC is nothing). |
It would be great to get the code or at least see the screenshots of such cases. |
Sure, one example is here: This line doesn't look very long by itself, however with inlay hints added, it looks like this: |
That's an interesting case actually, first time ever I see the No good ideas for the general case alas. |
Create a small repro, don't know if this helps: trait T1 {
type O;
}
struct F<X: T1>(X);
impl<X: T1> F<X> {
fn f<F>(&self, v: F) where F: FnOnce(&X::O) {
unimplemented!()
}
}
struct U;
impl T1 for U {
type O = ();
}
fn main() {
let s: F<U> = F(U);
s.f(|z| {});
println!("Hello, world!");
} z is annotated: |
Thanks a lot, small repros help tremendously. Yet this example does not show any type hints for me since RA fails to infer its type: I wonder, can that be caused by the rustc version you use? |
I'm on the latest stable (1.41.0) and this version https://github.com/rust-analyzer/rust-analyzer/tree/2020-02-11 of pre-compiled ra. |
@crlf0710, I wouldn't be so sure about the version of precompiled |
Hmm, yeah, you do use 2020-02-11 |
On a newer version it started to for me too, weird. But after I looked at it, I think this particular one is type-inference related, so we better fix that, not the inlay hints. |
I don't think this particular case differs from this one: Or, rather, it differs in a way that it's type inreference-related: instead of thinking about the hints shortening for this case, we need to concentrate on type resolution to eliminate all As for the long identifier names, I think it's a minor case compared to the complex types with So no bright ideas currently, especially with intellij-rust having neither also :) |
The |
The full repro is here: #3138 (comment) It uses |
I think I know what the problem is; the projection appears in a type in a where clause, where we can't normalize it at first. We probably need to normalize associated types in any type we get back from trait solving. |
Filed #3232. |
Would it be super slick if we could use the editor ruler as a guide as to whether we have space on the line to add in the inlays? Nothing would then breach the line. An alternative is to turn the problem on its head - turn editor.rulers off and instead highlight chars past a set width. (could be done in a separate extension) |
@gilescope though I use a ruller, but time-to-time I trespass. I did think about it, though was not brave enough to propose since not everyone uses rullers, and what if there are more than 1 of them? But anyway the feature can be just controlled by a boolean flag and most strict ruller presence, I am not sure that many users will do use it... |
With the resolution of #3232, the original motivating case looks much better now! Thanks a lot for this. If there's no more motivating cases raised up (i don't really have any now), i'm happy to just close this issue as resolved~ |
Thanks.
|
Would it be possible to integrate inline hints with the built-in VSCode line wrap feature? It seems, inline hints are ignored by the |
No, but please mention that in #2797 (comment). |
@SomeoneToIgnore I don't think that PR actually closes this issue, just another band-aid on it. A better solution would be to dynamically adjust based on the line length. |
From the twitter: https://twitter.com/spacemeowx2/status/1499432606873812995 |
I don't think this is in our hands any longer now that we moved to native VSCode inlay hints? |
I'm not sure how well |
Automatic Rustup
Automatic Rustup
Generally the code is usually formatted with the rustfmt, which keeps the characters per line below a certain limit. However when inlay hints get inserted, the lines sometimes gets too long, or even trimmed by screen edge.
Not sure what's the best solution for this. Maybe when a line will become too long after inlay hints are inserted, move all the hints out of line into a separate line using tiny font sizes as annotations?
The text was updated successfully, but these errors were encountered: