aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_api.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-11 17:43:10 +0000
committerAleksey Kladov <[email protected]>2019-01-11 17:43:10 +0000
commit19136cde000c2c227e79bf44febde990fe265cb7 (patch)
tree59693dafb7c1f1104ab99a0d7b90d3fca4089cb2 /crates/ra_hir/src/code_model_api.rs
parent0f9c350812e37b3cf2a1fcfb3c60a78122d60bf7 (diff)
uncopypaste def sources
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r--crates/ra_hir/src/code_model_api.rs29
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
3use relative_path::RelativePathBuf; 3use relative_path::RelativePathBuf;
4use ra_db::{CrateId, Cancelable, FileId}; 4use ra_db::{CrateId, Cancelable, FileId};
5use ra_syntax::{ast, TreeArc, SyntaxNode, AstNode}; 5use ra_syntax::{ast, TreeArc, SyntaxNode};
6 6
7use crate::{ 7use 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>> {