From 7e8527f74831b37c5757ea6b25e40bcbb61bb6d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Tue, 12 Feb 2019 10:33:23 +0200 Subject: Implement completion for associated items --- crates/ra_hir/src/ty/method_resolution.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index b8e911b88..e81bd3e06 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs @@ -174,4 +174,24 @@ impl Ty { } None } + + // This would be nicer if it just returned an iterator, but that runs into + // lifetime problems, because we need to borrow temp `CrateImplBlocks`. + pub fn iterate_impl_items( + self, + db: &impl HirDatabase, + mut callback: impl FnMut(ImplItem) -> Option, + ) -> Option { + let krate = def_crate(db, &self)?; + let impls = db.impls_in_crate(krate); + + for (_, impl_block) in impls.lookup_impl_blocks(db, &self) { + for item in impl_block.items() { + if let Some(result) = callback(*item) { + return Some(result); + } + } + } + None + } } -- cgit v1.2.3