diff options
-rw-r--r-- | crates/ra_hir/src/adt.rs | 9 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 18 | ||||
-rw-r--r-- | crates/ra_hir/src/docs.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/generics.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/display/navigation_target.rs | 20 | ||||
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 11 |
6 files changed, 36 insertions, 26 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index 38ff1d6f6..36679e99b 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs | |||
@@ -59,8 +59,8 @@ impl StructData { | |||
59 | db: &(impl DefDatabase + AstDatabase), | 59 | db: &(impl DefDatabase + AstDatabase), |
60 | struct_: Struct, | 60 | struct_: Struct, |
61 | ) -> Arc<StructData> { | 61 | ) -> Arc<StructData> { |
62 | let (_, struct_def) = struct_.source(db); | 62 | let src = struct_.source(db); |
63 | Arc::new(StructData::new(&*struct_def)) | 63 | Arc::new(StructData::new(&*src.ast)) |
64 | } | 64 | } |
65 | } | 65 | } |
66 | 66 | ||
@@ -211,9 +211,8 @@ impl StructField { | |||
211 | let es; | 211 | let es; |
212 | let (file_id, struct_kind) = match self.parent { | 212 | let (file_id, struct_kind) = match self.parent { |
213 | VariantDef::Struct(s) => { | 213 | VariantDef::Struct(s) => { |
214 | let (file_id, source) = s.source(db); | 214 | ss = s.source(db); |
215 | ss = source; | 215 | (ss.file_id, ss.ast.kind()) |
216 | (file_id, ss.kind()) | ||
217 | } | 216 | } |
218 | VariantDef::EnumVariant(e) => { | 217 | VariantDef::EnumVariant(e) => { |
219 | let (file_id, source) = e.source(db); | 218 | let (file_id, source) = e.source(db); |
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 27850028b..3469da18a 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -20,6 +20,17 @@ use crate::{ | |||
20 | type_ref::Mutability, | 20 | type_ref::Mutability, |
21 | }; | 21 | }; |
22 | 22 | ||
23 | pub struct Source<T> { | ||
24 | pub file_id: HirFileId, | ||
25 | pub ast: T, | ||
26 | } | ||
27 | |||
28 | impl<T> From<(HirFileId, T)> for Source<T> { | ||
29 | fn from((file_id, ast): (HirFileId, T)) -> Self { | ||
30 | Source { file_id, ast } | ||
31 | } | ||
32 | } | ||
33 | |||
23 | /// hir::Crate describes a single crate. It's the main interface with which | 34 | /// hir::Crate describes a single crate. It's the main interface with which |
24 | /// a crate's dependencies interact. Mostly, it should be just a proxy for the | 35 | /// a crate's dependencies interact. Mostly, it should be just a proxy for the |
25 | /// root module. | 36 | /// root module. |
@@ -354,11 +365,8 @@ pub struct Struct { | |||
354 | } | 365 | } |
355 | 366 | ||
356 | impl Struct { | 367 | impl Struct { |
357 | pub fn source( | 368 | pub fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::StructDef>> { |
358 | self, | 369 | self.id.source(db).into() |
359 | db: &(impl DefDatabase + AstDatabase), | ||
360 | ) -> (HirFileId, TreeArc<ast::StructDef>) { | ||
361 | self.id.source(db) | ||
362 | } | 370 | } |
363 | 371 | ||
364 | pub fn module(self, db: &impl HirDatabase) -> Module { | 372 | pub fn module(self, db: &impl HirDatabase) -> Module { |
diff --git a/crates/ra_hir/src/docs.rs b/crates/ra_hir/src/docs.rs index 1b0f84de5..edd937901 100644 --- a/crates/ra_hir/src/docs.rs +++ b/crates/ra_hir/src/docs.rs | |||
@@ -76,7 +76,7 @@ pub(crate) fn documentation_query( | |||
76 | FieldSource::Named(named) => docs_from_ast(&*named), | 76 | FieldSource::Named(named) => docs_from_ast(&*named), |
77 | FieldSource::Pos(..) => return None, | 77 | FieldSource::Pos(..) => return None, |
78 | }, | 78 | }, |
79 | DocDef::Struct(it) => docs_from_ast(&*it.source(db).1), | 79 | DocDef::Struct(it) => docs_from_ast(&*it.source(db).ast), |
80 | DocDef::Enum(it) => docs_from_ast(&*it.source(db).1), | 80 | DocDef::Enum(it) => docs_from_ast(&*it.source(db).1), |
81 | DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).1), | 81 | DocDef::EnumVariant(it) => docs_from_ast(&*it.source(db).1), |
82 | DocDef::Static(it) => docs_from_ast(&*it.source(db).1), | 82 | DocDef::Static(it) => docs_from_ast(&*it.source(db).1), |
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index b6c5e18d3..294a00721 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs | |||
@@ -69,7 +69,7 @@ impl GenericParams { | |||
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).1, start), |
72 | GenericDef::Struct(it) => generics.fill(&*it.source(db).1, 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).1, start), | 74 | GenericDef::Enum(it) => generics.fill(&*it.source(db).1, start), |
75 | GenericDef::Trait(it) => { | 75 | GenericDef::Trait(it) => { |
diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index cfd3f5478..c02bc005b 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs | |||
@@ -189,12 +189,12 @@ impl NavigationTarget { | |||
189 | pub(crate) fn from_adt_def(db: &RootDatabase, adt_def: hir::AdtDef) -> NavigationTarget { | 189 | pub(crate) fn from_adt_def(db: &RootDatabase, adt_def: hir::AdtDef) -> NavigationTarget { |
190 | match adt_def { | 190 | match adt_def { |
191 | hir::AdtDef::Struct(s) => { | 191 | hir::AdtDef::Struct(s) => { |
192 | let (file_id, node) = s.source(db); | 192 | let src = s.source(db); |
193 | NavigationTarget::from_named( | 193 | NavigationTarget::from_named( |
194 | file_id.original_file(db), | 194 | src.file_id.original_file(db), |
195 | &*node, | 195 | &*src.ast, |
196 | node.doc_comment_text(), | 196 | src.ast.doc_comment_text(), |
197 | node.short_label(), | 197 | src.ast.short_label(), |
198 | ) | 198 | ) |
199 | } | 199 | } |
200 | hir::AdtDef::Union(s) => { | 200 | hir::AdtDef::Union(s) => { |
@@ -226,12 +226,12 @@ impl NavigationTarget { | |||
226 | hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module), | 226 | hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module), |
227 | hir::ModuleDef::Function(func) => NavigationTarget::from_function(db, func), | 227 | hir::ModuleDef::Function(func) => NavigationTarget::from_function(db, func), |
228 | hir::ModuleDef::Struct(s) => { | 228 | hir::ModuleDef::Struct(s) => { |
229 | let (file_id, node) = s.source(db); | 229 | let src = s.source(db); |
230 | NavigationTarget::from_named( | 230 | NavigationTarget::from_named( |
231 | file_id.original_file(db), | 231 | src.file_id.original_file(db), |
232 | &*node, | 232 | &*src.ast, |
233 | node.doc_comment_text(), | 233 | src.ast.doc_comment_text(), |
234 | node.short_label(), | 234 | src.ast.short_label(), |
235 | ) | 235 | ) |
236 | } | 236 | } |
237 | hir::ModuleDef::Union(s) => { | 237 | hir::ModuleDef::Union(s) => { |
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index fbabeb194..80445761c 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -136,8 +136,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
136 | res.extend(hover_text(it.doc_comment_text(), it.short_label())) | 136 | res.extend(hover_text(it.doc_comment_text(), it.short_label())) |
137 | } | 137 | } |
138 | hir::ModuleDef::Struct(it) => { | 138 | hir::ModuleDef::Struct(it) => { |
139 | let it = it.source(db).1; | 139 | let src = it.source(db); |
140 | res.extend(hover_text(it.doc_comment_text(), it.short_label())) | 140 | res.extend(hover_text(src.ast.doc_comment_text(), src.ast.short_label())) |
141 | } | 141 | } |
142 | hir::ModuleDef::Union(it) => { | 142 | hir::ModuleDef::Union(it) => { |
143 | let it = it.source(db).1; | 143 | let it = it.source(db).1; |
@@ -176,8 +176,11 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn | |||
176 | if let Some((adt_def, _)) = ty.as_adt() { | 176 | if let Some((adt_def, _)) = ty.as_adt() { |
177 | match adt_def { | 177 | match adt_def { |
178 | hir::AdtDef::Struct(it) => { | 178 | hir::AdtDef::Struct(it) => { |
179 | let it = it.source(db).1; | 179 | let src = it.source(db); |
180 | res.extend(hover_text(it.doc_comment_text(), it.short_label())) | 180 | res.extend(hover_text( |
181 | src.ast.doc_comment_text(), | ||
182 | src.ast.short_label(), | ||
183 | )) | ||
181 | } | 184 | } |
182 | hir::AdtDef::Union(it) => { | 185 | hir::AdtDef::Union(it) => { |
183 | let it = it.source(db).1; | 186 | let it = it.source(db).1; |