fix: simplify types of variables for hover tooltip (#959)

* feat: type for hover on var

* test: update snapshots for hover on params

* fix: simplify type before formatting

* test: update snapshot

---------

Co-authored-by: Myriad-Dreamin <camiyoru@gmail.com>
This commit is contained in:
Yifan Song 2024-12-07 12:32:40 +01:00 committed by GitHub
parent 4a236e88cd
commit 44b3f3f8c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 11 additions and 5 deletions

View file

@ -305,12 +305,18 @@ pub(crate) fn var_docs(ctx: &mut LocalContext, pos: Span) -> Option<VarDocs> {
let ty = type_info.type_of_span(pos)?;
// todo multiple sources
// Must use raw result as type aliases contain the source information.
let mut srcs = ty.sources();
srcs.sort();
log::info!("check variable docs of ty: {ty:?} => {srcs:?}");
let doc_source = srcs.into_iter().next()?;
let return_ty = format_ty(Some(&ty));
// todo people can easily forget to simplify the type which is not good. we
// might find a way to ensure them at compile time.
//
// Must be simplified before formatting, to expand type aliases.
let simplified_ty = type_info.simplify(ty, false);
let return_ty = format_ty(Some(&simplified_ty));
match doc_source {
DocSource::Var(var) => {
let docs = type_info