diff options
Diffstat (limited to 'crates/ra_analysis/src/completion/completion_context.rs')
-rw-r--r-- | crates/ra_analysis/src/completion/completion_context.rs | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/crates/ra_analysis/src/completion/completion_context.rs b/crates/ra_analysis/src/completion/completion_context.rs index 71bf7fd32..4685c9328 100644 --- a/crates/ra_analysis/src/completion/completion_context.rs +++ b/crates/ra_analysis/src/completion/completion_context.rs | |||
@@ -24,13 +24,15 @@ pub(super) struct CompletionContext<'a> { | |||
24 | pub(super) module: Option<hir::Module>, | 24 | pub(super) module: Option<hir::Module>, |
25 | pub(super) function: Option<hir::Function>, | 25 | pub(super) function: Option<hir::Function>, |
26 | pub(super) function_syntax: Option<ast::FnDef<'a>>, | 26 | pub(super) function_syntax: Option<ast::FnDef<'a>>, |
27 | pub(super) use_item_syntax: Option<ast::UseItem<'a>>, | ||
27 | pub(super) is_param: bool, | 28 | pub(super) is_param: bool, |
28 | /// A single-indent path, like `foo`. | 29 | /// A single-indent path, like `foo`. |
29 | pub(super) is_trivial_path: bool, | 30 | pub(super) is_trivial_path: bool, |
30 | /// If not a trivial, path, the prefix (qualifier). | 31 | /// If not a trivial, path, the prefix (qualifier). |
31 | pub(super) path_prefix: Option<hir::Path>, | 32 | pub(super) path_prefix: Option<hir::Path>, |
32 | pub(super) after_if: bool, | 33 | pub(super) after_if: bool, |
33 | 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, | ||
34 | /// 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. |
35 | pub(super) is_new_item: bool, | 37 | pub(super) is_new_item: bool, |
36 | /// 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.<|> |
@@ -55,11 +57,12 @@ impl<'a> CompletionContext<'a> { | |||
55 | module, | 57 | module, |
56 | function: None, | 58 | function: None, |
57 | function_syntax: None, | 59 | function_syntax: None, |
60 | use_item_syntax: None, | ||
58 | is_param: false, | 61 | is_param: false, |
59 | is_trivial_path: false, | 62 | is_trivial_path: false, |
60 | path_prefix: None, | 63 | path_prefix: None, |
61 | after_if: false, | 64 | after_if: false, |
62 | is_stmt: false, | 65 | can_be_stmt: false, |
63 | is_new_item: false, | 66 | is_new_item: false, |
64 | dot_receiver: None, | 67 | dot_receiver: None, |
65 | is_method_call: false, | 68 | is_method_call: false, |
@@ -114,6 +117,8 @@ impl<'a> CompletionContext<'a> { | |||
114 | _ => (), | 117 | _ => (), |
115 | } | 118 | } |
116 | 119 | ||
120 | self.use_item_syntax = self.leaf.ancestors().find_map(ast::UseItem::cast); | ||
121 | |||
117 | self.function_syntax = self | 122 | self.function_syntax = self |
118 | .leaf | 123 | .leaf |
119 | .ancestors() | 124 | .ancestors() |
@@ -143,13 +148,22 @@ impl<'a> CompletionContext<'a> { | |||
143 | if path.qualifier().is_none() { | 148 | if path.qualifier().is_none() { |
144 | self.is_trivial_path = true; | 149 | self.is_trivial_path = true; |
145 | 150 | ||
146 | self.is_stmt = match name_ref | 151 | self.can_be_stmt = match name_ref |
147 | .syntax() | 152 | .syntax() |
148 | .ancestors() | 153 | .ancestors() |
149 | .filter_map(ast::ExprStmt::cast) | 154 | .filter_map(ast::ExprStmt::cast) |
150 | .next() | 155 | .next() |
151 | { | 156 | { |
152 | 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 | } | ||
153 | Some(expr_stmt) => expr_stmt.syntax().range() == name_ref.syntax().range(), | 167 | Some(expr_stmt) => expr_stmt.syntax().range() == name_ref.syntax().range(), |
154 | }; | 168 | }; |
155 | 169 | ||