Skip to content

feat: show full type in tooltips for hints #19640

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

roife
Copy link
Member

@roife roife commented Apr 20, 2025

fix #19615.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 20, 2025
@roife roife marked this pull request as draft April 21, 2025 02:25
@roife roife marked this pull request as ready for review April 21, 2025 03:22
@roife
Copy link
Member Author

roife commented Apr 21, 2025

image

@Veykril Veykril added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 5, 2025
@roife roife force-pushed the show-full-type-hints branch from d741cd3 to b9d0401 Compare June 27, 2025 06:33
@roife roife force-pushed the show-full-type-hints branch 2 times, most recently from 406534f to 289c402 Compare July 1, 2025 05:16
@roife roife requested a review from Veykril July 1, 2025 06:13
@roife
Copy link
Member Author

roife commented Jul 1, 2025

Previously, hovering over any part of a hint would display the complete type.

Now, the certain hidden content is only showed when the mouse hovers over its corresponding ....

image

Comment on lines 158 to 167
fn maybe_truncated<T, F: FnOnce(&mut Self) -> T>(&mut self, f: F) -> T {
let truncated = self.should_truncate() && self.fmt.start_truncated();
let res = f(self);
if truncated {
self.fmt.end_truncated();
}
res
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect something like the following instead

Suggested change
fn maybe_truncated<T, F: FnOnce(&mut Self) -> T>(&mut self, f: F) -> T {
let truncated = self.should_truncate() && self.fmt.start_truncated();
let res = f(self);
if truncated {
self.fmt.end_truncated();
}
res
}
fn maybe_truncated<T, F: FnOnce(&mut Self) -> T>(&mut self, f: F) -> Option<T> {
if self.should_truncate() {
let end_truncate = self.fmt.start_truncated();
if self.fmt.start_truncated() {
let res = f(self);
self.end_truncated();
Some(res)
} else {
write!(self, "{TYPE_HINT_TRUNCATION}")
None
}
} else {
Some(f(self))
}
}

This way any writers that don't care about the truncation behavior will have the previous behavior, that is they write the truncation dots as before.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we should limit the behavior of "write dots" within HirFormatter and not leak it into the specific writer, right? I will modify this part.

Copy link
Member Author

@roife roife Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we should do three things in end_truncated:

  1. Move the contents of last_part to tooltip
  2. Write TYPE_HINT_TRUNCATION into last_part
  3. Create a new part

Since the second step must be completed after 1 and before 3, we may need to let writer handle it, but I can have end_truncated take a parameter as a placeholder, so that TYPE_HINT_TRUNCATION is not leaked.

If the writer has more complex behavior in the future, we can consider using a closure.

(resolved in bed7a75)

@roife roife force-pushed the show-full-type-hints branch from c5d3132 to a0dc18e Compare July 17, 2025 05:57
@roife roife requested a review from Veykril July 17, 2025 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show the collapsed part in tooltips for inlay hints.
3 participants