mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Merge #11481
11481: Display parameter names when hovering over a function pointer r=Veykril a=Vannevelj Implements #11474 The idea is pretty straightforward: previously we constructed the hover based on just the parameter types, now we pass in the parameter names as well. I went for a quick-hit approach here but I expect someone will be able to point me to a better way of resolving the identifier. I haven't figured out yet how to actually run my rust-analyzer locally so I can see it in action but the unit test indicates it should work. Co-authored-by: Jeroen Vannevel <jer_vannevel@outlook.com>
This commit is contained in:
commit
24255e5b3d
5 changed files with 105 additions and 24 deletions
|
@ -1094,20 +1094,32 @@ impl HirDisplay for TypeRef {
|
|||
inner.hir_fmt(f)?;
|
||||
write!(f, "]")?;
|
||||
}
|
||||
TypeRef::Fn(tys, is_varargs) => {
|
||||
TypeRef::Fn(parameters, is_varargs) => {
|
||||
// FIXME: Function pointer qualifiers.
|
||||
write!(f, "fn(")?;
|
||||
f.write_joined(&tys[..tys.len() - 1], ", ")?;
|
||||
if *is_varargs {
|
||||
write!(f, "{}...", if tys.len() == 1 { "" } else { ", " })?;
|
||||
}
|
||||
write!(f, ")")?;
|
||||
let ret_ty = tys.last().unwrap();
|
||||
match ret_ty {
|
||||
TypeRef::Tuple(tup) if tup.is_empty() => {}
|
||||
_ => {
|
||||
write!(f, " -> ")?;
|
||||
ret_ty.hir_fmt(f)?;
|
||||
if let Some(((_, return_type), function_parameters)) = parameters.split_last() {
|
||||
for index in 0..function_parameters.len() {
|
||||
let (param_name, param_type) = &function_parameters[index];
|
||||
if let Some(name) = param_name {
|
||||
write!(f, "{}: ", name)?;
|
||||
}
|
||||
|
||||
param_type.hir_fmt(f)?;
|
||||
|
||||
if index != function_parameters.len() - 1 {
|
||||
write!(f, ", ")?;
|
||||
}
|
||||
}
|
||||
if *is_varargs {
|
||||
write!(f, "{}...", if parameters.len() == 1 { "" } else { ", " })?;
|
||||
}
|
||||
write!(f, ")")?;
|
||||
match &return_type {
|
||||
TypeRef::Tuple(tup) if tup.is_empty() => {}
|
||||
_ => {
|
||||
write!(f, " -> ")?;
|
||||
return_type.hir_fmt(f)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -201,7 +201,7 @@ impl<'a> TyLoweringContext<'a> {
|
|||
TypeRef::Placeholder => TyKind::Error.intern(Interner),
|
||||
TypeRef::Fn(params, is_varargs) => {
|
||||
let substs = self.with_shifted_in(DebruijnIndex::ONE, |ctx| {
|
||||
Substitution::from_iter(Interner, params.iter().map(|tr| ctx.lower_ty(tr)))
|
||||
Substitution::from_iter(Interner, params.iter().map(|(_, tr)| ctx.lower_ty(tr)))
|
||||
});
|
||||
TyKind::Function(FnPointer {
|
||||
num_binders: 0, // FIXME lower `for<'a> fn()` correctly
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue