Skip to content

Commit

Permalink
Auto merge of rust-lang#13517 - feniljain:fix_completions, r=Veykril
Browse files Browse the repository at this point in the history
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 :)
  • Loading branch information
bors committed Nov 2, 2022
2 parents c1305fa + 98125b9 commit 12ced8f
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions crates/ide-completion/src/completions/postfix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ pub(crate) fn complete_postfix(
}
}

if !ctx.config.snippets.is_empty() {
add_custom_postfix_completions(acc, ctx, &postfix_snippet, &receiver_text);
}

let try_enum = TryEnum::from_ty(&ctx.sema, &receiver_ty.strip_references());
if let Some(try_enum) = &try_enum {
match try_enum {
Expand Down Expand Up @@ -140,6 +136,10 @@ pub(crate) fn complete_postfix(
None => return,
};

if !ctx.config.snippets.is_empty() {
add_custom_postfix_completions(acc, ctx, &postfix_snippet, &receiver_text);
}

match try_enum {
Some(try_enum) => match try_enum {
TryEnum::Result => {
Expand Down Expand Up @@ -613,4 +613,25 @@ fn main() {
r#"fn main() { log::error!("{}", 2+2) }"#,
);
}

#[test]
fn postfix_custom_snippets_completion_for_references() {
check_edit_with_config(
CompletionConfig {
snippets: vec![Snippet::new(
&[],
&["ok".into()],
&["Ok(${receiver})".into()],
"",
&[],
crate::SnippetScope::Expr,
)
.unwrap()],
..TEST_CONFIG
},
"ok",
r#"fn main() { &&42.$0 }"#,
r#"fn main() { Ok(&&42) }"#,
);
}
}

0 comments on commit 12ced8f

Please sign in to comment.