aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-06-11 14:49:56 +0100
committerAleksey Kladov <[email protected]>2019-06-11 16:28:51 +0100
commit4f94af3c4aaa57ebb4cb01f7e4edfb3a0821b09b (patch)
treeb7bbb49966711e4b771d93561d1635607c300369 /crates/ra_hir/src/code_model.rs
parent36865adcb946d5567fb61d3547b78fc71df58b20 (diff)
use Source for Function
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r--crates/ra_hir/src/code_model.rs20
1 files changed, 14 insertions, 6 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 765850488..aa6eb741b 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -603,6 +603,14 @@ pub struct Function {
603 pub(crate) id: FunctionId, 603 pub(crate) id: FunctionId,
604} 604}
605 605
606impl HasSource for Function {
607 type Ast = TreeArc<ast::FnDef>;
608
609 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::FnDef>> {
610 self.id.source(db).into()
611 }
612}
613
606/// The declared signature of a function. 614/// The declared signature of a function.
607#[derive(Debug, Clone, PartialEq, Eq)] 615#[derive(Debug, Clone, PartialEq, Eq)]
608pub struct FnSignature { 616pub struct FnSignature {
@@ -619,11 +627,11 @@ impl FnSignature {
619 db: &(impl DefDatabase + AstDatabase), 627 db: &(impl DefDatabase + AstDatabase),
620 func: Function, 628 func: Function,
621 ) -> Arc<FnSignature> { 629 ) -> Arc<FnSignature> {
622 let (_, node) = func.source(db); 630 let src = func.source(db);
623 let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); 631 let name = src.ast.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
624 let mut params = Vec::new(); 632 let mut params = Vec::new();
625 let mut has_self_param = false; 633 let mut has_self_param = false;
626 if let Some(param_list) = node.param_list() { 634 if let Some(param_list) = src.ast.param_list() {
627 if let Some(self_param) = param_list.self_param() { 635 if let Some(self_param) = param_list.self_param() {
628 let self_type = if let Some(type_ref) = self_param.ascribed_type() { 636 let self_type = if let Some(type_ref) = self_param.ascribed_type() {
629 TypeRef::from_ast(type_ref) 637 TypeRef::from_ast(type_ref)
@@ -647,7 +655,7 @@ impl FnSignature {
647 params.push(type_ref); 655 params.push(type_ref);
648 } 656 }
649 } 657 }
650 let ret_type = if let Some(type_ref) = node.ret_type().and_then(|rt| rt.type_ref()) { 658 let ret_type = if let Some(type_ref) = src.ast.ret_type().and_then(|rt| rt.type_ref()) {
651 TypeRef::from_ast(type_ref) 659 TypeRef::from_ast(type_ref)
652 } else { 660 } else {
653 TypeRef::unit() 661 TypeRef::unit()
@@ -676,8 +684,8 @@ impl FnSignature {
676} 684}
677 685
678impl Function { 686impl Function {
679 pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> (HirFileId, TreeArc<ast::FnDef>) { 687 pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::FnDef>> {
680 self.id.source(db) 688 self.id.source(db).into()
681 } 689 }
682 690
683 pub fn module(self, db: &impl DefDatabase) -> Module { 691 pub fn module(self, db: &impl DefDatabase) -> Module {