diff options
Diffstat (limited to 'crates/ra_analysis/src/hir/function/mod.rs')
-rw-r--r-- | crates/ra_analysis/src/hir/function/mod.rs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/crates/ra_analysis/src/hir/function/mod.rs b/crates/ra_analysis/src/hir/function/mod.rs index 5e44a88a7..d171b6a8d 100644 --- a/crates/ra_analysis/src/hir/function/mod.rs +++ b/crates/ra_analysis/src/hir/function/mod.rs | |||
@@ -6,8 +6,8 @@ use std::{ | |||
6 | }; | 6 | }; |
7 | 7 | ||
8 | use ra_syntax::{ | 8 | use ra_syntax::{ |
9 | TextRange, TextUnit, SyntaxNodeRef, | ||
9 | ast::{self, AstNode, DocCommentsOwner, NameOwner}, | 10 | ast::{self, AstNode, DocCommentsOwner, NameOwner}, |
10 | TextRange, TextUnit, | ||
11 | }; | 11 | }; |
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
@@ -39,6 +39,32 @@ impl FunctionDescriptor { | |||
39 | FunctionDescriptor { fn_id } | 39 | FunctionDescriptor { fn_id } |
40 | } | 40 | } |
41 | 41 | ||
42 | pub(crate) fn guess_for_name_ref( | ||
43 | db: &impl HirDatabase, | ||
44 | file_id: FileId, | ||
45 | name_ref: ast::NameRef, | ||
46 | ) -> Option<FunctionDescriptor> { | ||
47 | FunctionDescriptor::guess_for_node(db, file_id, name_ref.syntax()) | ||
48 | } | ||
49 | |||
50 | pub(crate) fn guess_for_bind_pat( | ||
51 | db: &impl HirDatabase, | ||
52 | file_id: FileId, | ||
53 | bind_pat: ast::BindPat, | ||
54 | ) -> Option<FunctionDescriptor> { | ||
55 | FunctionDescriptor::guess_for_node(db, file_id, bind_pat.syntax()) | ||
56 | } | ||
57 | |||
58 | fn guess_for_node( | ||
59 | db: &impl HirDatabase, | ||
60 | file_id: FileId, | ||
61 | node: SyntaxNodeRef, | ||
62 | ) -> Option<FunctionDescriptor> { | ||
63 | let fn_def = node.ancestors().find_map(ast::FnDef::cast)?; | ||
64 | let res = FunctionDescriptor::guess_from_source(db, file_id, fn_def); | ||
65 | Some(res) | ||
66 | } | ||
67 | |||
42 | pub(crate) fn scope(&self, db: &impl HirDatabase) -> Arc<FnScopes> { | 68 | pub(crate) fn scope(&self, db: &impl HirDatabase) -> Arc<FnScopes> { |
43 | db.fn_scopes(self.fn_id) | 69 | db.fn_scopes(self.fn_id) |
44 | } | 70 | } |