diff options
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 34 | ||||
-rw-r--r-- | crates/ra_hir/src/docs.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/expr.rs | 12 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/presentation.rs | 3 | ||||
-rw-r--r-- | crates/ra_ide_api/src/display/navigation_target.rs | 32 | ||||
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 12 |
6 files changed, 41 insertions, 56 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index aa6eb741b..a8a0875e0 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -761,12 +761,17 @@ pub struct Const { | |||
761 | pub(crate) id: ConstId, | 761 | pub(crate) id: ConstId, |
762 | } | 762 | } |
763 | 763 | ||
764 | impl HasSource for Const { | ||
765 | type Ast = TreeArc<ast::ConstDef>; | ||
766 | |||
767 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ConstDef>> { | ||
768 | self.id.source(db).into() | ||
769 | } | ||
770 | } | ||
771 | |||
764 | impl Const { | 772 | impl Const { |
765 | pub fn source( | 773 | pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::ConstDef>> { |
766 | self, | 774 | self.id.source(db).into() |
767 | db: &(impl DefDatabase + AstDatabase), | ||
768 | ) -> (HirFileId, TreeArc<ast::ConstDef>) { | ||
769 | self.id.source(db) | ||
770 | } | 775 | } |
771 | 776 | ||
772 | pub fn module(self, db: &impl DefDatabase) -> Module { | 777 | pub fn module(self, db: &impl DefDatabase) -> Module { |
@@ -819,7 +824,7 @@ impl ConstSignature { | |||
819 | db: &(impl DefDatabase + AstDatabase), | 824 | db: &(impl DefDatabase + AstDatabase), |
820 | konst: Const, | 825 | konst: Const, |
821 | ) -> Arc<ConstSignature> { | 826 | ) -> Arc<ConstSignature> { |
822 | let (_, node) = konst.source(db); | 827 | let node = konst.source(db).ast; |
823 | const_signature_for(&*node) | 828 | const_signature_for(&*node) |
824 | } | 829 | } |
825 | 830 | ||
@@ -827,7 +832,7 @@ impl ConstSignature { | |||
827 | db: &(impl DefDatabase + AstDatabase), | 832 | db: &(impl DefDatabase + AstDatabase), |
828 | konst: Static, | 833 | konst: Static, |
829 | ) -> Arc<ConstSignature> { | 834 | ) -> Arc<ConstSignature> { |
830 | let (_, node) = konst.source(db); | 835 | let node = konst.source(db).ast; |
831 | const_signature_for(&*node) | 836 | const_signature_for(&*node) |
832 | } | 837 | } |
833 | } | 838 | } |
@@ -844,12 +849,17 @@ pub struct Static { | |||
844 | pub(crate) id: StaticId, | 849 | pub(crate) id: StaticId, |
845 | } | 850 | } |
846 | 851 | ||
852 | impl HasSource for Static { | ||
853 | type Ast = TreeArc<ast::StaticDef>; | ||
854 | |||
855 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StaticDef>> { | ||
856 | self.id.source(db).into() | ||
857 | } | ||
858 | } | ||
859 | |||
847 | impl Static { | 860 | impl Static { |
848 | pub fn source( | 861 | pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StaticDef>> { |
849 | self, | 862 | self.id.source(db).into() |
850 | db: &(impl DefDatabase + AstDatabase), | ||
851 | ) -> (HirFileId, TreeArc<ast::StaticDef>) { | ||
852 | self.id.source(db) | ||
853 | } | 863 | } |
854 | 864 | ||
855 | pub fn module(self, db: &impl DefDatabase) -> Module { | 865 | 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 8d7a5255f..86ca981f4 100644 --- a/crates/ra_hir/src/docs.rs +++ b/crates/ra_hir/src/docs.rs | |||
@@ -79,8 +79,8 @@ pub(crate) fn documentation_query( | |||
79 | DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast), | 79 | DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast), |
80 | DocDef::Enum(it) => docs_from_ast(&*it.source(db).ast), | 80 | DocDef::Enum(it) => docs_from_ast(&*it.source(db).ast), |
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).ast), |
83 | DocDef::Const(it) => docs_from_ast(&*it.source(db).1), | 83 | DocDef::Const(it) => docs_from_ast(&*it.source(db).ast), |
84 | DocDef::Function(it) => docs_from_ast(&*it.source(db).ast), | 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), |
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 46d51e0db..48e597519 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -1018,9 +1018,9 @@ pub(crate) fn body_with_source_map_query( | |||
1018 | 1018 | ||
1019 | match def { | 1019 | match def { |
1020 | DefWithBody::Const(ref c) => { | 1020 | DefWithBody::Const(ref c) => { |
1021 | let (file_id, src) = c.source(db); | 1021 | let src = c.source(db); |
1022 | collector = ExprCollector::new(def, file_id, def.resolver(db), db); | 1022 | collector = ExprCollector::new(def, src.file_id, def.resolver(db), db); |
1023 | collector.collect_const_body(&src) | 1023 | collector.collect_const_body(&src.ast) |
1024 | } | 1024 | } |
1025 | DefWithBody::Function(ref f) => { | 1025 | DefWithBody::Function(ref f) => { |
1026 | let src = f.source(db); | 1026 | let src = f.source(db); |
@@ -1028,9 +1028,9 @@ pub(crate) fn body_with_source_map_query( | |||
1028 | collector.collect_fn_body(&src.ast) | 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 src = s.source(db); |
1032 | collector = ExprCollector::new(def, file_id, def.resolver(db), db); | 1032 | collector = ExprCollector::new(def, src.file_id, def.resolver(db), db); |
1033 | collector.collect_static_body(&src) | 1033 | collector.collect_static_body(&src.ast) |
1034 | } | 1034 | } |
1035 | } | 1035 | } |
1036 | 1036 | ||
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index e9ae20225..8c4d7127b 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -126,12 +126,11 @@ impl Completions { | |||
126 | } | 126 | } |
127 | 127 | ||
128 | pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) { | 128 | pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) { |
129 | let (_file_id, ast_node) = constant.source(ctx.db); | 129 | let ast_node = constant.source(ctx.db).ast; |
130 | let name = match ast_node.name() { | 130 | let name = match ast_node.name() { |
131 | Some(name) => name, | 131 | Some(name) => name, |
132 | _ => return, | 132 | _ => return, |
133 | }; | 133 | }; |
134 | let (_, ast_node) = constant.source(ctx.db); | ||
135 | let detail = const_label(&ast_node); | 134 | let detail = const_label(&ast_node); |
136 | 135 | ||
137 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string()) | 136 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string()) |
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index 3333771ab..a036a3b36 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs | |||
@@ -212,24 +212,8 @@ impl NavigationTarget { | |||
212 | hir::ModuleDef::Struct(it) => NavigationTarget::from_adt_def(db, it.into()), | 212 | hir::ModuleDef::Struct(it) => NavigationTarget::from_adt_def(db, it.into()), |
213 | hir::ModuleDef::Enum(it) => NavigationTarget::from_adt_def(db, it.into()), | 213 | hir::ModuleDef::Enum(it) => NavigationTarget::from_adt_def(db, it.into()), |
214 | hir::ModuleDef::Union(it) => NavigationTarget::from_adt_def(db, it.into()), | 214 | hir::ModuleDef::Union(it) => NavigationTarget::from_adt_def(db, it.into()), |
215 | hir::ModuleDef::Const(s) => { | 215 | hir::ModuleDef::Const(it) => NavigationTarget::from_def_source(db, it), |
216 | let (file_id, node) = s.source(db); | 216 | hir::ModuleDef::Static(it) => NavigationTarget::from_def_source(db, it), |
217 | NavigationTarget::from_named( | ||
218 | file_id.original_file(db), | ||
219 | &*node, | ||
220 | node.doc_comment_text(), | ||
221 | node.short_label(), | ||
222 | ) | ||
223 | } | ||
224 | hir::ModuleDef::Static(s) => { | ||
225 | let (file_id, node) = s.source(db); | ||
226 | NavigationTarget::from_named( | ||
227 | file_id.original_file(db), | ||
228 | &*node, | ||
229 | node.doc_comment_text(), | ||
230 | node.short_label(), | ||
231 | ) | ||
232 | } | ||
233 | hir::ModuleDef::EnumVariant(var) => { | 217 | hir::ModuleDef::EnumVariant(var) => { |
234 | let src = var.source(db); | 218 | let src = var.source(db); |
235 | NavigationTarget::from_named( | 219 | NavigationTarget::from_named( |
@@ -281,16 +265,8 @@ impl NavigationTarget { | |||
281 | 265 | ||
282 | pub(crate) fn from_impl_item(db: &RootDatabase, impl_item: hir::ImplItem) -> NavigationTarget { | 266 | pub(crate) fn from_impl_item(db: &RootDatabase, impl_item: hir::ImplItem) -> NavigationTarget { |
283 | match impl_item { | 267 | match impl_item { |
284 | ImplItem::Method(f) => NavigationTarget::from_function(db, f), | 268 | ImplItem::Method(it) => NavigationTarget::from_function(db, it), |
285 | ImplItem::Const(c) => { | 269 | ImplItem::Const(it) => NavigationTarget::from_def_source(db, it), |
286 | let (file_id, node) = c.source(db); | ||
287 | NavigationTarget::from_named( | ||
288 | file_id.original_file(db), | ||
289 | &*node, | ||
290 | node.doc_comment_text(), | ||
291 | node.short_label(), | ||
292 | ) | ||
293 | } | ||
294 | ImplItem::TypeAlias(a) => { | 270 | ImplItem::TypeAlias(a) => { |
295 | let (file_id, node) = a.source(db); | 271 | let (file_id, node) = a.source(db); |
296 | NavigationTarget::from_named( | 272 | NavigationTarget::from_named( |
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 4dd3c1b9f..fe108a589 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -115,8 +115,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
115 | res.extend(hover_text(src.ast.doc_comment_text(), src.ast.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 src = it.source(db); |
119 | res.extend(hover_text(it.doc_comment_text(), it.short_label())) | 119 | res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) |
120 | } | 120 | } |
121 | hir::ImplItem::TypeAlias(it) => { | 121 | hir::ImplItem::TypeAlias(it) => { |
122 | let it = it.source(db).1; | 122 | let it = it.source(db).1; |
@@ -152,12 +152,12 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
152 | res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) | 152 | res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) |
153 | } | 153 | } |
154 | hir::ModuleDef::Const(it) => { | 154 | hir::ModuleDef::Const(it) => { |
155 | let it = it.source(db).1; | 155 | let src = it.source(db); |
156 | res.extend(hover_text(it.doc_comment_text(), it.short_label())) | 156 | res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) |
157 | } | 157 | } |
158 | hir::ModuleDef::Static(it) => { | 158 | hir::ModuleDef::Static(it) => { |
159 | let it = it.source(db).1; | 159 | let src = it.source(db); |
160 | res.extend(hover_text(it.doc_comment_text(), it.short_label())) | 160 | res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) |
161 | } | 161 | } |
162 | hir::ModuleDef::Trait(it) => { | 162 | hir::ModuleDef::Trait(it) => { |
163 | let it = it.source(db).1; | 163 | let it = it.source(db).1; |