aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/completion/completion_context.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-27 14:33:52 +0000
committerAleksey Kladov <[email protected]>2018-12-27 14:33:52 +0000
commite4de2c8d7f5ced7a24d0a76213ab113218c99d30 (patch)
treeb7e3edf5a0bebb168330ac56a261ed5b0a90d43e /crates/ra_analysis/src/completion/completion_context.rs
parent7a1ed6400dbc57656eebc345f7e2ffa963bf808e (diff)
add function to completion ctx
Diffstat (limited to 'crates/ra_analysis/src/completion/completion_context.rs')
-rw-r--r--crates/ra_analysis/src/completion/completion_context.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/crates/ra_analysis/src/completion/completion_context.rs b/crates/ra_analysis/src/completion/completion_context.rs
index 978772fd4..71bf7fd32 100644
--- a/crates/ra_analysis/src/completion/completion_context.rs
+++ b/crates/ra_analysis/src/completion/completion_context.rs
@@ -22,7 +22,8 @@ pub(super) struct CompletionContext<'a> {
22 pub(super) offset: TextUnit, 22 pub(super) offset: TextUnit,
23 pub(super) leaf: SyntaxNodeRef<'a>, 23 pub(super) leaf: SyntaxNodeRef<'a>,
24 pub(super) module: Option<hir::Module>, 24 pub(super) module: Option<hir::Module>,
25 pub(super) enclosing_fn: Option<ast::FnDef<'a>>, 25 pub(super) function: Option<hir::Function>,
26 pub(super) function_syntax: Option<ast::FnDef<'a>>,
26 pub(super) is_param: bool, 27 pub(super) is_param: bool,
27 /// A single-indent path, like `foo`. 28 /// A single-indent path, like `foo`.
28 pub(super) is_trivial_path: bool, 29 pub(super) is_trivial_path: bool,
@@ -52,7 +53,8 @@ impl<'a> CompletionContext<'a> {
52 leaf, 53 leaf,
53 offset: position.offset, 54 offset: position.offset,
54 module, 55 module,
55 enclosing_fn: None, 56 function: None,
57 function_syntax: None,
56 is_param: false, 58 is_param: false,
57 is_trivial_path: false, 59 is_trivial_path: false,
58 path_prefix: None, 60 path_prefix: None,
@@ -112,11 +114,18 @@ impl<'a> CompletionContext<'a> {
112 _ => (), 114 _ => (),
113 } 115 }
114 116
115 self.enclosing_fn = self 117 self.function_syntax = self
116 .leaf 118 .leaf
117 .ancestors() 119 .ancestors()
118 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) 120 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE)
119 .find_map(ast::FnDef::cast); 121 .find_map(ast::FnDef::cast);
122 match (&self.module, self.function_syntax) {
123 (Some(module), Some(fn_def)) => {
124 let function = source_binder::function_from_module(self.db, module, fn_def);
125 self.function = Some(function);
126 }
127 _ => (),
128 }
120 129
121 let parent = match name_ref.syntax().parent() { 130 let parent = match name_ref.syntax().parent() {
122 Some(it) => it, 131 Some(it) => it,