-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
base: master
Are you sure you want to change the base?
Conversation
d741cd3
to
b9d0401
Compare
b9d0401
to
406534f
Compare
406534f
to
289c402
Compare
crates/hir-ty/src/display.rs
Outdated
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 | ||
} |
There was a problem hiding this comment.
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
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
fix #19615.