aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/function
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-05 10:16:20 +0000
committerAleksey Kladov <[email protected]>2018-12-05 10:16:20 +0000
commit4344264024d374bb9cdc6f388f13c90b48c6c22e (patch)
tree52913fe6fe5127d4c4f1d0dd7b412ed0df03245a /crates/ra_hir/src/function
parent7960c8b27681ebeb72d83930c4a2bbf43a982c52 (diff)
move fuzzy source binding to a separete mode
Diffstat (limited to 'crates/ra_hir/src/function')
-rw-r--r--crates/ra_hir/src/function/mod.rs52
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
8use ra_syntax::{ 8use ra_syntax::{
9 TextRange, TextUnit, SyntaxNodeRef, 9 TextRange, TextUnit,
10 ast::{self, AstNode, DocCommentsOwner, NameOwner}, 10 ast::{self, AstNode, DocCommentsOwner, NameOwner},
11}; 11};
12use ra_db::FileId;
13 12
14use crate::{ 13use crate::{ DefId, HirDatabase };
15 Cancelable,
16 DefLoc, DefKind, DefId, HirDatabase, SourceItemId,
17 Module,
18};
19 14
20pub use self::scope::FnScopes; 15pub 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 }