diff options
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 99f004905..26ebc445b 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -463,7 +463,7 @@ impl Function { | |||
463 | self.id.source(db) | 463 | self.id.source(db) |
464 | } | 464 | } |
465 | 465 | ||
466 | pub fn module(&self, db: &impl HirDatabase) -> Module { | 466 | pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { |
467 | self.id.module(db) | 467 | self.id.module(db) |
468 | } | 468 | } |
469 | 469 | ||
@@ -497,6 +497,12 @@ impl Function { | |||
497 | db.generic_params((*self).into()) | 497 | db.generic_params((*self).into()) |
498 | } | 498 | } |
499 | 499 | ||
500 | /// The containing impl block, if this is a method. | ||
501 | pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> { | ||
502 | let module_impls = db.impls_in_module(self.module(db)); | ||
503 | ImplBlock::containing(module_impls, (*self).into()) | ||
504 | } | ||
505 | |||
500 | // TODO: move to a more general type for 'body-having' items | 506 | // TODO: move to a more general type for 'body-having' items |
501 | /// Builds a resolver for code inside this item. | 507 | /// Builds a resolver for code inside this item. |
502 | pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { | 508 | pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { |
@@ -527,6 +533,16 @@ impl Const { | |||
527 | pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) { | 533 | pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) { |
528 | self.id.source(db) | 534 | self.id.source(db) |
529 | } | 535 | } |
536 | |||
537 | pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { | ||
538 | self.id.module(db) | ||
539 | } | ||
540 | |||
541 | /// The containing impl block, if this is a method. | ||
542 | pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> { | ||
543 | let module_impls = db.impls_in_module(self.module(db)); | ||
544 | ImplBlock::containing(module_impls, (*self).into()) | ||
545 | } | ||
530 | } | 546 | } |
531 | 547 | ||
532 | impl Docs for Const { | 548 | impl Docs for Const { |
@@ -544,6 +560,10 @@ impl Static { | |||
544 | pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) { | 560 | pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) { |
545 | self.id.source(db) | 561 | self.id.source(db) |
546 | } | 562 | } |
563 | |||
564 | pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { | ||
565 | self.id.module(db) | ||
566 | } | ||
547 | } | 567 | } |
548 | 568 | ||
549 | impl Docs for Static { | 569 | impl Docs for Static { |
@@ -562,6 +582,10 @@ impl Trait { | |||
562 | self.id.source(db) | 582 | self.id.source(db) |
563 | } | 583 | } |
564 | 584 | ||
585 | pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { | ||
586 | self.id.module(db) | ||
587 | } | ||
588 | |||
565 | pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { | 589 | pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { |
566 | db.generic_params((*self).into()) | 590 | db.generic_params((*self).into()) |
567 | } | 591 | } |
@@ -586,6 +610,16 @@ impl Type { | |||
586 | pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { | 610 | pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { |
587 | db.generic_params((*self).into()) | 611 | db.generic_params((*self).into()) |
588 | } | 612 | } |
613 | |||
614 | pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { | ||
615 | self.id.module(db) | ||
616 | } | ||
617 | |||
618 | /// The containing impl block, if this is a method. | ||
619 | pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> { | ||
620 | let module_impls = db.impls_in_module(self.module(db)); | ||
621 | ImplBlock::containing(module_impls, (*self).into()) | ||
622 | } | ||
589 | } | 623 | } |
590 | 624 | ||
591 | impl Docs for Type { | 625 | impl Docs for Type { |