abracadabra
abracadabra copied to clipboard
Re-order function arguments
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)
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).
@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.
Oh fantastic!