mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
feature: Make replace_or_with_or_else assists more generally applicable
This commit is contained in:
parent
e6ba791dce
commit
199bc82ce8
8 changed files with 397 additions and 411 deletions
|
@ -1676,6 +1676,10 @@ impl Function {
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub fn num_params(self, db: &dyn HirDatabase) -> usize {
|
||||
db.function_data(self.id).params.len()
|
||||
}
|
||||
|
||||
pub fn method_params(self, db: &dyn HirDatabase) -> Option<Vec<Param>> {
|
||||
if self.self_param(db).is_none() {
|
||||
return None;
|
||||
|
@ -3846,11 +3850,13 @@ impl Type {
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME: Document this
|
||||
#[derive(Debug)]
|
||||
pub struct Callable {
|
||||
ty: Type,
|
||||
sig: CallableSig,
|
||||
callee: Callee,
|
||||
/// Whether this is a method that was called with method call syntax.
|
||||
pub(crate) is_bound_method: bool,
|
||||
}
|
||||
|
||||
|
@ -3884,14 +3890,14 @@ impl Callable {
|
|||
Other => CallableKind::Other,
|
||||
}
|
||||
}
|
||||
pub fn receiver_param(&self, db: &dyn HirDatabase) -> Option<ast::SelfParam> {
|
||||
pub fn receiver_param(&self, db: &dyn HirDatabase) -> Option<(ast::SelfParam, Type)> {
|
||||
let func = match self.callee {
|
||||
Callee::Def(CallableDefId::FunctionId(it)) if self.is_bound_method => it,
|
||||
_ => return None,
|
||||
};
|
||||
let src = func.lookup(db.upcast()).source(db.upcast());
|
||||
let param_list = src.value.param_list()?;
|
||||
param_list.self_param()
|
||||
Some((param_list.self_param()?, self.ty.derived(self.sig.params()[0].clone())))
|
||||
}
|
||||
pub fn n_params(&self) -> usize {
|
||||
self.sig.params().len() - if self.is_bound_method { 1 } else { 0 }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue