Skip to content

Commit 12ced8f

Browse files
committed
Auto merge of rust-lang#13517 - feniljain:fix_completions, r=Veykril
fix: make custom expr prefix completions to understand refs Possible fix of rust-lang#7929 While reviewing the postfix completion code I saw that while calling `add_custom_postfix_completions` we were doing it under the part where reference was not taken into consideration, but as we are only adding postfix completions with `Expr` scope ( [source](https://github.com/rust-lang/rust-analyzer/blob/ba28e19b7838e3ad4223ae82d074dc3950ef1548/crates/ide-completion/src/completions/postfix.rs#L272) ) I shifted the `add_custom_postfix_completions` call to part where references are considered I am not sure if this is the correct fix or I am understanding the problem exactly but this small move seemed to have fixed the issue :)
2 parents c1305fa + 98125b9 commit 12ced8f

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

crates/ide-completion/src/completions/postfix.rs

+25-4
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ pub(crate) fn complete_postfix(
6969
}
7070
}
7171

72-
if !ctx.config.snippets.is_empty() {
73-
add_custom_postfix_completions(acc, ctx, &postfix_snippet, &receiver_text);
74-
}
75-
7672
let try_enum = TryEnum::from_ty(&ctx.sema, &receiver_ty.strip_references());
7773
if let Some(try_enum) = &try_enum {
7874
match try_enum {
@@ -140,6 +136,10 @@ pub(crate) fn complete_postfix(
140136
None => return,
141137
};
142138

139+
if !ctx.config.snippets.is_empty() {
140+
add_custom_postfix_completions(acc, ctx, &postfix_snippet, &receiver_text);
141+
}
142+
143143
match try_enum {
144144
Some(try_enum) => match try_enum {
145145
TryEnum::Result => {
@@ -613,4 +613,25 @@ fn main() {
613613
r#"fn main() { log::error!("{}", 2+2) }"#,
614614
);
615615
}
616+
617+
#[test]
618+
fn postfix_custom_snippets_completion_for_references() {
619+
check_edit_with_config(
620+
CompletionConfig {
621+
snippets: vec![Snippet::new(
622+
&[],
623+
&["ok".into()],
624+
&["Ok(${receiver})".into()],
625+
"",
626+
&[],
627+
crate::SnippetScope::Expr,
628+
)
629+
.unwrap()],
630+
..TEST_CONFIG
631+
},
632+
"ok",
633+
r#"fn main() { &&42.$0 }"#,
634+
r#"fn main() { Ok(&&42) }"#,
635+
);
636+
}
616637
}

0 commit comments

Comments
 (0)