diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-05 10:21:28 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-05 10:21:28 +0000 |
commit | d1b993c0aacb2a29fc87283a8b35fe1b4a542459 (patch) | |
tree | 615c68873a325a02be8e21e1bd4dcb9ce8ab6a1e /crates/ra_hir/src/function/mod.rs | |
parent | 7960c8b27681ebeb72d83930c4a2bbf43a982c52 (diff) | |
parent | db456749a85e87cdbe3f87b85bf44446d9d5694b (diff) |
Merge #255
255: Binders r=matklad a=matklad
Binding sources to hir is a fuzzy operation, so let's move it to a special enclave in the source code.
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/function/mod.rs')
-rw-r--r-- | crates/ra_hir/src/function/mod.rs | 52 |
1 files changed, 2 insertions, 50 deletions
diff --git a/crates/ra_hir/src/function/mod.rs b/crates/ra_hir/src/function/mod.rs index e00bca6e3..5187dc051 100644 --- a/crates/ra_hir/src/function/mod.rs +++ b/crates/ra_hir/src/function/mod.rs | |||
@@ -6,16 +6,11 @@ use std::{ | |||
6 | }; | 6 | }; |
7 | 7 | ||
8 | use ra_syntax::{ | 8 | use ra_syntax::{ |
9 | TextRange, TextUnit, SyntaxNodeRef, | 9 | TextRange, TextUnit, |
10 | ast::{self, AstNode, DocCommentsOwner, NameOwner}, | 10 | ast::{self, AstNode, DocCommentsOwner, NameOwner}, |
11 | }; | 11 | }; |
12 | use ra_db::FileId; | ||
13 | 12 | ||
14 | use crate::{ | 13 | use crate::{ DefId, HirDatabase }; |
15 | Cancelable, | ||
16 | DefLoc, DefKind, DefId, HirDatabase, SourceItemId, | ||
17 | Module, | ||
18 | }; | ||
19 | 14 | ||
20 | pub use self::scope::FnScopes; | 15 | pub use self::scope::FnScopes; |
21 | 16 | ||
@@ -32,49 +27,6 @@ impl Function { | |||
32 | Function { fn_id } | 27 | Function { fn_id } |
33 | } | 28 | } |
34 | 29 | ||
35 | pub fn guess_from_source( | ||
36 | db: &impl HirDatabase, | ||
37 | file_id: FileId, | ||
38 | fn_def: ast::FnDef, | ||
39 | ) -> Cancelable<Option<Function>> { | ||
40 | let module = ctry!(Module::guess_from_child_node(db, file_id, fn_def.syntax())?); | ||
41 | let file_items = db.file_items(file_id); | ||
42 | let item_id = file_items.id_of(fn_def.syntax()); | ||
43 | let source_item_id = SourceItemId { file_id, item_id }; | ||
44 | let def_loc = DefLoc { | ||
45 | kind: DefKind::Function, | ||
46 | source_root_id: module.source_root_id, | ||
47 | module_id: module.module_id, | ||
48 | source_item_id, | ||
49 | }; | ||
50 | Ok(Some(Function::new(def_loc.id(db)))) | ||
51 | } | ||
52 | |||
53 | pub fn guess_for_name_ref( | ||
54 | db: &impl HirDatabase, | ||
55 | file_id: FileId, | ||
56 | name_ref: ast::NameRef, | ||
57 | ) -> Cancelable<Option<Function>> { | ||
58 | Function::guess_for_node(db, file_id, name_ref.syntax()) | ||
59 | } | ||
60 | |||
61 | pub fn guess_for_bind_pat( | ||
62 | db: &impl HirDatabase, | ||
63 | file_id: FileId, | ||
64 | bind_pat: ast::BindPat, | ||
65 | ) -> Cancelable<Option<Function>> { | ||
66 | Function::guess_for_node(db, file_id, bind_pat.syntax()) | ||
67 | } | ||
68 | |||
69 | fn guess_for_node( | ||
70 | db: &impl HirDatabase, | ||
71 | file_id: FileId, | ||
72 | node: SyntaxNodeRef, | ||
73 | ) -> Cancelable<Option<Function>> { | ||
74 | let fn_def = ctry!(node.ancestors().find_map(ast::FnDef::cast)); | ||
75 | Function::guess_from_source(db, file_id, fn_def) | ||
76 | } | ||
77 | |||
78 | pub fn scope(&self, db: &impl HirDatabase) -> Arc<FnScopes> { | 30 | pub fn scope(&self, db: &impl HirDatabase) -> Arc<FnScopes> { |
79 | db.fn_scopes(self.fn_id) | 31 | db.fn_scopes(self.fn_id) |
80 | } | 32 | } |