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.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/crates/ra_analysis/src/completion/completion_context.rs b/crates/ra_analysis/src/completion/completion_context.rs
index 949b8135e..4685c9328 100644
--- a/crates/ra_analysis/src/completion/completion_context.rs
+++ b/crates/ra_analysis/src/completion/completion_context.rs
@@ -31,7 +31,8 @@ pub(super) struct CompletionContext<'a> {
31 /// If not a trivial, path, the prefix (qualifier). 31 /// If not a trivial, path, the prefix (qualifier).
32 pub(super) path_prefix: Option<hir::Path>, 32 pub(super) path_prefix: Option<hir::Path>,
33 pub(super) after_if: bool, 33 pub(super) after_if: bool,
34 pub(super) is_stmt: bool, 34 /// `true` if we are a statement or a last expr in the block.
35 pub(super) can_be_stmt: bool,
35 /// Something is typed at the "top" level, in module or impl/trait. 36 /// Something is typed at the "top" level, in module or impl/trait.
36 pub(super) is_new_item: bool, 37 pub(super) is_new_item: bool,
37 /// The receiver if this is a field or method access, i.e. writing something.<|> 38 /// The receiver if this is a field or method access, i.e. writing something.<|>
@@ -61,7 +62,7 @@ impl<'a> CompletionContext<'a> {
61 is_trivial_path: false, 62 is_trivial_path: false,
62 path_prefix: None, 63 path_prefix: None,
63 after_if: false, 64 after_if: false,
64 is_stmt: false, 65 can_be_stmt: false,
65 is_new_item: false, 66 is_new_item: false,
66 dot_receiver: None, 67 dot_receiver: None,
67 is_method_call: false, 68 is_method_call: false,
@@ -147,13 +148,22 @@ impl<'a> CompletionContext<'a> {
147 if path.qualifier().is_none() { 148 if path.qualifier().is_none() {
148 self.is_trivial_path = true; 149 self.is_trivial_path = true;
149 150
150 self.is_stmt = match name_ref 151 self.can_be_stmt = match name_ref
151 .syntax() 152 .syntax()
152 .ancestors() 153 .ancestors()
153 .filter_map(ast::ExprStmt::cast) 154 .filter_map(ast::ExprStmt::cast)
154 .next() 155 .next()
155 { 156 {
156 None => false, 157 None => {
158 name_ref
159 .syntax()
160 .ancestors()
161 .filter_map(ast::Block::cast)
162 .next()
163 .and_then(|block| block.expr())
164 .map(|e| e.syntax().range())
165 == Some(name_ref.syntax().range())
166 }
157 Some(expr_stmt) => expr_stmt.syntax().range() == name_ref.syntax().range(), 167 Some(expr_stmt) => expr_stmt.syntax().range() == name_ref.syntax().range(),
158 }; 168 };
159 169