aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_impl
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_impl
parent0f9c350812e37b3cf2a1fcfb3c60a78122d60bf7 (diff)
uncopypaste def sources
Diffstat (limited to 'crates/ra_hir/src/code_model_impl')
-rw-r--r--crates/ra_hir/src/code_model_impl/function.rs22
1 files changed, 5 insertions, 17 deletions
diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs
index daf49e791..1ce939e05 100644
--- a/crates/ra_hir/src/code_model_impl/function.rs
+++ b/crates/ra_hir/src/code_model_impl/function.rs
@@ -3,16 +3,14 @@ mod scope;
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use ra_db::Cancelable; 5use ra_db::Cancelable;
6use ra_syntax::{ 6use ra_syntax::{TreeArc, ast::{self, NameOwner}};
7 TreeArc,
8 ast::{self, AstNode, NameOwner},
9};
10 7
11use crate::{ 8use crate::{
12 DefId, DefKind, HirDatabase, Name, AsName, Function, FnSignature, Module, HirFileId, 9 DefId, HirDatabase, Name, AsName, Function, FnSignature, Module,
13 type_ref::{TypeRef, Mutability}, 10 type_ref::{TypeRef, Mutability},
14 expr::Body, 11 expr::Body,
15 impl_block::ImplBlock, 12 impl_block::ImplBlock,
13 code_model_impl::def_id_to_ast,
16}; 14};
17 15
18pub use self::scope::{FnScopes, ScopesWithSyntaxMapping, ScopeEntryWithSyntax}; 16pub use self::scope::{FnScopes, ScopesWithSyntaxMapping, ScopeEntryWithSyntax};
@@ -22,16 +20,6 @@ impl Function {
22 Function { def_id } 20 Function { def_id }
23 } 21 }
24 22
25 pub(crate) fn source_impl(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::FnDef>) {
26 let def_loc = self.def_id.loc(db);
27 assert!(def_loc.kind == DefKind::Function);
28 let syntax = db.file_item(def_loc.source_item_id);
29 (
30 def_loc.source_item_id.file_id,
31 ast::FnDef::cast(&syntax).unwrap().to_owned(),
32 )
33 }
34
35 pub(crate) fn body(&self, db: &impl HirDatabase) -> Cancelable<Arc<Body>> { 23 pub(crate) fn body(&self, db: &impl HirDatabase) -> Cancelable<Arc<Body>> {
36 db.body_hir(self.def_id) 24 db.body_hir(self.def_id)
37 } 25 }
@@ -48,8 +36,8 @@ impl Function {
48 36
49impl FnSignature { 37impl FnSignature {
50 pub(crate) fn fn_signature_query(db: &impl HirDatabase, def_id: DefId) -> Arc<FnSignature> { 38 pub(crate) fn fn_signature_query(db: &impl HirDatabase, def_id: DefId) -> Arc<FnSignature> {
51 let func = Function::new(def_id); 39 // FIXME: we're using def_id_to_ast here to avoid returning Cancelable... this is a bit hacky
52 let node = func.source_impl(db).1; // TODO we're using source_impl here to avoid returning Cancelable... this is a bit hacky 40 let node: TreeArc<ast::FnDef> = def_id_to_ast(db, def_id).1;
53 let name = node 41 let name = node
54 .name() 42 .name()
55 .map(|n| n.as_name()) 43 .map(|n| n.as_name())