From 6f51f728a114078a0c3a029fc66cfb8c4daf9a28 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 1 Dec 2020 13:53:12 +0300 Subject: Type-safer API for dealing with parameter lists with optional self --- crates/hir/src/code_model.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'crates/hir/src/code_model.rs') diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index f06b5cd9f..ba121104b 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -744,14 +744,13 @@ impl Function { Some(SelfParam { func: self.id }) } - pub fn params(self, db: &dyn HirDatabase) -> Vec { + pub fn assoc_fn_params(self, db: &dyn HirDatabase) -> Vec { let resolver = self.id.resolver(db.upcast()); let ctx = hir_ty::TyLoweringContext::new(db, &resolver); let environment = TraitEnvironment::lower(db, &resolver); db.function_data(self.id) .params .iter() - .skip(if self.self_param(db).is_some() { 1 } else { 0 }) .map(|type_ref| { let ty = Type { krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate, @@ -764,6 +763,14 @@ impl Function { }) .collect() } + pub fn method_params(self, db: &dyn HirDatabase) -> Option> { + if self.self_param(db).is_none() { + return None; + } + let mut res = self.assoc_fn_params(db); + res.remove(0); + Some(res) + } pub fn is_unsafe(self, db: &dyn HirDatabase) -> bool { db.function_data(self.id).is_unsafe -- cgit v1.2.3 From 9d94ffad44f2b250e498f162cd498aed62877c8e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 1 Dec 2020 14:23:00 +0300 Subject: Place cursor correctly when completing assoc fns with self --- crates/hir/src/code_model.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'crates/hir/src/code_model.rs') diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index ba121104b..4500050f1 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -806,6 +806,7 @@ impl From for Access { } } +#[derive(Debug)] pub struct Param { ty: Type, } -- cgit v1.2.3