Show impl Trait in argument positon in completion details

`hir`: Use `db.callable_item_signature` query more.
This commit is contained in:
iDawer 2022-04-16 19:18:42 +05:00
parent c53412046f
commit d26deb5b9f
2 changed files with 39 additions and 19 deletions

View File

@ -1389,15 +1389,15 @@ impl Function {
} }
pub fn assoc_fn_params(self, db: &dyn HirDatabase) -> Vec<Param> { pub fn assoc_fn_params(self, db: &dyn HirDatabase) -> Vec<Param> {
let resolver = self.id.resolver(db.upcast());
let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
let environment = db.trait_environment(self.id.into()); let environment = db.trait_environment(self.id.into());
db.function_data(self.id) let substs = TyBuilder::placeholder_subst(db, self.id);
.params let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs);
callable_sig
.params()
.iter() .iter()
.enumerate() .enumerate()
.map(|(idx, (_, type_ref))| { .map(|(idx, ty)| {
let ty = Type { env: environment.clone(), ty: ctx.lower_ty(type_ref) }; let ty = Type { env: environment.clone(), ty: ty.clone() };
Param { func: self, ty, idx } Param { func: self, ty, idx }
}) })
.collect() .collect()
@ -1411,17 +1411,17 @@ impl Function {
} }
pub fn params_without_self(self, db: &dyn HirDatabase) -> Vec<Param> { pub fn params_without_self(self, db: &dyn HirDatabase) -> Vec<Param> {
let resolver = self.id.resolver(db.upcast());
let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
let environment = db.trait_environment(self.id.into()); let environment = db.trait_environment(self.id.into());
let substs = TyBuilder::placeholder_subst(db, self.id);
let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs);
let skip = if db.function_data(self.id).has_self_param() { 1 } else { 0 }; let skip = if db.function_data(self.id).has_self_param() { 1 } else { 0 };
db.function_data(self.id) callable_sig
.params .params()
.iter() .iter()
.enumerate() .enumerate()
.skip(skip) .skip(skip)
.map(|(idx, (_, type_ref))| { .map(|(idx, ty)| {
let ty = Type { env: environment.clone(), ty: ctx.lower_ty(type_ref) }; let ty = Type { env: environment.clone(), ty: ty.clone() };
Param { func: self, ty, idx } Param { func: self, ty, idx }
}) })
.collect() .collect()
@ -1573,11 +1573,12 @@ impl SelfParam {
} }
pub fn ty(&self, db: &dyn HirDatabase) -> Type { pub fn ty(&self, db: &dyn HirDatabase) -> Type {
let resolver = self.func.resolver(db.upcast()); let substs = TyBuilder::placeholder_subst(db, self.func);
let ctx = hir_ty::TyLoweringContext::new(db, &resolver); let callable_sig =
db.callable_item_signature(self.func.into()).substitute(Interner, &substs);
let environment = db.trait_environment(self.func.into()); let environment = db.trait_environment(self.func.into());
let ty = callable_sig.params()[0].clone();
Type { env: environment, ty: ctx.lower_ty(&db.function_data(self.func).params[0].1) } Type { env: environment, ty }
} }
} }
@ -2576,10 +2577,9 @@ impl Impl {
} }
pub fn self_ty(self, db: &dyn HirDatabase) -> Type { pub fn self_ty(self, db: &dyn HirDatabase) -> Type {
let impl_data = db.impl_data(self.id);
let resolver = self.id.resolver(db.upcast()); let resolver = self.id.resolver(db.upcast());
let ctx = hir_ty::TyLoweringContext::new(db, &resolver); let substs = TyBuilder::placeholder_subst(db, self.id);
let ty = ctx.lower_ty(&impl_data.self_ty); let ty = db.impl_self_ty(self.id).substitute(Interner, &substs);
Type::new_with_resolver_inner(db, &resolver, ty) Type::new_with_resolver_inner(db, &resolver, ty)
} }

View File

@ -642,3 +642,23 @@ fn main() {
"]], "]],
); );
} }
#[test]
fn detail_impl_trait_in_argument_position() {
check_empty(
r"
//- minicore: sized
trait Trait<T> {}
struct Foo;
impl Foo {
fn bar<U>(_: impl Trait<U>) {}
}
fn main() {
Foo::$0
}
",
expect![[r"
fn bar() fn(impl Trait<U>)
"]],
);
}