diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-12-01 12:38:45 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-12-01 12:38:45 +0000 |
commit | a18392bd903dd764c6c5f5efee0b3d789ee12e52 (patch) | |
tree | 078976eb0c5df12684284708a0d0c7763900e6a7 /crates/completion/src | |
parent | eb7f96951068bd8f8672a8234aa55b2a69d912b0 (diff) | |
parent | 21d962f0ac7d0e6c680250440b56a639c1c25249 (diff) |
Merge #6689
6689: Trigger .let postfix snippet in the middle of the block r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/completion/src')
-rw-r--r-- | crates/completion/src/completions/postfix.rs | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/crates/completion/src/completions/postfix.rs b/crates/completion/src/completions/postfix.rs index 1785794cc..c8ba63cd3 100644 --- a/crates/completion/src/completions/postfix.rs +++ b/crates/completion/src/completions/postfix.rs | |||
@@ -5,7 +5,7 @@ mod format_like; | |||
5 | use ide_db::ty_filter::TryEnum; | 5 | use ide_db::ty_filter::TryEnum; |
6 | use syntax::{ | 6 | use syntax::{ |
7 | ast::{self, AstNode, AstToken}, | 7 | ast::{self, AstNode, AstToken}, |
8 | SyntaxKind::BLOCK_EXPR, | 8 | SyntaxKind::{BLOCK_EXPR, EXPR_STMT}, |
9 | TextRange, TextSize, | 9 | TextRange, TextSize, |
10 | }; | 10 | }; |
11 | use text_edit::TextEdit; | 11 | use text_edit::TextEdit; |
@@ -221,9 +221,8 @@ pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { | |||
221 | ) | 221 | ) |
222 | .add_to(acc); | 222 | .add_to(acc); |
223 | 223 | ||
224 | let parent_node = dot_receiver.syntax().parent().and_then(|p| p.parent()); | 224 | if let Some(parent) = dot_receiver.syntax().parent().and_then(|p| p.parent()) { |
225 | if let Some(parent) = parent_node { | 225 | if matches!(parent.kind(), BLOCK_EXPR | EXPR_STMT) { |
226 | if parent.kind() == BLOCK_EXPR { | ||
227 | postfix_snippet( | 226 | postfix_snippet( |
228 | ctx, | 227 | ctx, |
229 | cap, | 228 | cap, |
@@ -390,6 +389,34 @@ fn main() { | |||
390 | } | 389 | } |
391 | 390 | ||
392 | #[test] | 391 | #[test] |
392 | fn let_middle_block() { | ||
393 | check( | ||
394 | r#" | ||
395 | fn main() { | ||
396 | baz.l<|> | ||
397 | res | ||
398 | } | ||
399 | "#, | ||
400 | expect![[r#" | ||
401 | sn box Box::new(expr) | ||
402 | sn call function(expr) | ||
403 | sn dbg dbg!(expr) | ||
404 | sn dbgr dbg!(&expr) | ||
405 | sn if if expr {} | ||
406 | sn let let | ||
407 | sn letm let mut | ||
408 | sn match match expr {} | ||
409 | sn not !expr | ||
410 | sn ok Ok(expr) | ||
411 | sn ref &expr | ||
412 | sn refm &mut expr | ||
413 | sn some Some(expr) | ||
414 | sn while while expr {} | ||
415 | "#]], | ||
416 | ); | ||
417 | } | ||
418 | |||
419 | #[test] | ||
393 | fn option_iflet() { | 420 | fn option_iflet() { |
394 | check_edit( | 421 | check_edit( |
395 | "ifl", | 422 | "ifl", |