mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Trigger .let postfix snippet in the middle of the block
This commit is contained in:
parent
75e037fcf7
commit
21d962f0ac
1 changed files with 31 additions and 4 deletions
|
@ -5,7 +5,7 @@ mod format_like;
|
||||||
use ide_db::ty_filter::TryEnum;
|
use ide_db::ty_filter::TryEnum;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode, AstToken},
|
ast::{self, AstNode, AstToken},
|
||||||
SyntaxKind::BLOCK_EXPR,
|
SyntaxKind::{BLOCK_EXPR, EXPR_STMT},
|
||||||
TextRange, TextSize,
|
TextRange, TextSize,
|
||||||
};
|
};
|
||||||
use text_edit::TextEdit;
|
use text_edit::TextEdit;
|
||||||
|
@ -221,9 +221,8 @@ pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
)
|
)
|
||||||
.add_to(acc);
|
.add_to(acc);
|
||||||
|
|
||||||
let parent_node = dot_receiver.syntax().parent().and_then(|p| p.parent());
|
if let Some(parent) = dot_receiver.syntax().parent().and_then(|p| p.parent()) {
|
||||||
if let Some(parent) = parent_node {
|
if matches!(parent.kind(), BLOCK_EXPR | EXPR_STMT) {
|
||||||
if parent.kind() == BLOCK_EXPR {
|
|
||||||
postfix_snippet(
|
postfix_snippet(
|
||||||
ctx,
|
ctx,
|
||||||
cap,
|
cap,
|
||||||
|
@ -389,6 +388,34 @@ fn main() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn let_middle_block() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn main() {
|
||||||
|
baz.l<|>
|
||||||
|
res
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
sn box Box::new(expr)
|
||||||
|
sn call function(expr)
|
||||||
|
sn dbg dbg!(expr)
|
||||||
|
sn dbgr dbg!(&expr)
|
||||||
|
sn if if expr {}
|
||||||
|
sn let let
|
||||||
|
sn letm let mut
|
||||||
|
sn match match expr {}
|
||||||
|
sn not !expr
|
||||||
|
sn ok Ok(expr)
|
||||||
|
sn ref &expr
|
||||||
|
sn refm &mut expr
|
||||||
|
sn some Some(expr)
|
||||||
|
sn while while expr {}
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn option_iflet() {
|
fn option_iflet() {
|
||||||
check_edit(
|
check_edit(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue