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 5 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 from b9d0401 to 406534f Compare July 1, 2025 04:39
@roife roife force-pushed the show-full-type-hints branch 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 165
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

@roife roife Jul 7, 2025

Choose a reason for hiding this comment

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

When self.fmt.start_truncated() returns false, we should call f(self) to write the type into last_part instead of writing .... A false return value indicates that the last part is a truncated part, and its content will be displayed in the tooltip. Therefore, we should write the complete value directly rather than truncating it.

For example, in SSSS<...>, if the ... represents a long type like TTTT<i32>, should_truncated will be true, but we should write the full signature TTTT<i32> into the last part (so that the tooltip shows TTTT<i32>) instead of just writing TTTT<...>.

if self.should_truncate() {
return write!(self, "{TYPE_HINT_TRUNCATION}");
}
in_truncated = !in_truncated && self.should_truncate() && self.fmt.start_truncated();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
in_truncated = !in_truncated && self.should_truncate() && self.fmt.start_truncated();
if self.should_truncate() {
in_truncated |= !in_truncated && self.fmt.start_truncated();
if !in_truncated {
return write!(self, "{TYPE_HINT_TRUNCATION}");
}
}

same reason as the review above

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