diff options
author | Aleksey Kladov <[email protected]> | 2018-12-30 19:14:35 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-12-30 19:14:35 +0000 |
commit | 29a52f8d56e8fa45727c9f38df819a9f82a4eb6f (patch) | |
tree | fe00b007d5a699f75175c96a562a45c0ed1d880c | |
parent | c0d1b17a4e976e07966a1d7f545b6e01d278fd08 (diff) |
refine semi completion
-rw-r--r-- | crates/ra_analysis/src/completion/complete_keyword.rs | 18 | ||||
-rw-r--r-- | crates/ra_analysis/src/completion/completion_context.rs | 32 |
2 files changed, 34 insertions, 16 deletions
diff --git a/crates/ra_analysis/src/completion/complete_keyword.rs b/crates/ra_analysis/src/completion/complete_keyword.rs index b2486104a..d70fdaada 100644 --- a/crates/ra_analysis/src/completion/complete_keyword.rs +++ b/crates/ra_analysis/src/completion/complete_keyword.rs | |||
@@ -191,6 +191,24 @@ mod tests { | |||
191 | return "return $0;" | 191 | return "return $0;" |
192 | "#, | 192 | "#, |
193 | ); | 193 | ); |
194 | check_keyword_completion( | ||
195 | r" | ||
196 | fn quux() -> i32 { | ||
197 | if condition { | ||
198 | <|> | ||
199 | } | ||
200 | let x = 92; | ||
201 | x | ||
202 | } | ||
203 | ", | ||
204 | r#" | ||
205 | if "if $0 {}" | ||
206 | match "match $0 {}" | ||
207 | while "while $0 {}" | ||
208 | loop "loop {$0}" | ||
209 | return "return $0;" | ||
210 | "#, | ||
211 | ); | ||
194 | } | 212 | } |
195 | 213 | ||
196 | #[test] | 214 | #[test] |
diff --git a/crates/ra_analysis/src/completion/completion_context.rs b/crates/ra_analysis/src/completion/completion_context.rs index 4685c9328..4584f355d 100644 --- a/crates/ra_analysis/src/completion/completion_context.rs +++ b/crates/ra_analysis/src/completion/completion_context.rs | |||
@@ -148,24 +148,24 @@ impl<'a> CompletionContext<'a> { | |||
148 | if path.qualifier().is_none() { | 148 | if path.qualifier().is_none() { |
149 | self.is_trivial_path = true; | 149 | self.is_trivial_path = true; |
150 | 150 | ||
151 | self.can_be_stmt = match name_ref | 151 | // Find either enclosing expr statement (thing with `;`) or a |
152 | // block. If block, check that we are the last expr. | ||
153 | self.can_be_stmt = name_ref | ||
152 | .syntax() | 154 | .syntax() |
153 | .ancestors() | 155 | .ancestors() |
154 | .filter_map(ast::ExprStmt::cast) | 156 | .find_map(|node| { |
155 | .next() | 157 | if let Some(stmt) = ast::ExprStmt::cast(node) { |
156 | { | 158 | return Some(stmt.syntax().range() == name_ref.syntax().range()); |
157 | None => { | 159 | } |
158 | name_ref | 160 | if let Some(block) = ast::Block::cast(node) { |
159 | .syntax() | 161 | return Some( |
160 | .ancestors() | 162 | block.expr().map(|e| e.syntax().range()) |
161 | .filter_map(ast::Block::cast) | 163 | == Some(name_ref.syntax().range()), |
162 | .next() | 164 | ); |
163 | .and_then(|block| block.expr()) | 165 | } |
164 | .map(|e| e.syntax().range()) | 166 | None |
165 | == Some(name_ref.syntax().range()) | 167 | }) |
166 | } | 168 | .unwrap_or(false); |
167 | Some(expr_stmt) => expr_stmt.syntax().range() == name_ref.syntax().range(), | ||
168 | }; | ||
169 | 169 | ||
170 | if let Some(off) = name_ref.syntax().range().start().checked_sub(2.into()) { | 170 | if let Some(off) = name_ref.syntax().range().start().checked_sub(2.into()) { |
171 | if let Some(if_expr) = | 171 | if let Some(if_expr) = |