aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/code_model.rs20
-rw-r--r--crates/ra_hir/src/docs.rs2
-rw-r--r--crates/ra_hir/src/expr.rs6
-rw-r--r--crates/ra_hir/src/expr/validation.rs2
-rw-r--r--crates/ra_hir/src/generics.rs2
-rw-r--r--crates/ra_hir/src/ty/infer.rs2
-rw-r--r--crates/ra_ide_api/src/completion/presentation.rs2
-rw-r--r--crates/ra_ide_api/src/display/function_signature.rs2
-rw-r--r--crates/ra_ide_api/src/display/navigation_target.rs8
-rw-r--r--crates/ra_ide_api/src/hover.rs12
10 files changed, 30 insertions, 28 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 {
diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/docs.rs
index 70b9d13b2..8d7a5255f 100644
--- a/crates/ra_hir/src/docs.rs
+++ b/crates/ra_hir/src/docs.rs
@@ -81,7 +81,7 @@ pub(crate) fn documentation_query(
81 DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).ast), 81 DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).ast),
82 DocDef::Static(it) => docs_from_ast(&*it.source(db).1), 82 DocDef::Static(it) => docs_from_ast(&*it.source(db).1),
83 DocDef::Const(it) => docs_from_ast(&*it.source(db).1), 83 DocDef::Const(it) => docs_from_ast(&*it.source(db).1),
84 DocDef::Function(it) => docs_from_ast(&*it.source(db).1), 84 DocDef::Function(it) => docs_from_ast(&*it.source(db).ast),
85 DocDef::Union(it) => docs_from_ast(&*it.source(db).1), 85 DocDef::Union(it) => docs_from_ast(&*it.source(db).1),
86 DocDef::Trait(it) => docs_from_ast(&*it.source(db).1), 86 DocDef::Trait(it) => docs_from_ast(&*it.source(db).1),
87 DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).1), 87 DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).1),
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index 012f374ec..46d51e0db 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -1023,9 +1023,9 @@ pub(crate) fn body_with_source_map_query(
1023 collector.collect_const_body(&src) 1023 collector.collect_const_body(&src)
1024 } 1024 }
1025 DefWithBody::Function(ref f) => { 1025 DefWithBody::Function(ref f) => {
1026 let (file_id, src) = f.source(db); 1026 let src = f.source(db);
1027 collector = ExprCollector::new(def, file_id, def.resolver(db), db); 1027 collector = ExprCollector::new(def, src.file_id, def.resolver(db), db);
1028 collector.collect_fn_body(&src) 1028 collector.collect_fn_body(&src.ast)
1029 } 1029 }
1030 DefWithBody::Static(ref s) => { 1030 DefWithBody::Static(ref s) => {
1031 let (file_id, src) = s.source(db); 1031 let (file_id, src) = s.source(db);
diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs
index a1b2641da..ff5e5f68e 100644
--- a/crates/ra_hir/src/expr/validation.rs
+++ b/crates/ra_hir/src/expr/validation.rs
@@ -71,7 +71,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
71 return; 71 return;
72 } 72 }
73 let source_map = self.func.body_source_map(db); 73 let source_map = self.func.body_source_map(db);
74 let file_id = self.func.source(db).0; 74 let file_id = self.func.source(db).file_id;
75 let source_file = db.parse(file_id.original_file(db)).tree; 75 let source_file = db.parse(file_id.original_file(db)).tree;
76 if let Some(field_list_node) = source_map 76 if let Some(field_list_node) = source_map
77 .expr_syntax(id) 77 .expr_syntax(id)
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index 2a92d5945..fcccd67c8 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -68,7 +68,7 @@ impl GenericParams {
68 generics.parent_params = parent.map(|p| db.generic_params(p)); 68 generics.parent_params = parent.map(|p| db.generic_params(p));
69 let start = generics.parent_params.as_ref().map(|p| p.params.len()).unwrap_or(0) as u32; 69 let start = generics.parent_params.as_ref().map(|p| p.params.len()).unwrap_or(0) as u32;
70 match def { 70 match def {
71 GenericDef::Function(it) => generics.fill(&*it.source(db).1, start), 71 GenericDef::Function(it) => generics.fill(&*it.source(db).ast, start),
72 GenericDef::Struct(it) => generics.fill(&*it.source(db).ast, start), 72 GenericDef::Struct(it) => generics.fill(&*it.source(db).ast, start),
73 GenericDef::Union(it) => generics.fill(&*it.source(db).1, start), 73 GenericDef::Union(it) => generics.fill(&*it.source(db).1, start),
74 GenericDef::Enum(it) => generics.fill(&*it.source(db).ast, start), 74 GenericDef::Enum(it) => generics.fill(&*it.source(db).ast, start),
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 6aa727ea1..a534c2336 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -1432,7 +1432,7 @@ mod diagnostics {
1432 ) { 1432 ) {
1433 match self { 1433 match self {
1434 InferenceDiagnostic::NoSuchField { expr, field } => { 1434 InferenceDiagnostic::NoSuchField { expr, field } => {
1435 let (file, _) = owner.source(db); 1435 let file = owner.source(db).file_id;
1436 let field = owner.body_source_map(db).field_syntax(*expr, *field); 1436 let field = owner.body_source_map(db).field_syntax(*expr, *field);
1437 sink.push(NoSuchField { file, field }) 1437 sink.push(NoSuchField { file, field })
1438 } 1438 }
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs
index d405161d6..e9ae20225 100644
--- a/crates/ra_ide_api/src/completion/presentation.rs
+++ b/crates/ra_ide_api/src/completion/presentation.rs
@@ -100,7 +100,7 @@ impl Completions {
100 ) { 100 ) {
101 let sig = func.signature(ctx.db); 101 let sig = func.signature(ctx.db);
102 let name = name.unwrap_or_else(|| sig.name().to_string()); 102 let name = name.unwrap_or_else(|| sig.name().to_string());
103 let (_, ast_node) = func.source(ctx.db); 103 let ast_node = func.source(ctx.db).ast;
104 let detail = function_label(&ast_node); 104 let detail = function_label(&ast_node);
105 105
106 let mut builder = CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name) 106 let mut builder = CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name)
diff --git a/crates/ra_ide_api/src/display/function_signature.rs b/crates/ra_ide_api/src/display/function_signature.rs
index d09950bce..d0c155de7 100644
--- a/crates/ra_ide_api/src/display/function_signature.rs
+++ b/crates/ra_ide_api/src/display/function_signature.rs
@@ -33,7 +33,7 @@ impl FunctionSignature {
33 33
34 pub(crate) fn from_hir(db: &db::RootDatabase, function: hir::Function) -> Self { 34 pub(crate) fn from_hir(db: &db::RootDatabase, function: hir::Function) -> Self {
35 let doc = function.docs(db); 35 let doc = function.docs(db);
36 let (_, ast_node) = function.source(db); 36 let ast_node = function.source(db).ast;
37 FunctionSignature::from(&*ast_node).with_doc_opt(doc) 37 FunctionSignature::from(&*ast_node).with_doc_opt(doc)
38 } 38 }
39} 39}
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs
index bef5f0980..3333771ab 100644
--- a/crates/ra_ide_api/src/display/navigation_target.rs
+++ b/crates/ra_ide_api/src/display/navigation_target.rs
@@ -164,13 +164,7 @@ impl NavigationTarget {
164 } 164 }
165 165
166 pub(crate) fn from_function(db: &RootDatabase, func: hir::Function) -> NavigationTarget { 166 pub(crate) fn from_function(db: &RootDatabase, func: hir::Function) -> NavigationTarget {
167 let (file_id, fn_def) = func.source(db); 167 NavigationTarget::from_def_source(db, func)
168 NavigationTarget::from_named(
169 file_id.original_file(db),
170 &*fn_def,
171 fn_def.doc_comment_text(),
172 fn_def.short_label(),
173 )
174 } 168 }
175 169
176 pub(crate) fn from_field(db: &RootDatabase, field: hir::StructField) -> NavigationTarget { 170 pub(crate) fn from_field(db: &RootDatabase, field: hir::StructField) -> NavigationTarget {
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index ee0f2dde8..4dd3c1b9f 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -96,8 +96,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
96 96
97 match classify_name_ref(db, &analyzer, name_ref) { 97 match classify_name_ref(db, &analyzer, name_ref) {
98 Some(Method(it)) => { 98 Some(Method(it)) => {
99 let it = it.source(db).1; 99 let src = it.source(db);
100 res.extend(hover_text(it.doc_comment_text(), it.short_label())); 100 res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label()));
101 } 101 }
102 Some(Macro(it)) => { 102 Some(Macro(it)) => {
103 let it = it.source(db).1; 103 let it = it.source(db).1;
@@ -111,8 +111,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
111 } 111 }
112 Some(AssocItem(it)) => match it { 112 Some(AssocItem(it)) => match it {
113 hir::ImplItem::Method(it) => { 113 hir::ImplItem::Method(it) => {
114 let it = it.source(db).1; 114 let src = it.source(db);
115 res.extend(hover_text(it.doc_comment_text(), it.short_label())) 115 res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label()))
116 } 116 }
117 hir::ImplItem::Const(it) => { 117 hir::ImplItem::Const(it) => {
118 let it = it.source(db).1; 118 let it = it.source(db).1;
@@ -132,8 +132,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
132 } 132 }
133 } 133 }
134 hir::ModuleDef::Function(it) => { 134 hir::ModuleDef::Function(it) => {
135 let it = it.source(db).1; 135 let src = it.source(db);
136 res.extend(hover_text(it.doc_comment_text(), it.short_label())) 136 res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label()))
137 } 137 }
138 hir::ModuleDef::Struct(it) => { 138 hir::ModuleDef::Struct(it) => {
139 let src = it.source(db); 139 let src = it.source(db);