aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/completion/completion_context.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/completion/completion_context.rs')
-rw-r--r--crates/ra_analysis/src/completion/completion_context.rs34
1 files changed, 29 insertions, 5 deletions
diff --git a/crates/ra_analysis/src/completion/completion_context.rs b/crates/ra_analysis/src/completion/completion_context.rs
index 064fbc6f7..12e98e870 100644
--- a/crates/ra_analysis/src/completion/completion_context.rs
+++ b/crates/ra_analysis/src/completion/completion_context.rs
@@ -31,6 +31,10 @@ pub(super) struct CompletionContext<'a> {
31 pub(super) is_stmt: bool, 31 pub(super) is_stmt: bool,
32 /// Something is typed at the "top" level, in module or impl/trait. 32 /// Something is typed at the "top" level, in module or impl/trait.
33 pub(super) is_new_item: bool, 33 pub(super) is_new_item: bool,
34 /// The receiver if this is a field or method access, i.e. writing something.<|>
35 pub(super) dot_receiver: Option<ast::Expr<'a>>,
36 /// If this is a method call in particular, i.e. the () are already there.
37 pub(super) is_method_call: bool,
34} 38}
35 39
36impl<'a> CompletionContext<'a> { 40impl<'a> CompletionContext<'a> {
@@ -54,6 +58,8 @@ impl<'a> CompletionContext<'a> {
54 after_if: false, 58 after_if: false,
55 is_stmt: false, 59 is_stmt: false,
56 is_new_item: false, 60 is_new_item: false,
61 dot_receiver: None,
62 is_method_call: false,
57 }; 63 };
58 ctx.fill(original_file, position.offset); 64 ctx.fill(original_file, position.offset);
59 Ok(Some(ctx)) 65 Ok(Some(ctx))
@@ -105,6 +111,12 @@ impl<'a> CompletionContext<'a> {
105 _ => (), 111 _ => (),
106 } 112 }
107 113
114 self.enclosing_fn = self
115 .leaf
116 .ancestors()
117 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE)
118 .find_map(ast::FnDef::cast);
119
108 let parent = match name_ref.syntax().parent() { 120 let parent = match name_ref.syntax().parent() {
109 Some(it) => it, 121 Some(it) => it,
110 None => return, 122 None => return,
@@ -120,11 +132,6 @@ impl<'a> CompletionContext<'a> {
120 } 132 }
121 if path.qualifier().is_none() { 133 if path.qualifier().is_none() {
122 self.is_trivial_path = true; 134 self.is_trivial_path = true;
123 self.enclosing_fn = self
124 .leaf
125 .ancestors()
126 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE)
127 .find_map(ast::FnDef::cast);
128 135
129 self.is_stmt = match name_ref 136 self.is_stmt = match name_ref
130 .syntax() 137 .syntax()
@@ -145,6 +152,23 @@ impl<'a> CompletionContext<'a> {
145 } 152 }
146 } 153 }
147 } 154 }
155 if let Some(_field_expr) = ast::FieldExpr::cast(parent) {
156 self.dot_receiver = self
157 .leaf
158 .ancestors()
159 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE)
160 .find_map(ast::FieldExpr::cast)
161 .and_then(ast::FieldExpr::expr);
162 }
163 if let Some(_method_call_expr) = ast::MethodCallExpr::cast(parent) {
164 self.dot_receiver = self
165 .leaf
166 .ancestors()
167 .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE)
168 .find_map(ast::MethodCallExpr::cast)
169 .and_then(ast::MethodCallExpr::expr);
170 self.is_method_call = true;
171 }
148 } 172 }
149} 173}
150 174