rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.26k stars 1.61k forks source link

Parentheses for function calls are not completed in match arms #18076

Open ChayimFriedman2 opened 1 month ago

ChayimFriedman2 commented 1 month ago

When "rust-analyzer.completion.callable.snippets": "fill_arguments" is set, r-a completes the parens for function calls flawlessly in most situations. But when inside a match arm, if I only typed part of the symbol (e.g. fo of fn foo()), it will complete the arguments, but if I typed it all, accepting the completion will do nothing.

Here's a short video:

https://github.com/user-attachments/assets/eddab49e-7201-4a8a-b5f5-249d17c03d50

rust-analyzer version: 0.3.2096-standalone (779d9eee2 2024-09-01)

rustc version: rustc 1.81.0 (eeb90cda1 2024-09-04)

editor or extension: VSCode

relevant settings:

{
    "rust-analyzer.completion.callable.snippets": "fill_arguments"
}

@rustbot label +A-ide +A-completion

roife commented 1 month ago

https://github.com/rust-lang/rust-analyzer/blob/e35227d186acd47d8e5f78cbd792d57ddf47d74b/crates/ide-completion/src/render/function.rs#L358-L368

In this case, the match has no other arms, so the expected_ty can be unified with the completed_ty, making the two equivalent. In other words, r-a considers it valid for the match to directly return the function pointer foo, and therefore, it won't automatically add parentheses.

ChayimFriedman2 commented 1 month ago

Well yes, but I don't think that's good behavior. r-a should at least also offer the full completion, probably only it if the match is not inside other expression.