-
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
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.
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.
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.
Here we should do three things in end_truncated
:
- Move the contents of
last_part
totooltip
- Write
TYPE_HINT_TRUNCATION
intolast_part
- 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)
c5d3132
to
a0dc18e
Compare
fix #19615.