aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-12-01 12:38:06 +0000
committerAleksey Kladov <[email protected]>2020-12-01 12:38:06 +0000
commit21d962f0ac7d0e6c680250440b56a639c1c25249 (patch)
tree2e1cded76236a3c2522bb4ea1021fb59f07a6cc2
parent75e037fcf75691a3a87d0cb37ea660dd7105ffba (diff)
Trigger .let postfix snippet in the middle of the block
-rw-r--r--crates/completion/src/completions/postfix.rs35
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;
5use ide_db::ty_filter::TryEnum; 5use ide_db::ty_filter::TryEnum;
6use syntax::{ 6use 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};
11use text_edit::TextEdit; 11use 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#"
395fn 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",