diff options
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 29 |
1 files changed, 6 insertions, 23 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 3f882a736..5f61bb589 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -2,7 +2,7 @@ use std::sync::Arc; | |||
2 | 2 | ||
3 | use relative_path::RelativePathBuf; | 3 | use relative_path::RelativePathBuf; |
4 | use ra_db::{CrateId, Cancelable, FileId}; | 4 | use ra_db::{CrateId, Cancelable, FileId}; |
5 | use ra_syntax::{ast, TreeArc, SyntaxNode, AstNode}; | 5 | use ra_syntax::{ast, TreeArc, SyntaxNode}; |
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | Name, DefId, Path, PerNs, ScopesWithSyntaxMapping, Ty, HirFileId, | 8 | Name, DefId, Path, PerNs, ScopesWithSyntaxMapping, Ty, HirFileId, |
@@ -12,6 +12,7 @@ use crate::{ | |||
12 | expr::BodySyntaxMapping, | 12 | expr::BodySyntaxMapping, |
13 | ty::InferenceResult, | 13 | ty::InferenceResult, |
14 | adt::VariantData, | 14 | adt::VariantData, |
15 | code_model_impl::def_id_to_ast, | ||
15 | }; | 16 | }; |
16 | 17 | ||
17 | /// hir::Crate describes a single crate. It's the main interface with which | 18 | /// hir::Crate describes a single crate. It's the main interface with which |
@@ -186,13 +187,7 @@ impl Struct { | |||
186 | &self, | 187 | &self, |
187 | db: &impl HirDatabase, | 188 | db: &impl HirDatabase, |
188 | ) -> Cancelable<(HirFileId, TreeArc<ast::StructDef>)> { | 189 | ) -> Cancelable<(HirFileId, TreeArc<ast::StructDef>)> { |
189 | let (file_id, syntax) = self.def_id.source(db); | 190 | Ok(def_id_to_ast(db, self.def_id)) |
190 | Ok(( | ||
191 | file_id, | ||
192 | ast::StructDef::cast(&syntax) | ||
193 | .expect("struct def should point to StructDef node") | ||
194 | .to_owned(), | ||
195 | )) | ||
196 | } | 191 | } |
197 | } | 192 | } |
198 | 193 | ||
@@ -219,13 +214,7 @@ impl Enum { | |||
219 | } | 214 | } |
220 | 215 | ||
221 | pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::EnumDef>)> { | 216 | pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::EnumDef>)> { |
222 | let (file_id, syntax) = self.def_id.source(db); | 217 | Ok(def_id_to_ast(db, self.def_id)) |
223 | Ok(( | ||
224 | file_id, | ||
225 | ast::EnumDef::cast(&syntax) | ||
226 | .expect("enum def should point to EnumDef node") | ||
227 | .to_owned(), | ||
228 | )) | ||
229 | } | 218 | } |
230 | } | 219 | } |
231 | 220 | ||
@@ -259,13 +248,7 @@ impl EnumVariant { | |||
259 | &self, | 248 | &self, |
260 | db: &impl HirDatabase, | 249 | db: &impl HirDatabase, |
261 | ) -> Cancelable<(HirFileId, TreeArc<ast::EnumVariant>)> { | 250 | ) -> Cancelable<(HirFileId, TreeArc<ast::EnumVariant>)> { |
262 | let (file_id, syntax) = self.def_id.source(db); | 251 | Ok(def_id_to_ast(db, self.def_id)) |
263 | Ok(( | ||
264 | file_id, | ||
265 | ast::EnumVariant::cast(&syntax) | ||
266 | .expect("variant def should point to EnumVariant node") | ||
267 | .to_owned(), | ||
268 | )) | ||
269 | } | 252 | } |
270 | } | 253 | } |
271 | 254 | ||
@@ -304,7 +287,7 @@ impl Function { | |||
304 | } | 287 | } |
305 | 288 | ||
306 | pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::FnDef>)> { | 289 | pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::FnDef>)> { |
307 | Ok(self.source_impl(db)) | 290 | Ok(def_id_to_ast(db, self.def_id)) |
308 | } | 291 | } |
309 | 292 | ||
310 | pub fn body_syntax_mapping(&self, db: &impl HirDatabase) -> Cancelable<Arc<BodySyntaxMapping>> { | 293 | pub fn body_syntax_mapping(&self, db: &impl HirDatabase) -> Cancelable<Arc<BodySyntaxMapping>> { |