diff options
author | Aleksey Kladov <[email protected]> | 2019-01-11 17:43:10 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-11 17:43:10 +0000 |
commit | 19136cde000c2c227e79bf44febde990fe265cb7 (patch) | |
tree | 59693dafb7c1f1104ab99a0d7b90d3fca4089cb2 /crates/ra_hir/src/code_model_impl/function.rs | |
parent | 0f9c350812e37b3cf2a1fcfb3c60a78122d60bf7 (diff) |
uncopypaste def sources
Diffstat (limited to 'crates/ra_hir/src/code_model_impl/function.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_impl/function.rs | 22 |
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; | |||
3 | use std::sync::Arc; | 3 | use std::sync::Arc; |
4 | 4 | ||
5 | use ra_db::Cancelable; | 5 | use ra_db::Cancelable; |
6 | use ra_syntax::{ | 6 | use ra_syntax::{TreeArc, ast::{self, NameOwner}}; |
7 | TreeArc, | ||
8 | ast::{self, AstNode, NameOwner}, | ||
9 | }; | ||
10 | 7 | ||
11 | use crate::{ | 8 | use 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 | ||
18 | pub use self::scope::{FnScopes, ScopesWithSyntaxMapping, ScopeEntryWithSyntax}; | 16 | pub 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 | ||
49 | impl FnSignature { | 37 | impl 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()) |