rust-lang / rust-analyzer

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

Generate additional function parameters from function call #18576

Open iLePix opened 3 days ago

iLePix commented 3 days ago

let's say we have the following code:

fn foo(x: i32) { ... }

I now want to add a second argument and add the parameter to the signature automatically, via assist.

foo(5, "bar");

resulting in this:

fn foo(x: i32, arg: &str) { ... }

This is somewhat similar to the assist to generate a new function based on a function call, but instead updating the signature of an existing function. This would be especially useful when using more complex types that can be inferred.

SinanAkkoyun commented 3 days ago

+1

ChayimFriedman2 commented 3 days ago

Should this also update all other existing calls? If yes this runs into UI issues similar to those of the update signature helper, if not this isn't very useful.

iLePix commented 2 days ago

Should this also update all other existing calls? If yes this runs into UI issues similar to those of the update signature helper, if not this isn't very useful.

No it should only update the existing signature of the function. I disagree, since sometimes rust infers complex types that I must explicitly write out because there's no easy way to add them to already existing function arguments. I also think that creating erros at all call sites is rather a feature than a bug, since a change in the function signature has to be handled everywhere.