aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/completion/complete_dot.rs17
-rw-r--r--crates/ra_analysis/src/completion/complete_keyword.rs2
-rw-r--r--crates/ra_analysis/src/completion/complete_scope.rs3
-rw-r--r--crates/ra_analysis/src/completion/complete_snippet.rs2
-rw-r--r--crates/ra_analysis/src/completion/completion_context.rs15
5 files changed, 18 insertions, 21 deletions
diff --git a/crates/ra_analysis/src/completion/complete_dot.rs b/crates/ra_analysis/src/completion/complete_dot.rs
index 93d657576..f24835d17 100644
--- a/crates/ra_analysis/src/completion/complete_dot.rs
+++ b/crates/ra_analysis/src/completion/complete_dot.rs
@@ -6,20 +6,9 @@ use crate::completion::{CompletionContext, Completions, CompletionKind, Completi
6 6
7/// Complete dot accesses, i.e. fields or methods (currently only fields). 7/// Complete dot accesses, i.e. fields or methods (currently only fields).
8pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> { 8pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> {
9 let module = if let Some(module) = &ctx.module { 9 let (function, receiver) = match (&ctx.function, ctx.dot_receiver) {
10 module 10 (Some(function), Some(receiver)) => (function, receiver),
11 } else { 11 _ => return Ok(()),
12 return Ok(());
13 };
14 let function = if let Some(fn_def) = ctx.enclosing_fn {
15 hir::source_binder::function_from_module(ctx.db, module, fn_def)
16 } else {
17 return Ok(());
18 };
19 let receiver = if let Some(receiver) = ctx.dot_receiver {
20 receiver
21 } else {
22 return Ok(());
23 }; 12 };
24 let infer_result = function.infer(ctx.db)?; 13 let infer_result = function.infer(ctx.db)?;
25 let receiver_ty = if let Some(ty) = infer_result.type_of_node(receiver.syntax()) { 14 let receiver_ty = if let Some(ty) = infer_result.type_of_node(receiver.syntax()) {
diff --git a/crates/ra_analysis/src/completion/complete_keyword.rs b/crates/ra_analysis/src/completion/complete_keyword.rs
index 5427fcb11..d1e0a20a8 100644
--- a/crates/ra_analysis/src/completion/complete_keyword.rs
+++ b/crates/ra_analysis/src/completion/complete_keyword.rs
@@ -18,7 +18,7 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
18 if !ctx.is_trivial_path { 18 if !ctx.is_trivial_path {
19 return; 19 return;
20 } 20 }
21 let fn_def = match ctx.enclosing_fn { 21 let fn_def = match ctx.function_syntax {
22 Some(it) => it, 22 Some(it) => it,
23 None => return, 23 None => return,
24 }; 24 };
diff --git a/crates/ra_analysis/src/completion/complete_scope.rs b/crates/ra_analysis/src/completion/complete_scope.rs
index a57670e3b..514fd2f88 100644
--- a/crates/ra_analysis/src/completion/complete_scope.rs
+++ b/crates/ra_analysis/src/completion/complete_scope.rs
@@ -14,8 +14,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) ->
14 Some(it) => it, 14 Some(it) => it,
15 None => return Ok(()), 15 None => return Ok(()),
16 }; 16 };
17 if let Some(fn_def) = ctx.enclosing_fn { 17 if let Some(function) = &ctx.function {
18 let function = hir::source_binder::function_from_module(ctx.db, module, fn_def);
19 let scopes = function.scopes(ctx.db); 18 let scopes = function.scopes(ctx.db);
20 complete_fn(acc, &scopes, ctx.offset); 19 complete_fn(acc, &scopes, ctx.offset);
21 } 20 }
diff --git a/crates/ra_analysis/src/completion/complete_snippet.rs b/crates/ra_analysis/src/completion/complete_snippet.rs
index fb9da0a4f..a495751dd 100644
--- a/crates/ra_analysis/src/completion/complete_snippet.rs
+++ b/crates/ra_analysis/src/completion/complete_snippet.rs
@@ -7,7 +7,7 @@ fn snippet(label: &str, snippet: &str) -> Builder {
7} 7}
8 8
9pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) { 9pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) {
10 if !(ctx.is_trivial_path && ctx.enclosing_fn.is_some()) { 10 if !(ctx.is_trivial_path && ctx.function_syntax.is_some()) {
11 return; 11 return;
12 } 12 }
13 snippet("pd", "eprintln!(\"$0 = {:?}\", $0);").add_to(acc); 13 snippet("pd", "eprintln!(\"$0 = {:?}\", $0);").add_to(acc);
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,