abracadabra icon indicating copy to clipboard operation
abracadabra copied to clipboard

Re-order function arguments

Open qpwo opened this issue 3 years ago • 1 comments

Is this request related to a problem? Please describe.

I'm always frustrated when I want to change the order of arguments to a function and I have to manually go through the callers and update them. I usually make a mistake and introduce a bug.

Describe the solution you'd like

Select a function, abracadabra re-order arguments. Something like dragging boxes would be nifty but it's fine if I have to fill out a textbox with the same names in a different order. Then the function

Example: before:

// in utils.js
function repeat(f, n) {
    return Array(n).fill(null).map((_,i) => f(i))
}
// in app.js
const squares = repeat(i => i*i, 5)

After:

// in utils.js
function repeat(n, f) {
    return Array(n).fill(null).map((_,i) => f(i))
}
// in app.js
const squares = repeat(5, i => i*i)

qpwo avatar Jul 14 '21 20:07 qpwo

That would be useful indeed. The difficult part is to get the exported references (it has to work cross-files), in particular with JavaScript code.

I believe this may be easier to address once https://github.com/nicoespeon/abracadabra/issues/275 is tackled. Using typescript at the project level would give us the AST cross-files (today refactorings are limited within the same file).

nicoespeon avatar Jul 20 '21 22:07 nicoespeon

@qpwo I'm happy to tell you that will be a reality with the next release, thanks to the amazing contribution from @11joselu He cracked the problem of "exported references" by leveraging VS Code's "Find All References" command—smart!

Here is a demo of the exact scenario you submitted:

https://user-images.githubusercontent.com/1094774/199372640-ba019675-34f4-4f8a-b9fc-5082da963f1a.mp4

I'll cut a new release soon, in the following days.

nicoespeon avatar Nov 02 '22 01:11 nicoespeon

Oh fantastic!

qpwo avatar Nov 08 '22 00:11 qpwo