mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
internal: Store function param names in ItemTree
This commit is contained in:
parent
f609efff87
commit
cd9d76e0ca
11 changed files with 60 additions and 91 deletions
|
@ -12,10 +12,7 @@ use hir_ty::{
|
|||
},
|
||||
Interner, TraitRefExt, WhereClause,
|
||||
};
|
||||
use syntax::{
|
||||
ast::{self, HasName},
|
||||
SmolStr,
|
||||
};
|
||||
use syntax::SmolStr;
|
||||
|
||||
use crate::{
|
||||
Adt, Const, ConstParam, Enum, Field, Function, GenericParam, HasCrate, HasVisibility,
|
||||
|
@ -69,7 +66,7 @@ impl HirDisplay for Function {
|
|||
};
|
||||
|
||||
let mut first = true;
|
||||
for (param, type_ref) in self.assoc_fn_params(f.db).into_iter().zip(&data.params) {
|
||||
for (name, type_ref) in &data.params {
|
||||
if !first {
|
||||
write!(f, ", ")?;
|
||||
} else {
|
||||
|
@ -79,11 +76,9 @@ impl HirDisplay for Function {
|
|||
continue;
|
||||
}
|
||||
}
|
||||
match param.pattern_source(f.db) {
|
||||
Some(ast::Pat::IdentPat(p)) if p.name().is_some() => {
|
||||
write!(f, "{}: ", p.name().unwrap())?
|
||||
}
|
||||
_ => write!(f, "_: ")?,
|
||||
match name {
|
||||
Some(name) => write!(f, "{}: ", name)?,
|
||||
None => write!(f, "_: ")?,
|
||||
}
|
||||
// FIXME: Use resolved `param.ty` or raw `type_ref`?
|
||||
// The former will ignore lifetime arguments currently.
|
||||
|
|
|
@ -1343,7 +1343,7 @@ impl Function {
|
|||
.params
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(idx, type_ref)| {
|
||||
.map(|(idx, (_, type_ref))| {
|
||||
let ty = Type { krate, env: environment.clone(), ty: ctx.lower_ty(type_ref) };
|
||||
Param { func: self, ty, idx }
|
||||
})
|
||||
|
@ -1421,6 +1421,10 @@ impl Param {
|
|||
&self.ty
|
||||
}
|
||||
|
||||
pub fn name(&self, db: &dyn HirDatabase) -> Option<Name> {
|
||||
db.function_data(self.func.id).params[self.idx].0.clone()
|
||||
}
|
||||
|
||||
pub fn as_local(&self, db: &dyn HirDatabase) -> Local {
|
||||
let parent = DefWithBodyId::FunctionId(self.func.into());
|
||||
let body = db.body(parent);
|
||||
|
@ -1454,7 +1458,7 @@ impl SelfParam {
|
|||
func_data
|
||||
.params
|
||||
.first()
|
||||
.map(|param| match &**param {
|
||||
.map(|(_, param)| match &**param {
|
||||
TypeRef::Reference(.., mutability) => match mutability {
|
||||
hir_def::type_ref::Mutability::Shared => Access::Shared,
|
||||
hir_def::type_ref::Mutability::Mut => Access::Exclusive,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue